N=int(input()) A=list(map(int,input().split())) ANS=N*(N+1)//2 X=0 for i in range(N): if A[i]: X+=1 ANS-=X else: X=0 print(ANS)