N=int(eval(input()))

A=[int(a)-1 for a in eval(input())]

r=1 if 1 in A else 2

print((sum([1 if A[i]&r and (N-1&i)==i else 0 for i in range(N)])%2*r))
N=int(eval(input()));A=[int(a)-1 for a in eval(input())];print((sum([A[i] for i in range(N) if N-1&i==i])%(4>>int(1 in A))))
N = int(eval(input()))
A = [int(a) - 1 for a in eval(input())]
r = 1 if 1 in A else 2
print((sum([1 if A[i] & r and (N - 1 & i) == i else 0 for i in range(N)]) % 2 * r))

N = int(eval(input()))
A = [int(a) - 1 for a in eval(input())]
print((sum([A[i] for i in range(N) if N - 1 & i == i]) % (4 >> int(1 in A))))

-r = 1 if 1 in A else 2 -print((sum([1 if A[i] & r and (N - 1 & i) == i else 0 for i in range(N)]) % 2 * r)) +print((sum([A[i] for i in range(N) if N - 1 & i == i]) % (4 >> int(1 in A))))