n=int(input())
a=list(map(int,input().split()))

if n==1:
    if a[0]==0:
        print(1)
    else:
        print(0)
    quit()

l=[0]
r=[0]
s_l=0
s_r=0
for i in range(n):
    s_l+=a[i]
    s_r+=a[n-i-1]
    l.append(s_l)
    r.append(s_r)

d={}
for i in r:
    if i in d:
        d[i]+=1
    else:
        d[i]=1

if s_l==0:
    ans=1
else:
    ans=0

d[s_l]-=1
for i in range(0,n+1):
    d[r[n-i-1]]-=1
    if s_l-l[i] in d:
        ans+=d[s_l-l[i]]


print(ans)
