import sys
input = sys.stdin.readline
s = []
defboj(command,x):
global s
if command == "add":
if x notin s:
s.append(x)
elif command == "remove":
if x in s:
s.remove(x)
elif command == "check":
if x in s:
print(1)
else :
print(0)
elif command == "toggle":
if x in s : s.remove(x)
else : s.append(x)
elif command == "all" : s = [i for i inrange(1,21)]
elif command == "empty" : s=[]
M = int(input())
for _ inrange(M):
command = input().strip()
if command == "all"or command == "empty" :
boj(command,0)
else :
command,x = command.split()
boj(str(command),int(x))