import heapq

N = int(eval(input()))

A = [int(_) for _ in input().split()]

cumsum = [0]

for a in A:

    cumsum += [cumsum[-1] + a]

heapq.heapify(cumsum)

before = 10 ** 10

count = 0

ans = 0

while cumsum:

    now = heapq.heappop(cumsum)

    count += before == now

    if not (before == now and cumsum):

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

        count = 0

    before = now

print(ans)

N = int(eval(input()))

A = [int(_) for _ in input().split()]

cumsum = [0]

for a in A:

    cumsum += [cumsum[-1] + a]

cumsum.sort()

ans = 0

count = 0

for i in range(N):

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

        count += 1

    if cumsum[i] != cumsum[i + 1] or i == N - 1:

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

        count = 0

print(ans)

import heapq

N = int(eval(input()))
A = [int(_) for _ in input().split()]
cumsum = [0]
for a in A:
    cumsum += [cumsum[-1] + a]
heapq.heapify(cumsum)
before = 10**10
count = 0
ans = 0
while cumsum:
    now = heapq.heappop(cumsum)
    count += before == now
    if not (before == now and cumsum):
        ans += count * (count + 1) // 2
        count = 0
    before = now
print(ans)

N = int(eval(input()))
A = [int(_) for _ in input().split()]
cumsum = [0]
for a in A:
    cumsum += [cumsum[-1] + a]
cumsum.sort()
ans = 0
count = 0
for i in range(N):
    if cumsum[i] == cumsum[i + 1]:
        count += 1
    if cumsum[i] != cumsum[i + 1] or i == N - 1:
        ans += count * (count + 1) // 2
        count = 0
print(ans)

-import heapq - -heapq.heapify(cumsum) -before = 10**10 +cumsum.sort() +ans = 0 -ans = 0 -while cumsum: -    now = heapq.heappop(cumsum) -    count += before == now -    if not (before == now and cumsum): +for i in range(N): +    if cumsum[i] == cumsum[i + 1]: +        count += 1 +    if cumsum[i] != cumsum[i + 1] or i == N - 1: -    before = now