import math
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]

#print(n)
#print(a)
answer = 0
b=[0]
for i in range(n):
    b.append(b[i]+a[i])
#c=sorted(b)
c=np.sort(b)
#print(b)
#print(c)
renzoku = 0
for i in range(1,n+1):
    if c[i-1] == c[i]:
        renzoku += 1
    elif renzoku > 0:
        answer += math.factorial(renzoku)
#        print(i,renzoku)
        renzoku = 0
if renzoku > 0:
    answer += math.factorial(renzoku)    
#    print(i,renzoku)
print(answer)
