from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) A = list(map(int,input().split())) ans = N*(N+1)//2 for g,r in groupby(A): if g==1: n = len(list(r)) ans -= n*(n+1)//2 print(ans)