N = int(input()) A = list(map(int,input().split())) import sys ans = 0 right = 0 for left in range(N): while right < N and A[right] == 1: right += 1 if right == N: print(ans) exit() ans += N - right if left == right: right += 1 print(ans)