n = int(input())
a = list(map(int,input().split()))
 
b = []
 
sum = 0
bus = 0
for i in range(n):
    sum += a[i]
    b.append(sum)
    bus = max(bus,abs(a[i]))
 
 
c = [0 for i in range(2*bus)]
 
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):
    if c[i] > 0:
        ans += d[c[i]-1]
 
ans += c[n]
 
print(ans)