from collections import Counter
from math import factorial

n = int(input())
a = list(map(int, input().split()))

l_sum = [0]
s= 0
for i in range(n):
    s += a[i]
    l_sum.append(s)

c_sum = Counter(l_sum)

# print(c_sum)
ans = 0
for i in c_sum:
    if c_sum[i] > 1:
        ans += factorial(c_sum[i]-1)

print(ans)