n=int(input()) a=list(map(int,input().split())) ans=0 cnt2=0 for i in range(n): if a[i]==0: ans+=n-i else: cnt2=max(cnt2,i) for j in range(cnt2,n): if a[j]==0: cnt2=j ans+=n-j break else: cnt2=n print(ans)