n = int(input()) A = list(map(int, input().split())) ans = n*(n+1)//2 X = [] cur = A[0] cnt = 0 for a in A: if a == cur: cnt += 1 else: if cur == 1: X.append(cnt) cur = a cnt = 1 else: if cur == 1: X.append(cnt) for x in X: ans -= x*(x+1)//2 print(ans)