def cmbn2(n):
  #n>=2
  return int(n*(n-1)/2)

N=int(input())
A=list(map(int, input().split()))
R=[0]*(N+1)
for i in range(N):
  R[i+1]=R[i]+A[i]
  
#m=len(set(R[1:]))
#print((N-m)*m)
#print(R[:10],)
#print(R.count(4))

ans=0
for a in list(set(R[1:])):
  b=R.count(a)
  if b>=2:
    ans+=cmbn2(b)
print(ans)
  