from collections import Counter

import math



def combi(n, r):

  if n >= 2:

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

  else:

    return 0



n = int(eval(input()))

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

s = [0]

for i in range(n):

  s.append(s[i] + a[i])

cs = Counter(s)



ans = 0

for i in list(cs.values()):

  ans += combi(i, 2)

print(ans)
from collections import defaultdict



n = int(eval(input()))

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



accum = [0] * (n + 1)



for i in range(n):

  accum[i + 1] = accum[i] + A[i]

  

box = defaultdict(int)



for i in accum:

  box[i] += 1

  

ans = 0

for k, v in list(box.items()):

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

  

print(ans)
from collections import Counter
import math


def combi(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0


n = int(eval(input()))
a = list(map(int, input().split()))
s = [0]
for i in range(n):
    s.append(s[i] + a[i])
cs = Counter(s)
ans = 0
for i in list(cs.values()):
    ans += combi(i, 2)
print(ans)

from collections import defaultdict

n = int(eval(input()))
A = list(map(int, input().split()))
accum = [0] * (n + 1)
for i in range(n):
    accum[i + 1] = accum[i] + A[i]
box = defaultdict(int)
for i in accum:
    box[i] += 1
ans = 0
for k, v in list(box.items()):
    ans += v * (v - 1) // 2
print(ans)

-from collections import Counter -import math - - -def combi(n, r): -    if n >= 2: -        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) -    else: -        return 0 - +from collections import defaultdict -a = list(map(int, input().split())) -s = [0] +A = list(map(int, input().split())) +accum = [0] * (n + 1) -    s.append(s[i] + a[i]) -cs = Counter(s) +    accum[i + 1] = accum[i] + A[i] +box = defaultdict(int) +for i in accum: +    box[i] += 1 -for i in list(cs.values()): -    ans += combi(i, 2) +for k, v in list(box.items()): +    ans += v * (v - 1) // 2