N = int(input()) stk = [] for i in list(map(int, input().split())): stk.append(i) if len(stk) >= 3 and stk[-1] == stk[-2] == stk[-3]: stk.pop() stk.pop() stk.pop() print(N-len(stk))