from sys import stdin N = int(stdin.readline()) A = list(map(int,stdin.readline().split())) ns = 0 ans = 0 for i in A: if i == 0: ans += ns * (ns+1)//2 ns = 0 else: ns += 1 ans += ns * (ns+1)//2 print (N*(N+1)//2-ans)