CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))
from collections import Counter
from itertools import accumulate
D = Counter(list(accumulate(A)))
res = D[0]
#print(D)
for v in list(D.values()):
    res += v*(v-1)//2
print(res)

# Optimized solution
from collections import Counter
from itertools import accumulate
n = eval(input())
D = Counter(accumulate(list(map(int,input().split()))))
res = D[0]
for v in list(D.values()):
    res += v*(v-1)//2
print(res)
# Original solution
from collections import Counter
N = int(eval(input()))
A = [int(i) for i in input().split()]
cum = [0]
for a in A:
    cum.append(cum[-1] + a)
count = Counter(cum)
ans = 0
for v in list(count.values()):
    ans += v * (v - 1) // 2
print(ans)

# Optimized solution
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
cum = [0]
for a in A:
    cum.append(cum[-1] + a)
count = Counter(cum)
ans = 0
for v in list(count.values()):
    ans += v * (v - 1) // 2
print(ans)
# Original solution
from collections import defaultdict
import math

def combnations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(eval(input()))
a = list(map(int, input().split()))
rui = [0] * (N + 1)
for i in range(N):
    rui[i + 1] = rui[i] + a[i]

d = defaultdict(int)
for key in rui:
    d[key] += 1

sortd = sorted(list(d.items()), key=lambda x: x[1], reverse=True)

cnt = 0
for i, j in sortd:
    if j >= 2:
        cnt += combnations(j, 2)
    else:
        break
print(cnt)

# Optimized solution
from collections import defaultdict

N = int(eval(input()))
a = list(map(int, input().split()))
rui = [0] * (N + 1)
for i in range(N):
    rui[i + 1] = rui[i] + a[i]

d = defaultdict(int)
for key in rui:
    d[key] += 1

sortd = sorted(list(d.items()), key=lambda x: x[1], reverse=True)

cnt = 0
for i, j in sortd:
    if j >= 2:
        cnt += (j * (j - 1) // 2)
print(cnt)
# Original solution
import sys
sys.setrecursionlimit(100000)

nCr = {}
def cmb(n, r):
    if n == 1: return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


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

L=[0]
s=0
for i in range(N):
    s+=a[i]
    L.append(s)

L=sorted(L)

s=0
t=L[0]
c=1
for i in range(1,len(L)):
    if(t==L[i]):
        c+=1
    else:
        s+=cmb(c,2)
        t=L[i]
        c=1
else:
    s+=cmb(c,2)
print(s)


# Optimized solution
import sys
sys.setrecursionlimit(10000000)

nCr = {}
def cmb(n, r):
    if n == 1: return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


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

L=[0]
s=0
for i in range(N):
    s+=a[i]
    L.append(s)

L=sorted(L)

s=0
t=L[0]
c=1
for i in range(1,len(L)):
    if(t==L[i]):
        c+=1
    else:
        s+=cmb(c,2)
        t=L[i]
        c=1
else:
    s+=cmb(c,2)
print(s)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
c = [0] * (n + 1)
for i in range(n):
  c[i + 1] = c[i] + a[i]
result = 0
for i in range(1, n + 1):
  for j in range(i):
    if c[i] - c[j] == 0:
      result += 1
print(result)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
c = [0] * (n + 1)
for i in range(n):
  c[i + 1] = c[i] + a[i]
d = {}
for i in range(1, n + 1):
  if c[i] not in d:
    d[c[i]] = 0
  d[c[i]] += 1
result = 0
if 0 in d:
  result += d[0]
for k in d:
  if d[k] != 1:
    result += d[k] * (d[k] - 1) // 2
print(result)
# Original solution
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)


# Optimized solution
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)
# Original solution
from itertools import*
from collections import*
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, list(range(n, n - r, -1)))
    under = reduce(mul, list(range(1,r + 1)))
    return over // under


