import numpy

N=int(eval(input()))

A=list(map(int,input().split()))

B=list(numpy.cumsum(A))+[0]

C=sorted(B)

d=C[0]

cnt=1

ans=0

for i in range(N):

  if C[i+1]==d:

    cnt+=1

  else:

    ans+=cnt*(cnt-1)//2

    cnt=1

    d=C[i+1]

ans+=cnt*(cnt-1)//2

print(ans)    
N=int(eval(input()))

A=list(map(int, input().split()))

D=[0]

d=0

for i in A:

  d+=i

  D.append(d)

D=sorted(D)

ans=0

d=-10**9+1

D.append(10**9+1)

cnt=0

for i in range(N+2):

  if D[i]==d:

    cnt+=1

  else:

    if cnt>1:

      ans+=cnt*(cnt-1)//2

      cnt=1

    else:

      cnt=1

    d=D[i]

print(ans)
import numpy

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(numpy.cumsum(A)) + [0]
C = sorted(B)
d = C[0]
cnt = 1
ans = 0
for i in range(N):
    if C[i + 1] == d:
        cnt += 1
    else:
        ans += cnt * (cnt - 1) // 2
        cnt = 1
        d = C[i + 1]
ans += cnt * (cnt - 1) // 2
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
D = [0]
d = 0
for i in A:
    d += i
    D.append(d)
D = sorted(D)
ans = 0
d = -(10**9) + 1
D.append(10**9 + 1)
cnt = 0
for i in range(N + 2):
    if D[i] == d:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt * (cnt - 1) // 2
            cnt = 1
        else:
            cnt = 1
        d = D[i]
print(ans)

-import numpy - -B = list(numpy.cumsum(A)) + [0] -C = sorted(B) -d = C[0] -cnt = 1 +D = [0] +d = 0 +for i in A: +    d += i +    D.append(d) +D = sorted(D) -for i in range(N): -    if C[i + 1] == d: +d = -(10**9) + 1 +D.append(10**9 + 1) +cnt = 0 +for i in range(N + 2): +    if D[i] == d: -        ans += cnt * (cnt - 1) // 2 -        cnt = 1 -        d = C[i + 1] -ans += cnt * (cnt - 1) // 2 +        if cnt > 1: +            ans += cnt * (cnt - 1) // 2 +            cnt = 1 +        else: +            cnt = 1 +        d = D[i]