n = int(input()) A = list(map(int, input().split())) ans = 0 for i, a in enumerate(A): if not a: ans += (i+1)*(n-i) print(ans)