import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

for i in range(1, N):
    if b[i]==b[i-1]:
        c = c+1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
        c=1
else:
    if c>1:
        ans = ans + C(c, 2)
    if b[i-1]==0:
        ans = ans + c
        
print(ans)