import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from collections import defaultdict

from itertools import accumulate



n, *a = list(map(int, read().split()))

dict = defaultdict(int)

ans = 0

for aa in list(accumulate([0] + a)):

    dict[aa] += 1

for v in list(dict.values()):

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

print(ans)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from collections import Counter

from itertools import accumulate



n, *a = list(map(int, read().split()))

ans = 0

for v in list(Counter([0] + list(accumulate(a))).values()):

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

print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from collections import defaultdict
from itertools import accumulate

n, *a = list(map(int, read().split()))
dict = defaultdict(int)
ans = 0
for aa in list(accumulate([0] + a)):
    dict[aa] += 1
for v in list(dict.values()):
    ans += v * (v - 1) // 2
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from collections import Counter
from itertools import accumulate

n, *a = list(map(int, read().split()))
ans = 0
for v in list(Counter([0] + list(accumulate(a))).values()):
    ans += v * (v - 1) // 2
print(ans)

-from collections import defaultdict +from collections import Counter -dict = defaultdict(int) -for aa in list(accumulate([0] + a)): -    dict[aa] += 1 -for v in list(dict.values()): +for v in list(Counter([0] + list(accumulate(a))).values()):