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

b = []

sum = 0
for i in range(n):
    sum += a[i]
    b.append(sum)



c = [0 for i in range(2*n)]

for i in range(n):
    c[n+b[i]] += 1

sub = 0
d = []
for i in range(2*n):
    sub += i
    d.append(sub)
    



ans = 0

for i in range(2*n):
    if c[i] > 0:
        ans += d[c[i]-1]

ans += c[n]

print(ans)
    
    
    