from scipy.special import comb
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
tmp=0
for i in range(0,n):
  l[i+1]=tmp+a[i]
  tmp=l[i+1]
#print(l)

s=set(l)
ans=0
s=set([i for i in s if l.count(i) > 1])
#print(s)
for i in s:
  ans+=comb(l.count(i), 2, exact=True)
print(ans)