import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) ans = N*(N+1)//2 now = 0 for Ai in A: if Ai==1: now += 1 else: ans -= now*(now+1)//2 now = 0 ans -= now*(now+1)//2 print(ans)