import math
import collections
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])

c = collections.Counter(x)
for i in c.items():
    if i[0]==0:
        if i[1]==2:
            ans+=2
        else:
            ans+=math.factorial(i[1])
    elif i[1]>=2:
        ans+=math.factorial(i[1]-1)
print(ans)