import bisect import copy import decimal import fractions import heapq import itertools import math import sys from collections import deque,defaultdict,Counter from functools import lru_cache,reduce from math import gcd as Gcd read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines N,*A=map(int,read().split()) ans=N*(N+1)//2 cur=0 while cur!=N: if A[cur]==0: cur+=1 continue i=cur+1 while i!=N and A[i]==1: i+=1 ans-=(i-cur)*(i-cur+1)//2 cur=i print(ans)