n = int(input()) a = list(map(int,input().split())) b = a[:] for i in range(1,n,2): b[i] ^= 1 b.append(-1) pre = n c = [0]*n for i in range(n-1,-1,-1): if b[i] != b[pre]: pre = i c[i] = pre + 1 ans = 0 for i in range(n): if a[i]: ans += min(c[i], n-1) - i print(ans)