N=int(input())
L=list(map(int,input().split()))
N=200000
L=[i for i in range(N)]
Left=[[0,0]]
Right=[[0,N]]
for i in range(N):
    Left.append([Left[i][0]+L[i],i+1])
for i in range(N):
    Right.append([Right[i][0]+L[i*(-1)-1],N-i-1])
Right=list(reversed(Right))
Left=sorted(Left, key=lambda x: x[0])
_sum_=Right[0][0]
Left=sorted(Left, key=lambda x: x[0],reverse=True)
Right=sorted(Right, key=lambda x: x[0])
Left.append([0,0])
Right.append([0,0])

j=0
s=0
ans=0
for i in range(N+1):
    if i != 0:
        if Left[i][0]!=Left[i-1][0]:
            s=0
    while(Left[i][0]+Right[j][0]<_sum_ and j<=N):
        j+=1
    if j>N:
        break
    elif Left[i][0]+Right[j][0]>_sum_:
        continue
    else:
        while(Left[i][0]+Right[j][0]==_sum_ and j<=N):
            if Left[i][1]>=Right[j][1]:
                j+=1
            else:
                s+=1
                ans+=s
                break
print(ans)