def cmb(n,r):
    if n==0 or r==0:
        return 1
    else:
        ans=1
        for i in range(1,min(r,n-r)+1):
            ans=ans*(n-i+1)//i
        return ans

n=int(input())
a=list(map(int,input().split()))
a_sum=[a[0]]
a_i=a[0]
b=[]
ans=0
for i in range(1,n):
    a_i+=a[i]
    if a_i==0:
        ans+=1
    if a_i not in b and a_i in a_sum:
        b.append(a_i)
    a_sum.append(a_i)
for i in b:
    cnt=a_sum.count(i)
    ans+=cmb(cnt,2)
print(ans)