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