n = int(input()) a = list(map(int, input().split())) li0 = [x for x in range(n) if a[x] == 0] li0 = list(reversed(li0)) ans = 0 if 0 not in a: print(0) exit() for i in range(n-1): if a[i] == 0: ans += n - i if i >= li0[-1]: li0 = li0[:len(li0)-1] else: if len(li0) == 0: break ans += n - i - (li0[-1]-i) print(ans)