n = int(input())
A = list(map(int,input().split()))
S = []
sm = 0
ST=[]
ans=0
def cou(r:int):
    return r*(r-1)/2
    
for a in A:
    sm += a
    S.append(sm)
S.sort()
for s in S:
    ST.append(S.count(s))
for st in ST:
    num=cou(st)
    ans+=num
ans+=ST[0]
print(ans)