N = int(input()) A = input().replace(' ', '').split('0') print((N+1)*N//2 - sum((len(a)+1)*len(a)//2 for a in A))