n,*a=map(int,open(0).read().split())
c=b=0
for i in range(n):
  if a[i]:
    b+=c
  else:
    c=i+1
    b+=i+1
print(b)