n,*a=list(map(int,open(0).read().split()))
print((sum(cmb(v,2)for k,v in list(Counter(accumulate(a)).items()) if v>1)+list(accumulate(a)).count(0)))

# Optimized solution
from itertools import accumulate
from collections import Counter
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, list(range(n, n - r, -1)))
    under = reduce(mul, list(range(1,r + 1)))
    return over // under
 
 
n,*a=list(map(int,open(0).read().split()))
b=list(accumulate(a))
print((sum(cmb(v,2)for k,v in list(Counter(b).items()) if v>1)+b.count(0)))
# Original solution
import sys
readline = sys.stdin.buffer.readline
from collections import Counter

n = int(readline())
lst1 = list(map(int,readline().split()))

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
lst2 = [0]+cumsum(lst1)

c = Counter(lst2)

ans = 0
for i in range(len(lst2)-1):
    c[lst2[i]] -= 1
    ans += c[lst2[i]]

print(ans)

# Optimized solution
import sys
readline = sys.stdin.buffer.readline

n = int(readline())
lst1 = list(map(int,readline().split()))

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
lst2 = [0] + cumsum(lst1)

ans = 0

dic1 = dict()
for i in lst2:
    if i in dic1:
        ans += dic1[i]
        dic1[i] += 1
    else:
        dic1[i] = 1

print(ans)
# Original solution
from itertools import accumulate
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))
A = list(map(int, input().split()))
f = [1]*(N+1)


def fact():
    for i in range(1, N):
        f[i+1] = f[i]*(i+1)


def comb(n, r):
    return f[n]//(f[r]*f[n-r])


a = accumulate(A)
C = Counter(a)
fact()

ans = 0
for i, v in list(C.items()):
    if i == 0:
        ans += v
    if v > 1:
        ans += comb(v, 2)
print(ans)


# Optimized solution
from itertools import accumulate
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))
A = list(map(int, input().split()))
f = [1]*(N+1)


def fact(n):
    for i in range(1, n):
        f[i+1] = f[i]*(i+1)


def comb(n, r):
    return f[n]//(f[r]*f[n-r])


a = accumulate(A)
C = Counter(a)
fact(max(C.values()))

ans = 0
for i, v in list(C.items()):
    if i == 0:
        ans += v
    if v > 1:
        ans += comb(v, 2)
print(ans)
# Original solution
from itertools import accumulate
from collections import Counter

N = int(eval(input()))
A = [int(i) for i in input().split()]

B = [0] + list(accumulate(A))

ans = 0
for i in set(B):
    p = Counter(B)[i]
    ans += p*(p-1)//2

print(ans)


# Optimized solution
from itertools import accumulate
from collections import Counter

N = int(eval(input()))
A = [int(i) for i in input().split()]

B = [0] + list(accumulate(A))
C = Counter(B)

ans = 0
for i in set(B):
    p = C[i]
    ans += p*(p-1)//2

print(ans)
# Original solution
n=int(eval(input()))
s=input().split()
l=[int(i) for i in s]
ll=[0 for i in range(n)]
ll[0]=l[0]
for i in range(1,n):
    ll[i]=ll[i-1]+l[i]
ll=[0]+ll
dic={}
for i in ll:
    if i not in list(dic.keys()):
        dic[i]=1
    else:
        dic[i]+=1
res=0
for i in list(dic.keys()):
    res+=dic[i]*(dic[i]-1)//2
print(res)


# Optimized solution
n=int(eval(input()))
s=input().split()
l=[int(i) for i in s]
ll=[0 for i in range(n)]
ll[0]=l[0]
for i in range(1,n):
    ll[i]=ll[i-1]+l[i]
ll=[0]+ll
ll.sort()
now=ll[0]
cnt=1
res=0
for i in range(1,n+1):
    if ll[i]==now:
        cnt+=1
    else:
        res+=cnt*(cnt-1)//2
        cnt=1
        now=ll[i]
