N = int(input()) A = list(map(int, input().split())) M = [0] * 2 m, n = 0, 0 ans = 0 i = N - 1 for a in A[::-1]: ans += m * a * (i != N - 1) m, n = n * (1 - a) + 1, m * a + 1 # if a: m = 1 # else: n = 1 i -= 1 print(ans)