N=int(input())
A = list(map(int,input().split()))
B=[0]*(N)
total=0
count=0
flag=0
for i in range(N):
  total+=A[i]
  B[i]=total
total=0
if B[N-1]==0:
  flag=1  
B[N-1]=10000000000
B.sort()
for i in range(N-1):
  count+=1
  if B[i]!=B[i+1]:
    if B[i]==0 and flag==1:
      count+=1
    if count>=2:
        total+=count*(count+1)//2
    count=0
#print(B)
print(total)