#解法:積が0にならないものを取り除く N = int(input()) print(N*(N+1)//2-sum([len(s)*(len(s)+1)//2 for s in "".join(list(map(str,input().split()))).split("0")]))