import numpy
N = int(input())
ary = list(map(int, input().split(' ')))
count = 0
zero_count = 0
for i in range(N):
    if ary[0] == 0:
        zero_count += 1
        ary.pop(0)
        continue
    elif len(ary)>=2 and ary[0] == ary[1]:
        ary.pop(0)
        continue
    else:
        if zero_count != 0:
            count += zero_count * (zero_count + 1) / 2
            zero_count = 0
        ary_int = numpy.cumsum(ary)
        count += ary_int.tolist().count(0)
        ary.pop(0)
if zero_count != 0:
    count += zero_count * (zero_count + 1) / 2
    zero_count = 0

print(int(count))