Problem:


Kagisys

ある部屋ではICカードを用いて鍵を開け閉めする電子錠システムを用いている。
このシステムは以下のように動作する。

各ユーザーが持つICカードを扉にかざすと、そのICカードのIDがシステムに渡される。
システムはIDが登録されている時、施錠されているなら開錠し、そうでないのなら施錠し、それぞれメッセージが出力される。
IDが登録されていない場合は、登録されていないというメッセージを出力し、開錠及び施錠はおこなわれない。

さて、現在システムにはN個のID(U1, U2, ……, UN)が登録されており、施錠されている。
M回ICカードが扉にかざされ、そのIDはそれぞれ順番にT1, T2, ……, TMであるとする。
この時のシステムがどのようなメッセージを出力するか求めよ。

Input

入力は以下の形式で与えられる。

N
U1
U2
……
UN
M
T1
T2
……
TM

Constraints

N, Mは整数である

1 ≤ N ≤ 256

Uiは1文字以上10文字以下の小文字英字のみからなる文字列である

Uiはユニークである(i &ne; jならばUi &ne; Uj)

1 ≤ M ≤ 256

Tiは1文字以上10文字以下の小文字英字のみからなる文字列である

Output

各T1, T2, ……, TMについて、

開錠された時は、"Opened by "の後に続けてIDを、

施錠された時は、"Closed by "の後に続けてIDを、

IDが登録されていないものだった場合は"Unknown "の後に続けてIDを
それぞれ1行に出力せよ。

初期状態では施錠された状態である。

Sample Input 1

4
abcd
efgh
ijkl
mnop
5
abcd
abcc
efgh
abcd
mnop

Output for the Sample Input 1

Opened by abcd
Unknown abcc
Closed by efgh
Opened by abcd
Closed by mnop

Sample Input 2

2
a
abcdefghij
9
c
bcdefghijk
abcdefghij
b
a
b
a
bcdefghijk
c

Output for the Sample Input 2

Unknown c
Unknown bcdefghijk
Opened by abcdefghij
Unknown b
Closed by a
Unknown b
Opened by a
Unknown bcdefghijk
Unknown c

Sample Input 3

2
z
x
2
z
x

Output for the Sample Input 3

Opened by z
Closed by x



Sample input:
4
abcd
efgh
ijkl
mnop
5
abcd
abcc
efgh
abcd
mnop


Sample output:
Opened by abcd
Unknown abcc
Closed by efgh
Opened by abcd
Closed by mnop

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
id_set = set()
key_status = True
for i in range(n):
	id_set.add(raw_input())
m = int(raw_input())
for i in range(m):
	ic_id = raw_input()
	if ic_id in id_set:
		key_status = not key_status
		print "Closed" if key_status else "Opend", "by", ic_id
	else :
		print "Unknown", ic_id

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-

n = int(raw_input())
ID=[]
for i in range(n):
    ID.append(raw_input())
m = int(raw_input())
door = 1
for i in range(m):
    per = raw_input()
    if per in ID:
        if door == 1:
            print "Opend by", per
        else:
            print "Closed by", per
        door *= -1
    else:
        print "Unknown", per

Submission status: Wrong Answer

Solution code:
n = input()
U = [raw_input() for _ in range(n)]
m = input()
T = [raw_input() for _ in range(m)]

print U, T

Submission status: Wrong Answer

Solution code:
n = int(input())
l1 = [input() for i in range(n)]

m = int(input())
c = 0
l = ["Opend","Closed"]
for i in range(m):
  s = input()
  if s in l1:
    print(l[c%2]+" by "+ s)
    c += 1
  else:
    print("Unknown "+ s)

Submission status: Wrong Answer

Solution code:
k=[input() for _ in range(int(input()))]
a=1
for _ in range(int(input())):
    b=input()
    if b in k:print(('Opend' if a>0 else 'Closed')+' by '+b);a=~a
    else:print('Unknown '+b)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    reg = []
    for _ in range(n):
        reg.append(input())
    m = int(input())
    state = 0

    for _ in range(m):
        p = input()
        if p in reg and not state:
            print("Opened by %s" % (p))
            state = 1
        elif p in reg and state:
            print("Closed by %s" % (p))
            state = 0
        else:print("Unkown %s" % (p))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
