def inp(): return list(map(int,input().split())) N,=inp() A=inp() ans=0 B=[] for i in range(N): if len(B)>1 and B[-2]==B[-1]==A[i]: B.pop() B.pop() ans+=3 else: B.append(A[i]) print(ans)