N = int(input()) A = list(map(int,input().split())) S = [0] * N now = 0 end = 0 while now < N - 1: if A[now] == 0: S[now] = 0 now += 1 continue for i in range(now,N-1): if A[i+1] == A[i] or i == N-2: end = i+1 break for i in range(now,end,2): S[i] = end - i now = end sum = 0 for i in range(N): sum += S[i] print(sum) #多分ok