import math

n = int(eval(input()))

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

dic_S = {0:[0]}

S = 0

ans = 0

for i in range(n):

    S += a[i]

    if S not in dic_S:

        dic_S[S] = []

    else:

        pass

    dic_S[S].append(a[i])

    



for k in list(dic_S.keys()):

    I = len(dic_S[k])

    if 3 <= I:

        ans += math.factorial(I) // (math.factorial(I-2)*2)

    elif I == 2:

        ans += 1

    else:

        pass

print(ans)

n = int(eval(input()))

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

dic_S = {0:[0]}

S = 0

ans = 0

for i in range(n):

    S += a[i]

    if S not in dic_S:

        dic_S[S] = []

    else:

        pass

    dic_S[S].append(a[i])

    



for k in list(dic_S.keys()):

    I = len(dic_S[k])

    if 3 <= I:

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

    elif I == 2:

        ans += 1

    else:

        pass

print(ans)

import math

n = int(eval(input()))
a = list(map(int, input().split()))
dic_S = {0: [0]}
S = 0
ans = 0
for i in range(n):
    S += a[i]
    if S not in dic_S:
        dic_S[S] = []
    else:
        pass
    dic_S[S].append(a[i])
for k in list(dic_S.keys()):
    I = len(dic_S[k])
    if 3 <= I:
        ans += math.factorial(I) // (math.factorial(I - 2) * 2)
    elif I == 2:
        ans += 1
    else:
        pass
print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
dic_S = {0: [0]}
S = 0
ans = 0
for i in range(n):
    S += a[i]
    if S not in dic_S:
        dic_S[S] = []
    else:
        pass
    dic_S[S].append(a[i])
for k in list(dic_S.keys()):
    I = len(dic_S[k])
    if 3 <= I:
        ans += (I * (I - 1)) // 2
    elif I == 2:
        ans += 1
    else:
        pass
print(ans)

-import math - -        ans += math.factorial(I) // (math.factorial(I - 2) * 2) +        ans += (I * (I - 1)) // 2