res+=cnt*(cnt-1)//2
print(res)
# Original solution
def into_ruiseki(a):
	n = len(a)
	ret = [0 for i in range(n + 1)]
	for i in range(n):
		ret[i + 1] = ret[i] + a[i]
	return ret

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

left = into_ruiseki(a)
right = into_ruiseki(a[::-1])

total = sum(a)
ans = 0
for i in range(n):
	for j in range(n - i):
		if total - left[i] - right[j] == 0:
			ans += 1
print(ans)


# Optimized solution
def into_ruiseki(a):
	n = len(a)
	ret = [0 for i in range(n + 1)]
	for i in range(n):
		ret[i + 1] = ret[i] + a[i]
	return ret

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

b = sorted(into_ruiseki(a))
# print("b =", b)
ans = 0
cnt = 1
for i in range(1, n + 1):
	if b[i] == b[i - 1]:
		cnt += 1
	else:
		ans += cnt * (cnt - 1) // 2
		cnt = 1
ans += cnt * (cnt - 1) // 2
print(ans)
# Original solution
# -*- coding: utf-8 -*-
# 整数の入力
import sys
n = int(eval(input()))
li = list(map(int, input().split()))

count = 0
table = {}

for i in range(len(li)) :
  sum = 0
  if i in list(table.keys()) :
    count += table[i]
    continue

  match_i = list()

  for j in range(len(li)-i) :
    sum = sum + li[i+j]
    if sum == 0:
      count = count + 1
      for k in match_i:
        table[k] = table[k] + 1
      table[i+j+1] = 0
      match_i.append(i+j+1)

print(count)
#print(table)

# Optimized solution
def tri(n):
  return n * (n+1) // 2

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

SA = [0] * (N+1)
for i in range(N):
  SA[i+1] = SA[i] + A[i]
  
SA.sort()

ans = 0
cnt = 0

for i in range(N+1):
  if i == 0:
    now = SA[i]
    continue
  
  if now == SA[i]:
    cnt += 1
    continue
  elif cnt > 0:
    ans += tri(cnt)
    cnt = 0
  else:
    pass
  now = SA[i]

if cnt > 0:
    ans += tri(cnt)
    
print(ans)
# Original solution
import itertools
n = int(eval(input()))
a = list(map(int,input().split()))
arr = [0]
ans = 0
for i, j in enumerate(a):
    arr.append(arr[i] + j)

_set = set(arr)
for i in _set:
    c = arr.count(i)
    if c == 2:
        ans += 1
    elif c > 2:
        ans += len(list(itertools.combinations(list(range(c)), 2)))

print(ans)

# Optimized solution
import itertools
n = int(eval(input()))
a = list(map(int,input().split()))
arr = [0]
ans = 0
for i, j in enumerate(a):
    arr.append(arr[i] + j)

_set = set(arr)
for i in _set:
    c = arr.count(i)
    if c == 2:
        ans += 1
    elif c > 2:
        ans += (c * (c - 1)) // 2

print(ans)
# Original solution
from collections import Counter


class Combination:
    def __init__(self, n):
        """

        :param n: 使用する最大のn (nCm)
        """
        self.n = n
        self.memo = [None for _ in range(n + 1)]
        self.memo[0] = [1]
        for i in range(1, n + 1):
            self._nCm_pascal(i)

    def _nCm_pascal(self, i):
        """
        パスカルの三角形のn階層目のリストを取得する
        :param i: 作成する階層
        :return:
        """
        if self.n < i:
            return

        pre_row = self.memo[i - 1]
        row = [1] * (i + 1)

        for j in range(1, i):
            row[j] = pre_row[j - 1] + pre_row[j]

        self.memo[i] = row

    def nCm(self, n, m):
        return self.memo[n][m]


N = [int(_) for _ in input().split()][0]
a = [int(_) for _ in input().split()]
s = [0] * (N + 1)

cnt = Counter()
comb = Combination(N)
for i in range(N):
    s[i + 1] = a[i] + s[i]
    cnt[s[i + 1]] += 1