U = [raw_input() for _ in range(N)]  # user id

M = int(raw_input())
T = [raw_input() for _ in range(M)]

state = "lock"

for i in T:
    if i in U:
        if state == "lock":
            print "Opend by %s" % i
            state == "open"
        if state == "open":
            print "Closed by %s" % i
    else:
        print "Unknown by %s" % i

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
U = [raw_input() for _ in range(N)]  # user id

M = int(raw_input())
T = [raw_input() for _ in range(M)]

state = "lock"

for i in T:
    if i in U:
        if state == "lock":
            print "Opend by %s" % i
            state = "open"
        if state == "open":
            print "Closed by %s" % i
            state = "lock"
    else:
        print "Unknown by %s" % i

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
U = [raw_input() for _ in range(N)]  # user id

M = int(raw_input())
T = [raw_input() for _ in range(M)]

state = "lock"

for i in T:
    if i in U:
        if state == "lock":
            print "Opend by %s" % i
            state = "open"
        elif state == "open":
            print "Closed by %s" % i
            state = "lock"
    else:
        print "Unknown by %s" % i

Submission status: Wrong Answer

Solution code:
N = int(input())
U = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

opened = False
for T_i in T:
    if T_i in U:
        if opened == True:
            print('Closed by ' + T_i)
            opened = False
        else:
            print('Opened by ' + T_i)
            opened = True

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    n = I()
    a = [S() for _ in range(n)]
    m = I()
    b = [S() for _ in range(m)]
    d = 1
    for c in b:
        if c not in a:
            rr.append('Unknown {}'.format(c))
        elif d == 1:
            rr.append('Opened {}'.format(c))
            d = 0
        else:
            rr.append('Closed {}'.format(c))
            d = 1

    return '\n'.join(map(str, rr))


print(main())

Submission status: Wrong Answer

Solution code:
u = [raw_input() for i in range(input())]
t = [raw_input() for i in range(input())]
s = 0
for id in t:
	if id in u:
		print ("Opened" if s else "Closed") + " by " + id
		s = 1 - s
	else:
		print "Unknown",id

Submission status: Accepted

Solution code:
n = int(input())
ids = [input() for _ in range(n)]
m = int(input())
cnt = 0
for _ in range(m):
  t = input()
  if t in ids:
    cnt += 1
    move = ["Closed by", "Opened by"]
    print(move[cnt % 2], t)
  else:
    print("Unknown", t)

Submission status: Accepted

