from collections import Counter
from math import factorial as fac
N = int(input())
A = list(map(int,input().split()))
S = [0]
for i in range(N):
    S.append(A[i]+S[i])
S.sort()
A = Counter(S)
print(sum([fac(e-1) for e in A.values() if e>1]))