n=int(input()) ns=list(map(int,input().split())) s='' box=[] for i in range(n): if ns[i] == 1: s+='1' if i == n-1: box.append(s) else: if len(s) > 0: box.append(s) s='' h=0 for i in box: h += (len(i)+1)*len(i) // 2 total = (n+1)*n // 2 print(total-h)