from collections import * N = int(input()) A = list(map(int, input().split())) Q = deque() for i in range(N): if A[i] == 0: Q.append(i) ans = 0 for i in range(N): if Q: ans += N - Q[0] if Q[0] == i: Q.popleft() print(ans)