n = int(eval(input()))

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



b = []

bn = 0

for i in range(n):

    bn += a[i]

    b.append(bn)

b.append(0)



b.sort()

num = []

i = 0

count = 0

for j in range(1, n+1):

    if b[i] == b[j]:

        count += 1

        if j == n:

            num.append(count)

    else:

        i = j

        num.append(count)

        count = 0



ans = 0

for i in num:

    ans += ((i+1) * i // 2)

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

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



cum = [0] * (n+1)

for i in range(n):

    cum[i+1] = cum[i] + a[i]



cum.sort()

num = cum[0]

count = 1

ans = 0

for i in range(n):

    if cum[i+1] == num:

        count += 1

    else:

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

        num = cum[i+1]

        count = 1



if count > 1:

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



print(ans)





n = int(eval(input()))
a = list(map(int, input().split()))
b = []
bn = 0
for i in range(n):
    bn += a[i]
    b.append(bn)
b.append(0)
b.sort()
num = []
i = 0
count = 0
for j in range(1, n + 1):
    if b[i] == b[j]:
        count += 1
        if j == n:
            num.append(count)
    else:
        i = j
        num.append(count)
        count = 0
ans = 0
for i in num:
    ans += (i + 1) * i // 2
print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(n):
    cum[i + 1] = cum[i] + a[i]
cum.sort()
num = cum[0]
count = 1
ans = 0
for i in range(n):
    if cum[i + 1] == num:
        count += 1
    else:
        ans += count * (count - 1) // 2
        num = cum[i + 1]
        count = 1
if count > 1:
    ans += count * (count - 1) // 2
print(ans)

-b = [] -bn = 0 +cum = [0] * (n + 1) -    bn += a[i] -    b.append(bn) -b.append(0) -b.sort() -num = [] -i = 0 -count = 0 -for j in range(1, n + 1): -    if b[i] == b[j]: +    cum[i + 1] = cum[i] + a[i] +cum.sort() +num = cum[0] +count = 1 +ans = 0 +for i in range(n): +    if cum[i + 1] == num: -        if j == n: -            num.append(count) -        i = j -        num.append(count) -        count = 0 -ans = 0 -for i in num: -    ans += (i + 1) * i // 2 +        ans += count * (count - 1) // 2 +        num = cum[i + 1] +        count = 1 +if count > 1: +    ans += count * (count - 1) // 2