n = int(input()) a = list(map(int, input().split())) b0 = a[:] b1 = a[:] for i in range(n): if i % 2 == 0: b0[i] ^= 1 else: b1[i] ^= 1 nxt0 = [n - 1] * n nxt1 = [n - 1] * n for b, nxt in ((b0, nxt0), (b1, nxt1)): x = n - 1 for i in range(n)[::-1]: nxt[i] = x if b[i] == 1: x = i ans = 0 for i in range(n): if a[i] == 0: continue if i % 2 == 0: ans += nxt0[i] - i else: ans += nxt1[i] - i print(ans)