import math

N=int(input())
A=list(map(int,input().split()))
 
count=0
score=0
SUM=[0]
 
for i in range(N):
    SUM=SUM+[SUM[i]+A[i]]

    
SUM.sort()



for i in range(1,len(SUM)):
    if SUM[i]==SUM[i-1]:
        count=count+1
    else:
        if count!=0:
            score=score+math.factorial(count)
        count=0
        
if count!=0:
    score=score+math.factorial(count)

 
print(score)
