def calc(value):
    tmp = 1
    for i in range(1, value+1):
        tmp *= i
    return tmp//2


n = int(input())
array = [int(x) for x in input().split()]

tmp_sum = 0
sum_array = []

for i in array:
    tmp_sum += i
    sum_array.append(tmp_sum)

sum_dict = {x:sum_array.count(x) for x in set(sum_array)}

minus = 0
if sum_array.count(0) == 1:
    sum_dict[0] += 1
else:
    minus = sum_dict[0]

res = 0
for key, value in sum_dict.items():
    if value >= 2:
        res += calc(value)

print(res-minus)

