n = int(input())
a = list(map(int,input().split()))
sum = 0
s = 0
l = [0]
p = [0]
for i in range(n):
    sum = sum + a[i]
    if not sum in l:
        p.append(sum)
    l.append(sum)

def fact(n):
    val = min(n,1)
    for i in range(2, n + 1):
        val *= i
    return val

for thing in p:
    de = fact(l.count(thing) - 1)
    s = s +  de

print(s)