N = int(input())
D = 0
G = 0
I = 0
V = 0
v = 0
P = 0
p = 0
for i in range(N):
g = int(input())
if G == D:
I += 1
if g == 1:
D += 1
else:
G += 1
#preokret
if V == 1 and g == 1 and P != 0:
v += 1
elif V == 2 and g == 2 and P != 0:
v += 1
else:
V = g
if G<=D and P == 2:
if p