import math
n = int(input())
a = list(map(int, input().split()))
ans=0
x=[a[0]]
for i in range(1,n):
    x.append(a[i]+x[i-1])
for i in set(x):
    t = x.count(i)
    if i != 0:
        if t >= 2:
            ans += math.factorial(t-1)
    else:
        ans += math.factorial(t)
print(ans)