N = int(input()) A = list(map(int,input().split())) ans = 0 prev = 0 for i in range(N): if A[i] == 0: ans += (i-prev+1)*(N-i) prev = i+1 print(ans)