ans = 0
for k, v in list(cnt.items()):
    # print(k,v)
    if v <= 1: continue
    ans += comb.nCm(v, 2)
ans += cnt[0]
print(ans)


# Optimized solution
from collections import Counter

N = [int(_) for _ in input().split()][0]
a = [int(_) for _ in input().split()]
s = [0] * (N + 1)

cnt = Counter()
for i in range(N):
    s[i + 1] = a[i] + s[i]
    cnt[s[i + 1]] += 1

ans = 0
for k, v in list(cnt.items()):
    # print(k,v)
    if v <= 1: continue

    ans += (v * (v - 1)) // 2
ans += cnt[0]
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

Asum = [0]*(N+1)
for i in range(N):
    Asum[i+1] = Asum[i] + A[i]

ans = 0
for i in range(N):
    ans += Asum[i+1:].count(Asum[i])
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

Asum = [0]*(N+1)
for i in range(N):
    Asum[i+1] = Asum[i] + A[i]

Asum.sort()
ans = 0
same = 1
tmp = Asum[0] - 1
for i in range(N+1):
    if tmp != Asum[i]:
        ans += same*(same - 1)//2
        tmp = Asum[i]
        same = 1
    else:
        same += 1
ans += same*(same - 1)//2
print(ans)
# Original solution
import itertools
L = [0]
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
dic = {}
dic[0] = 1
for i in range(N):
    n = L[-1] + A[i]
    L.append(n)
    dic.setdefault(n, 0)
    dic[n] += 1
for key in list(dic.keys()):
    if dic[key] > 1:
        cnt += len(list(itertools.combinations(list(range(dic[key])), 2)))
print((int(cnt)))

# Optimized solution
from math import factorial as f
L = [0]
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
dic = {}
dic[0] = 1
for i in range(N):
    n = L[-1] + A[i]
    L.append(n)
    dic.setdefault(n, 0)
    dic[n] += 1
for key in list(dic.keys()):
    if dic[key] > 1:
        cnt += f(dic[key]) // f(2) // f(dic[key] - 2)
print((int(cnt)))
# Original solution
from math import factorial as f
L = [0]
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
dic = {}
dic[0] = 1
for i in range(N):
    n = L[-1] + A[i]
    L.append(n)
    dic.setdefault(n, 0)
    dic[n] += 1
for key in list(dic.keys()):
    if dic[key] > 1:
        cnt += f(dic[key]) // f(2) // f(dic[key] - 2)
print((int(cnt)))

# Optimized solution
L = [0]
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
dic = {}
dic[0] = 1
for i in range(N):
    n = L[-1] + A[i]
    L.append(n)
    dic.setdefault(n, 0)
    dic[n] += 1
for key in list(dic.keys()):
    n = dic[key]
    if n > 1:
        cnt += n * (n - 1) // 2
print((int(cnt)))
# Original solution
from collections import *
from itertools import *

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

s1=[0]+list(accumulate(A))
nums=defaultdict(int)
for i in range(N+1):
  nums[s1[i]]+=1

ans=0
s2=set(s1)
for x in s2:
  ans+=nums[x]*(nums[x]-1)//2

print(ans)


# Optimized solution
from collections import *
from itertools import *

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

s=[0]+list(accumulate(A))
s_cnt=Counter(s)

ans=0
for x in list(s_cnt.values()):
  ans+=(x*(x-1))//2

print(ans)
# Original solution
import math

n = int(eval(input()))
a = [int(i) for i in input().split()]
zero = 0
total_list = [0]
total = 0
for i in a:
  total += i
  zero += total_list.count(total)
  total_list.append(total)

print(zero)


# Optimized solution
import math

n = int(eval(input()))
zero = 0
total_dictionary = {0: 1}
total = 0

