N = int(input())
A = list(map(int,input().split()))

A_left = [0]*N
x = 0
A_left[0]=A[0]
for i in range(N-1):
    A_left[i+1] = A_left[i]+A[i+1]
    
A_right = [0]*N
x = 0
A_right[N-1]=A[N-1]
for i in range(N-1):
    j = N - i - 1
    A_right[j-1] = A_right[j]+A[j-1]

sumA = -A_left[N-1]

counter = 0
for j in range(1,N):
    if A_right[j] + sumA == 0:
        counter += 1

for i in range(N-2):
    Ai = A_left[i]
    for j in range(i+2,N):
        if Ai + A_right[j] + sumA == 0:
            counter += 1
           
            
for i in range(N-1):
    if A_left[i] + sumA == 0:
        counter += 1


print(counter)