N = int(input()) A = list(map(int, input().split())) A[-1]=0 ans = 0 k = 0 for i in range(N-1): if (k==0 and A[i]==0): continue if (k>0 and A[i]==A[i-1]): for j in range(k,0,-2): ans+=j k=A[i] else: k+=1 for i in range(k,0,-2): ans+=i print(ans)