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[1]>=2:
        ans+=math.factorial(i[1]-1)
print(ans)