inputs = readlines

reg_num = nil
reg_users = []
door_open = false

inputs.map(&:chomp).each_with_index do |line, i|
  if i == 0
    reg_num = line.to_i
  end

  if i >= 1 && i <= reg_num + 1
    reg_users << line
  end

  if i > reg_num + 1
    if reg_users.include?(line)
      puts "#{door_open ? 'Closed' : 'Opened'} by #{line}"
      door_open = !door_open
    else
      puts "Unknown #{line}"
    end
  end
end
