import collections

N = int(eval(input()))

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



sumA = [0]*(N+1)

table = collections.defaultdict(int)

table[0] += 1

for i in range(N):

    sumA[i+1] = sumA[i]+A[i]

    table[sumA[i+1]] += 1

ans = 0

table = list(table.values())

table = [x for x in table if x > 1]

for x in table:

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



print(ans)

import itertools

import collections

N = int(eval(input()))

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



table = collections.defaultdict(int)

A = [0] + A

s = itertools.accumulate(A)

for x in s:

    table[x] += 1

ans = 0

for x in table:

    if table[x] > 1:

        ans += (table[x] * (table[x]-1)) // 2

print(ans)

import collections

N = int(eval(input()))
A = list(map(int, input().split()))
sumA = [0] * (N + 1)
table = collections.defaultdict(int)
table[0] += 1
for i in range(N):
    sumA[i + 1] = sumA[i] + A[i]
    table[sumA[i + 1]] += 1
ans = 0
table = list(table.values())
table = [x for x in table if x > 1]
for x in table:
    ans += x * (x - 1) // 2
print(ans)

import itertools
import collections

N = int(eval(input()))
A = list(map(int, input().split()))
table = collections.defaultdict(int)
A = [0] + A
s = itertools.accumulate(A)
for x in s:
    table[x] += 1
ans = 0
for x in table:
    if table[x] > 1:
        ans += (table[x] * (table[x] - 1)) // 2
print(ans)

+import itertools -sumA = [0] * (N + 1) -table[0] += 1 -for i in range(N): -    sumA[i + 1] = sumA[i] + A[i] -    table[sumA[i + 1]] += 1 +A = [0] + A +s = itertools.accumulate(A) +for x in s: +    table[x] += 1 -table = list(table.values()) -table = [x for x in table if x > 1] -    ans += x * (x - 1) // 2 +    if table[x] > 1: +        ans += (table[x] * (table[x] - 1)) // 2