n = int(input())
a = list(map(int,input().split()))
 
b = []
 
sum = 0
for i in range(n):
    sum += a[i]
    b.append(sum)

bus = 0
for i in range(n):
    bus = max(bus,abs(b[i]))

c = [0 for i in range(2*bus+1)]
 
for i in range(n):
    c[bus+b[i]] += 1
 
sub = 0
d = []
for i in range(n):
    sub += i
    d.append(sub)
 
ans = 0
 
for i in range(2*bus+1):
    if c[i] > 0:
        ans += d[c[i]-1]
 
ans += c[bus]
 
print(ans)
