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