n = int(eval(input()))

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

s = [0]*(n+1)

for i in range(n):

    s[i+1] = s[i] + a[i]

s = sorted(s)

r = 0

k = 0

for i in range(n):

    if s[i] == s[i+1]:

        k += 1

    else:

        r += (k+1)*k//2

        k = 0

r += (k+1)*k//2

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

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

s = [0]*(n+1)

for i in range(n):

    s[i+1] = s[i] + a[i]

dic = {}

for i in s:

    if i in dic:

        dic[i] += 1

    else:

        dic[i] = 1

r = 0

for d in list(dic.values()):

    r += d*(d-1)//2

print(r)
n = int(eval(input()))
a = list(map(int, input().split()))
s = [0] * (n + 1)
for i in range(n):
    s[i + 1] = s[i] + a[i]
s = sorted(s)
r = 0
k = 0
for i in range(n):
    if s[i] == s[i + 1]:
        k += 1
    else:
        r += (k + 1) * k // 2
        k = 0
r += (k + 1) * k // 2
print(r)

n = int(eval(input()))
a = list(map(int, input().split()))
s = [0] * (n + 1)
for i in range(n):
    s[i + 1] = s[i] + a[i]
dic = {}
for i in s:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
r = 0
for d in list(dic.values()):
    r += d * (d - 1) // 2
print(r)

-s = sorted(s) +dic = {} +for i in s: +    if i in dic: +        dic[i] += 1 +    else: +        dic[i] = 1 -k = 0 -for i in range(n): -    if s[i] == s[i + 1]: -        k += 1 -    else: -        r += (k + 1) * k // 2 -        k = 0 -r += (k + 1) * k // 2 +for d in list(dic.values()): +    r += d * (d - 1) // 2