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

su = 0
S = [0]
for i in range(n):
    su += A[i]
    S.append(su)

# print(S)

D = {}
for i in range(len(S)):
    try:
        D[S[i]] += 1
    except:
        D[S[i]] = 1

def kai(x):
    ans = 1
    for i in range(1, x+1):
        ans *= i
    return ans


ans = 0
for i in D.values():
    if i > 1:
        ans += kai(i-1)
print(ans)