for i in input().split():
  total += int(i)
  zero += total_dictionary.get(total,0)
  if total in total_dictionary:
    total_dictionary[total] += 1
  else:
    total_dictionary[total] = 1

print(zero)
# Original solution
from itertools import accumulate
from collections import defaultdict
N = int(eval(input()))
As = [0]+list(map(int, input().split()))
Acc = list(accumulate(As))

d = defaultdict(int)
for a in Acc:
    d[a] += 1
ans = 0
for k in list(d.keys()):
    n = d[k]
    ans += n * (n-1)//2
print(ans) 

# Optimized solution
from itertools import accumulate
from collections import defaultdict
n = int(eval(input()))
As = list(map(int, input().split()))

acc = [0]+list(accumulate(As))
d = defaultdict(int)
for a in acc:
    d[a] += 1
ans = 0
for k in list(d.keys()):
    n = d[k]
    ans += n*(n-1)//2
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
S = []
s = 0
for i in range(N):
    s += A[i]
    S.append(s)
ans = 0
for i in range(N):
    x = S.pop(0)
    if x == 0:
        ans += 1
    ans += S.count(x)
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
S = []
s = 0
for i in range(N):
    s += A[i]
    S.append(s)
ans = 0
S.sort()
x = S[0]
j = 1
if x == 0:
    ans += 1
for i in range(1,N):
    y = S[i]
    if y == 0:
        ans += 1
    if x == y:
        ans += j
        j += 1
    else:
        x = y
        j = 1