Solution code:
N = int(input())
U = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
# open: True, close: False
f = False
for i in T:
    if i in U:
        if f:
            print("Closed by {}".format(i))
        else:
            print("Opened by {}".format(i))
        f = not f
    else:
        print("Unknown {}".format(i))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    IDs = []
    for _ in range(N):
        IDs.append(input())
    locked = True
    M = int(input())
    for _ in range(M):
        t = input()
        if t in IDs:
            if locked:
                print('Opened by', t)
                locked = False
            else:
                print('Closed by', t)
                locked = True
        else:
            print('Unknown', t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n = input()
        ids = Counter()
        for i in range(n):
            ids[raw_input()] += 1
        m = input()
        opened = False
        for i in range(m):
            log = raw_input()
            if ids[log] == 0:
                print 'Unknown ' + log
            elif opened:
                opened = not opened
                print 'Closed by ' + log
            else:
                opened = not opened
                print 'Opened by ' + log
            
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
U = [input() for i in range(0,N)]
M = int(input())
door = False
for i in range(M):
    T = input()
    if T in U:
        if door == True:
            print("Closed by " + T)
            door = False
        else:
            print("Opened by " + T)
            door = True
    else:
        print("Unknown " + T)

Submission status: Accepted

Solution code:
n = int(raw_input())
id_set = set()
key_status = True
for i in range(n):
	id_set.add(raw_input())
m = int(raw_input())
for i in range(m):
	ic_id = raw_input()
	if ic_id in id_set:
		key_status = not key_status
		print "Closed" if key_status else "Opened", "by", ic_id
	else :
		print "Unknown", ic_id

Submission status: Accepted

Solution code:
#! /usr/bin/python
# -*- coding: utf-8 -*-

n = int(raw_input())
ID=[]
for i in range(n):
    ID.append(raw_input())
m = int(raw_input())
door = 1
for i in range(m):
    per = raw_input()
    if per in ID:
        if door == 1:
            print "Opened by", per
        else:
            print "Closed by", per
        door *= -1
    else:
        print "Unknown", per

Submission status: Accepted

Solution code:
n = int(input())
ids = []
for i in range(n):
    ids.append(input())

m = int(input())
num = 0
for i in range(m):
    act = input()
    if act in ids:
        print("Opened by" if num % 2 == 0 else "Closed by", act)
        num += 1
    else:
        print("Unknown", act)

Submission status: Accepted

Solution code:
n = int(input())
registerd = [input() for _ in range(n)]

door_open = False

m = int(input())
for _ in range(m):
    ic = input()
    if ic in registerd:
        if door_open:
            print("Closed by {0}".format(ic))
            door_open = False
        else:
            print("Opened by {0}".format(ic))
            door_open = True
    else:
        print("Unknown {0}".format(ic))

Submission status: Accepted

Solution code:
flag = True
u = [input() for i in range(int(input()))]
for i in range(int(input())):
	t = input()
	if t in u:
		if flag:
			print('Opened by {}'.format(t))
			flag = not flag
		else:
			print('Closed by {}'.format(t))
			flag = not flag
	else:
		print('Unknown {}'.format(t))

Submission status: Accepted

Solution code:
open =  "Opened by {}"
close = "Closed by {}"
unknown = "Unknown {}"
lock = True

n = input()

keys = []
for _ in xrange(n):
	keys.append(raw_input())
	
m = input()
operator = []
for _ in xrange(m):
	operator.append(raw_input())
	
for var in operator:
	if var in keys:
		if lock:
			print open.format(var)
			lock = False
		else:
			print close.format(var)
			lock = True
	else:
		print unknown.format(var)

Submission status: Accepted

Solution code:
n = input()
U = [raw_input() for _ in range(n)]
m = input()
T = [raw_input() for _ in range(m)]

isOpen = False

for t in T:
    if t in U:
        if isOpen:
            isOpen = False
            print "Closed by " + t
        else:
            isOpen = True
            print "Opened by " + t
    else:
        print "Unknown " + t

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    n = int(input())
    ids = [input() for i in range(n)]
    m = int(input())
    locked = True
    for j in range(m):
        t = input()
        if t in ids:
            if locked:
                print("Opened by {}".format(t))
                locked = False
            else:
                print("Closed by {}".format(t))
                locked = True
        else:
            print("Unknown {}".format(t))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 17:16:33 2016

"""

U = []
n = int(input())
for _ in range(n):
    U.append(input())

D = True
U = set(U)
    
m = int(input())
for _ in range(m):
    t = input()
    if t in U:
        print({True:"Opened by ", False:"Closed by "}[D]+t)
        D = not D
    else:
        print("Unknown " + t)

Submission status: Accepted

Solution code:
n = int(input())
l1 = [input() for i in range(n)]

m = int(input())
c = 0
l = ["Opened","Closed"]
for i in range(m):
  s = input()
  if s in l1:
    print(l[c%2]+" by "+ s)
    c += 1
  else:
    print("Unknown "+ s)

Submission status: Accepted

Solution code:

n = int(input())

u = [input() for _ in range(n)]

m = int(input())

t = [input() for _ in range(m)]

state = 'Closed'

for k in t:
    if k in u:
        if state == 'Closed':
            print('Opened by', k)
            state = 'Opened'
        else:
            print('Closed by', k)
            state = 'Closed'
    else:
        print('Unknown', k)

Submission status: Accepted

Solution code:
n = int(input())
xs = []
for i in range(n): xs.append(input())
m = int(input())
flag = 1
for i in range(m):
    s = input()
    if s in xs:
        print("Opened" if flag == 1 else "Closed", "by", s)
        flag ^= 1
    else:
        print("Unknown", s)

Submission status: Accepted

Solution code:
now=False
lst=[]
N=int(input())
for k in range(N):lst.append(input())
M=int(input())
for t in range(M):
    ID=input()
    if ID in lst:
        now=not(now)
        if now:
            print("Opened by",ID)
        else:
            print("Closed by",ID)
    else:
        print("Unknown",ID)

Submission status: Accepted

Solution code:
Lock = False
key = int(input())
U = []
for i in range(key):
    U.append(input())
attack = int(input())
for i in range(attack):

    T = input()
    found = False
    for k in range(key):
        if T == U[k]:
            found = True
            if Lock == True:
                print("Closed by " + U[k])
                Lock = False
                break
            else:
                print("Opened by " + U[k])
                Lock = True
                break
    if found == False:
        print("Unknown " + T)

Submission status: Accepted

Solution code:
N = int(input())
lst = [ input() for _ in range(N) ]

M = int(input())
f = False
for _ in range(M):
	s = input()
	if s in lst:
		if f==False:
			f=True
			print("Opened by",s)
		else:
			f=False
			print("Closed by",s)
	else:
		print("Unknown",s)

Submission status: Accepted

Solution code:
N = int(raw_input())
u = {}
for _ in xrange(N):
  u[raw_input()] = True
M = int(raw_input())
is_opened = False
for _ in xrange(M):
  key = raw_input()
  if key in u:
    if is_opened == True:
      print "Closed by %s" % (key)
      is_opened = False
    else:
      print "Opened by %s" % (key)
      is_opened = True
  else:
    print "Unknown %s" % (key)

Submission status: Accepted

Solution code:
l = [input() for _ in range(int(input()))]
f,r = True,''
for _ in range(int(input())):
    s = input()
    if s in l:
        if f: r = 'Opened by '+s
        else: r = 'Closed by '+s
        f = not(f)
    else: r = 'Unknown '+s
    print(r)

Submission status: Accepted

Solution code:
k=[input() for _ in range(int(input()))]
a=1
for _ in range(int(input())):
    b=input()
    if b in k:print(('Opened' if a>0 else 'Closed')+' by '+b);a=~a
    else:print('Unknown '+b)

Submission status: Accepted

Solution code:
k=[input() for _ in range(int(input()))]
a=1
for _ in range(int(input())):
    b=input()
    if b in k:print(['Closed','Opened'][a>0]+' by '+b);a=~a
    else:print('Unknown '+b)

Submission status: Accepted

Solution code:

n = int(input())
u = []
for i in range(n):
    tmp = input()
    u.append( tmp )

m = int( input() )
t = []
for i in range(m):
    tmp = input()
    t.append( tmp )

lock = True
for i in t:
    b = False
    for j in u:
        if i == j:
            b = True
            break
    if b and lock:
        print( "Opened by " + i )
        lock = False
    elif b and not lock:
        print( "Closed by " + i )
        lock = True
    else:
        print( "Unknown " + i )

Submission status: Accepted

Solution code:
N = int(input())
a = 0
lst = []
for i in range(N):
    lst.append(str(raw_input()))
M = int(input())
for j in range(M):
    T = str(raw_input())
    if (T in lst) == True:
        if a == 0:
            a = 1
            print "Opened by " + T
        else:
            a = 0
            print "Closed by " + T
    else:
        print "Unknown " + T

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    reg = []
    for _ in range(n):
        reg.append(input())
    m = int(input())
    state = 0

    for _ in range(m):
        p = input()
        if p in reg and not state:
            print("Opened by %s" % (p))
            state = 1
        elif p in reg and state:
            print("Closed by %s" % (p))
            state = 0
        else:print("Unknown %s" % (p))

Submission status: Accepted

Solution code:
N = int(input())
reg = [input() for i in range(N)]
M = int(input())
src = [input() for i in range(M)]

closed = True
for name in src:
    if name in reg:
        closed = not closed
        print(('Closed' if closed else 'Opened') + ' by ' + name)
    else:
        print('Unknown ' + name)

Submission status: Accepted

Solution code:
N = int(raw_input())
U = [raw_input() for _ in range(N)]  # user id

M = int(raw_input())
T = [raw_input() for _ in range(M)]

lock = True

for i in T:
    if i in U:
        print ("Opened" if lock else "Closed") + " by " + i
        lock = not lock
    else:
        print "Unknown", i

Submission status: Accepted

Solution code:
N = int(input())
U = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

opened = False
for T_i in T:
    if T_i in U:
        if opened == True:
            print('Closed by ' + T_i)
            opened = False
        else:
            print('Opened by ' + T_i)
            opened = True
    else:
        print('Unknown ' + T_i)

Submission status: Accepted

Solution code:
n = int(input())
user = [input() for i in range(n)]

m = int(input())
locked = True
for i in range(m):
    t = input()
    if t in user:
        if locked:
            locked = False
            print("Opened by", t)
        else:
            locked = True
            print("Closed by", t)
    else:
        print("Unknown", t)

Submission status: Accepted

Solution code:
N = int(raw_input())
U = [raw_input() for _ in range(N)]

M = int(raw_input())

is_lock = True

for _ in range(M):
    T = raw_input()
    if T not in U:
        print "Unknown %s" % T
    elif is_lock:
        is_lock = False
        print "Opened by %s" % T
    else:
        is_lock = True
        print "Closed by %s" % T

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    n = I()
    a = [S() for _ in range(n)]
    m = I()
    b = [S() for _ in range(m)]
    d = 1
    for c in b:
        if c not in a:
            rr.append('Unknown {}'.format(c))
        elif d == 1:
            rr.append('Opened by {}'.format(c))
            d = 0
        else:
            rr.append('Closed by {}'.format(c))
            d = 1

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
a = int(input())
b = []
clo = True
for i in range(a):
    b.append(input())

c = int(input())
for i in range(c):
    d = input()
    for j in range(a):
        if d == b[j]:
            know = True
            break
        else:
            know = False
    if know:
        if clo:
            clo = False
            print("Opened by " + d)
        else:
            clo = True
            print("Closed by " + d)
    else:
        print("Unknown " + d)

Submission status: Accepted

Solution code:
flag = 0
N = int(input())
Us = [input() for _ in range(N)]
M = int(input())
for _ in range(M):
    T = input()
    if T in Us: flag ^= 1
    else:
        print("Unknown {}".format(T))
        continue
    print("{} by {}".format(["Closed", "Opened"][flag], T))

Submission status: Accepted

Solution code:
s={input() for _ in range(int(input()))}
k=False
t=[input() for _ in range(int(input()))]
for i in t:
  if i in s:
    k=not k
    if k:
      print("Opened by",i)
    else:
      print("Closed by",i)
  else:
    print("Unknown",i)

Submission status: Accepted

Solution code:

n = input()
user = [""] * n
for i in range(n):
  user[i] = raw_input()
m = input()
st = 0
for i in range(m):
  t = raw_input()
  if t in user:
    print ("Closed" if st else "Opened") + " by " + t
    st = not st
  else:
    print "Unknown " + t

Submission status: Accepted

Solution code:
u = [raw_input() for i in range(input())]
t = [raw_input() for i in range(input())]
isopen = -1
for id in t:
	if id in u:
		print "Opened by %s"%(id) if isopen < 0 else "Closed by %s"%(id)
		isopen *= -1
	else:
		print "Unknown",id

Submission status: Accepted

Solution code:
u = [raw_input() for i in range(input())]
t = [raw_input() for i in range(input())]
s = 1
for id in t:
	if id in u:
		print ("Opened" if s else "Closed") + " by " + id
		s = 1 - s
	else:
		print "Unknown",id

Submission status: Accepted

Solution code:
N = int(input())
U = []
for i in range(N):
    U.append(input())
M = int(input())
T = []
for i in range(M):
    T.append(input())
open = False

for t in T:
    if t in U:
        if not open:
            print("Opened by " + t)
        else:
            print("Closed by " + t)
        open = not open
    else:
        print("Unknown " + t)

Submission status: Accepted

Solution code:
n = int(input())
u = {input() for i in range(n)}
m = int(input())
isLocked = True
for i in range(m):
	t = input()
	if t in u:
		if isLocked:
			print("Opened by",t)
		else:
			print("Closed by",t)
		isLocked = not isLocked
	else:
		print("Unknown",t)

Submission status: Accepted

Solution code:
n = int(input())
u = [str(input()) for i in range(n)]
m = int(input())
t = [str(input()) for i in range(m)]
flag = 1
for i in t:
    if i in u:
        if flag == 1:
            flag = 0
            print("Opened by" + " " + str(i))
        else:
            flag = 1
            print("Closed by" + " " + str(i))
    else:
        print("Unknown" + " " + str(i))

Submission status: Accepted

Solution code:
def get_input():
    input_data = int(input())
    return input_data

def make_registered_id_set(N):
    registered_id_set = set()
    for i in range(N):
        registered_id = input()
        registered_id_set.add(registered_id)
    return registered_id_set

class SecurityDoor:
    CLOSED = 0
    OPENED = 1
    DUMMY = -1
    def __init__(self, registered_id_set):
        self.flag = SecurityDoor.CLOSED
        self.registered_id_set = registered_id_set

    def check_id(self, user_id):
        if user_id in self.registered_id_set:
            msg = self.change_status() + user_id
        else:
            msg = "Unknown " + user_id
        print(msg)

    def change_status(self):
        if self.flag == SecurityDoor.OPENED:
            self.flag = SecurityDoor.CLOSED
            msg = "Closed by "
        else:
            self.flag = SecurityDoor.OPENED
            msg = "Opened by "
        return msg



if __name__ == "__main__":
    N = get_input()
    registered_id_set = make_registered_id_set(N)
    touch_num = get_input()
    security_door = SecurityDoor(registered_id_set)
    for i in range(touch_num):
        user_id = input()
        security_door.check_id(user_id)

Submission status: Accepted

Solution code:
def main():
    from collections import defaultdict
    n = int(input())
    u = [input() for i in range(n)]
    d = defaultdict(int)
    for ui in u:
        d[ui] = 1
    m = int(input())
    f = True
    for _ in range(m):
        n = input()
        if d[n]:
            if f:
                print("Opened by " + n)
                f ^= 1
            else:
                print("Closed by " + n)
                f ^= 1
        else:
            print("Unknown " + n)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    d = defaultdict(lambda : 0)
    n = I()
    for i in range(n):
        u = input()
        d[u] = 1
    ans = ["Opened by", "Closed by"]
    m = I()
    k = 0
    for i in range(m):
        t = input()
        if not d[t]:
            print("Unknown",t)
        else:
            print(ans[k],t)
            k ^= 1
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())
u = set([input() for _ in range(n)])
m = int(input())
b = True
for i in range(m):
    s = input()
    if s in u:
        if b:
            print('Opened by ' + s)
        else:
            print('Closed by ' + s)
        b ^= True
    else:
        print('Unknown ' + s)

Submission status: Accepted

Solution code:
U=[]
T=[]
N=int(input())
for i in range(N):
  U.append(input())
M=int(input())
for i in range(M):
  T.append(input())
count=0
for i in range(len(T)):
  for j in range(len(U)):
    if T[i]==U[j]:
      if count==0:
        print("Opened by",T[i])
        count=1
        break
      if count==1:
        print("Closed by",T[i])
        count=0
        break
    if j==int(len(U))-1:
      print("Unknown",T[i])

Submission status: Accepted

Solution code:
N = int(input())
U = [ input() for _ in range(N)]

M = int(input())
is_lock = True

for _ in range(M):
    T = input()
    if T not in U:
       print("Unknown %s" % T)
    elif is_lock:
       is_lock = False
       print("Opened by %s" % T)
    else:
       is_lock = True
       print("Closed by %s" % T)

Submission status: Accepted

Solution code:
def Open(x) :
	print("Opened by", x)
	door = 1
	return door

def Close(x) :
	print("Closed by", x)
	door = 0
	return door
	
def Out(x) :
	print("Unknown", x)
	
N = int(input())
U = list()
for i in range(N) :
	U.append(input())
M = int(input())
T = list()
for i in range(M) :
	T.append(input())
	
door = 0
# 0 = close, 1 = open
for i in range(M) :
	if(T[i] in U) :
		if(door == 0) :
			door = Open(T[i])
		else :
			door = Close(T[i])
	else :
		Out(T[i])

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    uu = [input() for _ in range(n)]
    m = int(input())
    is_closed = True
    for _ in range(m):
        t = input()
        if t in uu:
            if is_closed:
                print("Opened by", t)
            else:
                print("Closed by", t)
            is_closed = not is_closed
        else:
            print("Unknown", t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
data={}
for i in range(int(input())):
    data[input()]=False
f=False
for i in range(int(input())):
    key=input()
    if key in data:
        if f:
            print('Closed by',key)
            f=False
        else:
            print('Opened by',key)
            f=True
    else:
        print('Unknown',key)

Submission status: Accepted

Solution code:
N = int(raw_input())
U = [raw_input() for _ in range(N)]

M = int(raw_input())
T = [raw_input() for _ in range(M)]

msg = ["Opened by {}", "Closed by {}", "Unknown {}"]
cnt = 0
for t in T:
    if t in U:
        print msg[cnt%2].format(t)
        cnt += 1
    else:
        print msg[2].format(t)

Submission status: Runtime Error

Solution code:
n = int)input())
xs = []
for i in range(n): xs.append(input())
m = int(input())
flag = 1
for i in range(m):
    s = input()
    if s in l:
        print("Opened" if flag == 1 else "Closed", "by", s)
        flag ^= 1
    else:
        print("Unknown", s)

Submission status: Runtime Error

Solution code:
n = int)input())
xs = []
for i in range(n): xs.append(input())
m = int(input())
flag = 1
for i in range(m):
    s = input()
    if s in xs:
        print("Opened" if flag == 1 else "Closed", "by", s)
        flag ^= 1
    else:
        print("Unknown", s)

Submission status: Runtime Error

Solution code:
now=False
N=int(input())
for k in range(N):
    lst=lst.append(input())
M=int(input())
for t in range(M):
    ID=input()
    if ID in lst:
        now=not(now)
        if now:
            print("Opened by",ID)
        else:
            print("Closed by",ID)
    else:
        print("Unknown",ID)

Submission status: Runtime Error

Solution code:
now=False
lst=[]
N=int(input())
for k in range(N):
    lst=lst.append(input())
M=int(input())
for t in range(M):
    ID=input()
    if ID in lst:
        now=not(now)
        if now:
            print("Opened by",ID)
        else:
            print("Closed by",ID)
    else:
        print("Unknown",ID)

Submission status: Runtime Error

Solution code:
def OorC():
    if (T in lst) == True:
        if lst2[lst.index(T)] % 2 == 0:
            lst2[lst.index(T)] += 1
            print "Opened by " + T
        else:
            lst2[lst.index(T)] += 1
            print "Closed by " + T
    else:
        print "Unknown " + T
        

while 1:
    N = int(input())
    if N == 0:
        break
    lst = []
    lst2 = []
    for i in range(N):
        lst.append(str(raw_input()))
        lst2.append(0)
    M = int(input())
    for j in range(M):
        T = str(raw_input())
        OorC()

Submission status: Runtime Error

Solution code:
def OorC():
    if (T in lst) == True:
        if lst2[lst.index(T)] % 2 == 0:
            lst2[lst.index(T)] += 1
            print "Opened by " + T
        else:
            lst2[lst.index(T)] += 1
            print "Closed by " + T
    else:
        print "Unknown " + T
        

while 1:
    N = int(input())
    lst = []
    lst2 = []
    for i in range(N):
        lst.append(str(raw_input()))
        lst2.append(0)
    M = int(input())
    for j in range(M):
        T = str(raw_input())
        OorC()

Submission status: Runtime Error

Solution code:
while 1:
    N = int(input())
    a = 0
    lst = []
    for i in range(N):
        lst.append(str(raw_input()))
    M = int(input())
    for j in range(M):
        T = str(raw_input())
        if (T in lst) == True:
            if a == 0:
                a = 1
                print "Opened by " + T
            else:
                a = 0
                print "Closed by " + T
        else:
            print "Unknown " + T

Submission status: Runtime Error

Solution code:

    N = int(input())
    a = 0
    lst = []
    for i in range(N):
        lst.append(str(raw_input()))
    M = int(input())
    for j in range(M):
        T = str(raw_input())
        if (T in lst) == True:
            if a == 0:
                a = 1
                print "Opened by " + T
            else:
                a = 0
                print "Closed by " + T
        else:
            print "Unknown " + T