n,*a = map(int,open(0).read().split()) ans = cnt = r = 0 for l in range(n): if r < l: r = l while r < n and a[r]: r += 1 ans += n-r print(ans)