print(ans)
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
S = [0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+A[i]
S.sort()
L=[]
k=0
p=0
for i in range(N+2):
    if i==N+1:
        L.append(p)
        continue
    if S[i]==k:
        p+=1
    else:
        L.append(p)
        p=1
        k=S[i]
ans=0
for x in L:
    ans+=(x*(x-1))//2
print(ans)


# Optimized solution
n=int(eval(input()));d={0:1};r=s=0
for i in input().split():s+=int(i);x=d.get(s,0);r+=x;d[s]=x+1
print(r)
# Original solution
def comb(n, r):
    ret = 1
    if (n == r) or (n == 0) or (r == 0):
        ret = 1
    else:
        for i in range(1, n + 1):
            ret *= i
        for i in range(1, r + 1):
            ret //= i
        for i in range(1, n - r + 1):
            ret //= i
    return ret

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

s = [0, a[0]]
for i in range(1, n):
    s.append(s[i]+a[i])
d = {}
for x in s:
    if x in list(d.keys()):
        d[x] += 1
    else:
        d[x] = 1

ans = 0
for k, v in list(d.items()):
    if v >= 2:
        ans += comb(v, 2)
print(ans)

# Optimized solution
'''
https://beta.atcoder.jp/contests/agc023/submissions/2426081
'''
n = int(eval(input()))
A = list(map(int, input().split()))
B = {0:1}
s = 0
ans = 0
for a in A:
    s += a
    B_s = B.get(s, 0) 
    ans += B_s
    B[s] = B_s + 1
print(ans)
# Original solution
from collections import Counter
N=int(eval(input()))
A=list(map(int,input().split()))
cumulative_sum=0
count=0
counter=Counter([0])
for a in A:
    cumulative_sum+=a
    count+=counter[cumulative_sum]
    counter[cumulative_sum]+=1
print(count)

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
cumulative_sum=0
count=0
counter={0:1}
for a in A:
    cumulative_sum+=a
    if cumulative_sum not in counter:
        counter[cumulative_sum]=0
    count+=counter[cumulative_sum]
    counter[cumulative_sum]+=1
print(count)
# Original solution
N = int(eval(input()))

A = [0] + [n for n in map(int, input().split())]

for i in range(N):
    A[i+1] += A[i]

A.sort()
ans = 0

cnt_list = []
temp = A[0]
cnt = 0

for i in range(N+1):
    if temp == A[i]:
        cnt += 1
    else:
        cnt_list.append(cnt)
        cnt = 1
        temp = A[i]
else:
    cnt_list.append(cnt)
for x in cnt_list:
    if x > 1:
        ans += x*(x-1) / 2

print((int(ans)))


# Optimized solution
N = int(eval(input()))

A = [0] + [a for a in map(int, input().split())]

for i in range(N):
    A[i+1] += A[i]
A.sort()
temp = A[0]
cnt = 0
ans = 0
for a in A:
    if temp == a:
        cnt += 1
    else:
        ans += cnt *(cnt-1) // 2
        cnt = 1
        temp = a
ans += cnt * (cnt-1) // 2

print((int(ans)))
# Original solution
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(eval(input()))
def MAP()   : return list(map(int,input().split()))
def LIST()  : return list(MAP())

n = INT()
a = LIST()
s = accumulate(a)

d = defaultdict(int)
for x in s:
    d[x] += 1

ans = d[0]
for x in d:
    ans += d[x]*(d[x]-1)//2

print(ans)

# Optimized solution
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(eval(input()))
def MAP()   : return list(map(int,input().split()))
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = Counter(list(accumulate(a))+[0])

ans = 0
for x in b:
    ans += b[x] * ( b[x] - 1 ) // 2

print(ans)
# Original solution
from collections import defaultdict
N = int(eval(input()))
A = [int(a) for a in input().split()]

series = [0] * (N + 1)
for i in range(1, N+1):
    series[i] = series[i-1] + i
sumDict = defaultdict(int)
sumDict[0] = 1
sum = 0
for a in A:
    sum += a
    sumDict[sum] += 1

total = 0
for key in sumDict:
    total += series[sumDict[key] - 1]
print(total)

# Optimized solution
import sys

def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    sumDict = dict()
    sumA = 0
    sumDict[0] = 1
    for i, a in enumerate(A):
        sumA += a
        if sumA in sumDict: sumDict[sumA] += 1
        else: sumDict[sumA] = 1
    ans = 0
    for key in sumDict: ans += sumDict[key] * (sumDict[key] - 1) // 2
    print(ans)

    return 0

if __name__ == "__main__":
    solve()
# Original solution
import itertools

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

c = [0] * (N+1)

for i in range(N):
    c[i+1] = c[i] + A[i]

cnt = 0
for i in range(N+1):
    for j in range(i+1, N+1):
        if c[j] - c[i] == 0:
            cnt += 1
print(cnt)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

c = [0] * (N+1)

for i in range(N):
    c[i+1] = c[i] + A[i]
cnt = {}
for i in range(0,N+1):
    if c[i] not in cnt:
        cnt[c[i]] = 1
    else:
        cnt[c[i]] += 1
count = 0
for v in list(cnt.values()):
    count += v * (v-1) // 2
print(count)
# Original solution
from collections import Counter

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

A_sum = [A[0]]
for i in range(1,N):
    A_sum.append(A_sum[i-1]+A[i])
    

a_cnt = Counter(A_sum)


ans = 0
for k,v in list(a_cnt.items()):
    ans += v*(v-1)//2
    if k==0:
        ans += v
    
print(ans)

# Optimized solution
from collections import Counter
from itertools import accumulate

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

B = [0] + list(accumulate(A))

cnt = Counter(B)

ans = 0
for v in list(cnt.values()):
    ans += v*(v-1)//2
    
print(ans)
# Original solution
from collections import Counter
from itertools import accumulate

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

a_cum = list(accumulate(a))
cnt = Counter(a_cum)

ans = 0
for k, v in list(cnt.items()):
    if k == 0:
        ans += v + v*(v-1) // 2
    elif v > 0:
        ans += v*(v-1) // 2
        
print(ans)

# Optimized solution
from collections import Counter
from itertools import accumulate

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

cnt = Counter(list(accumulate(a)))

ans = 0
for k,v in list(cnt.items()):
    if k == 0:
        ans += v
    ans += v*(v-1)//2
print(ans)