CodeEff/ECCO huggingface dataset:
# Original solution
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
import itertools as it
from collections import Counter
#======================================================#
def main():
    n = II()
    aa = MII()
    cum = list(it.accumulate([0]+aa))
    c = Counter(cum)
    print((sum([(n*(n-1))//2 for n in list(c.values())])))

if __name__ == '__main__':
    main()

# Optimized solution
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
import itertools as it
from collections import Counter
#======================================================#
def main():
    n = II()
    aa = MII()
    cum = list(it.accumulate([0]+aa))
    c = Counter(cum)
    print((sum([(n*(n-1))//2 for n in list(c.values()) if n>1])))

if __name__ == '__main__':
    main()
# Original solution
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
import itertools as it
from collections import Counter
#======================================================#
def main():
    n = II()
    aa = MII()
    cum = list(it.accumulate([0]+aa))
    c = Counter(cum)
    print((sum([(n*(n-1))//2 for n in list(c.values()) if n>1])))

if __name__ == '__main__':
    main()

# Optimized solution
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from itertools import accumulate
from collections import Counter
#======================================================#
def main():
    n = II()
    cum = list(accumulate([0]+MII()))
    cnt = [n for n in list(Counter(cum).values()) if n > 1]
    ans = sum([(n*(n-1))//2 for n in cnt])
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S)

ret = 0
for s in set(S):
    cnt = S.count(s)
    ret += cnt * (cnt - 1) / 2
print((int(ret)))


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

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S) + [None]
ret = 0
cnt = 1
for i in range(1, N + 2):
    if S[i] != S[i - 1]:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
    else:
        cnt += 1

print(ret)
# Original solution
#zero_sum slow
import sys

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

res = 0
s = 0
s_list = [[0,0]]
i = 0
while i < N:
    s += A[i]
    inside = True
    j = 0
    while j < len(s_list):
        if s == s_list[j][1]:
            temp = s_list[j][0]
            s_list[j][0] += 1
            res -= temp * (temp + 1) / 2.
            res += (temp + 1) * (temp + 2) / 2.
            inside = False
            j = len(s_list) + 1
        j += 1
    if inside:
        s_list.append([0,s])
    i += 1
    
print((int(res)))

# Optimized solution
#zero_sum slow
import sys

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


res = 0
s = 0
s_list = {}
s_list.update({0:0})
i = 0
while i < N:
    s += A[i]
    try:
        s_temp = s_list[s]
        s_list[s] += 1
        res -= s_temp * (s_temp + 1) / 2.
        res += (s_temp + 1) * (s_temp + 2) / 2.
    except:
        s_list.update({s:0})
    i += 1
    
print((int(res)))
# Original solution
N = int(eval(input()))
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=0
for i in range(N+1):
    for j in range(i+1,N+1):
        if BBB[i]==BBB[j]:
            ans+=1
print(ans)

# Optimized solution
N = int(eval(input()))
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = float("inf")
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print((sum([(i-1)*i//2 for i in ans])))
# Original solution
n = int(eval(input()))
ary = list(map(int, input().split()))
#print(n,ary)

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2
#print(ary_2)

from collections import Counter
c = Counter(ary_2)
v = (list(c.values()))
#print(v)

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for j in v:
    if j >1:
        ans += combinations_count(j,2)

print(ans)

# Optimized solution
n = int(eval(input()))
ary = list(map(int, input().split()))
#print(n,ary)

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2
#print(ary_2)

from collections import Counter
c = Counter(ary_2)
v = (list(c.values()))
#print(v)

ans = 0
for j in v:
    if j >1:
        ans += j * (j-1) // 2

print(ans)
# Original solution
import math

N=int(eval(input()))
A=list(map(int,input().split()))
 
count=0
score=0
SUM=[0]
 
for i in range(N):
    SUM=SUM+[SUM[i]+A[i]]

    
SUM.sort()



for i in range(1,len(SUM)):
    if SUM[i]==SUM[i-1]:
        count=count+1
    else:
        if count!=0:
            score=score+math.factorial(count)
        count=0
        
if count!=0:
    score=score+math.factorial(count)

 
print(score)


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

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

    
SUM.sort()



for i in range(1,N+1):
    if SUM[i]==SUM[i-1]:
        count=count+1
    else:
        if count!=0:
            score=score+count*(count+1)//2
        count=0
        
if count!=0:
    score=score+count*(count+1)//2

 
print(score)
# Original solution
import sys,math,collections,itertools
input = sys.stdin.readline

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

Ac = collections.Counter(A)
cnt = 0
for val in list(Ac.values()):
    cnt += val*(val-1)//2
print(cnt)


# Optimized solution
import sys,collections,itertools
input = sys.stdin.readline
N=int(eval(input()))
a=list(map(int,input().split()))
A =[0]+list(itertools.accumulate(a))
Ac = collections.Counter(A)
cnt = 0
for val in list(Ac.values()):
    cnt += val*(val-1)//2
print(cnt)
# Original solution
import math
N = int(eval(input()))
l = [int(x) for x in input().split()]
s = [0] * (N+1)
for i in range(N):
    s[i+1] = s[i] + l[i]
s.sort()
ans = 0
owari = False
for i in range(N+1):
    if owari:
        break
    x = s.pop(0)
    count = 1
    for j in range(N+1):
        if not s:
            owari = True
            if count != 1:
              ans += math.factorial(count) // (math.factorial(count-2)*2)
            break
        elif x == s[0]:
            s.pop(0)
            count += 1
        elif count != 1:
            ans += math.factorial(count) // (math.factorial(count-2)*2)
            break
        else:
            break
print(ans)

# Optimized solution
N = int(eval(input()))
l = [int(x) for x in input().split()]
s = [0] * (N+1)
for i in range(N):
    s[i+1] = s[i] + l[i]
s.sort()

#count
table= {}
for i in range(N+1):
    if s[i] in table:
        table[s[i]] += 1
    else:
        table[s[i]] = 1
ans = 0
for key,val in list(table.items()):
    if val >= 2:
        ans += val*(val-1)//2
print(ans)
# Original solution
from collections import Counter
N = int(eval(input()))  # 長さN
A = list(map(int, input().split()))  # 整数列A

S = [0]
for i in range(len(A)):
    S.append(S[-1] + A[i])

c = Counter(S)

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

print(ans)


# Optimized solution
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
s = [0]
for a in A:
    s.append(s[-1]+a)

c = Counter(s)

ans = 0
for k, v in list(c.items()):
    ans += v*(v-1)//2
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
from math import factorial
from collections import Counter
def comb(r):
    return int(factorial(r)/factorial(r-2)/factorial(2))
cum = [a[0]]
for i in range(1,n):
    cum.append(cum[-1] + a[i])
cnt = Counter(cum)
ans = 0
for v in list(cnt.values()):
    if v >= 2:
        ans += comb(v)
print((ans+cum.count(0)))

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
from itertools import accumulate
from collections import Counter
import math
a = list(accumulate(a))
b = Counter(a)
def comb(n):
    return math.factorial(n)/math.factorial(n-2)/math.factorial(2)
cnt = 0
for v in list(b.values()):
    if v >= 2:
        cnt += comb(v)
print((int(cnt+a.count(0))))
# Original solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    tl = [0]
    for v in a:
        t += v
        tl.append(t)
    tl = collections.Counter(tl)
    s = 0
    for k, v in list(tl.items()):
        s += (v * (v - 1) // 2)
    print(s)


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ans = [0]
    t = 0
    for i in range(n):
        t += a[i]
        ans.append(t)
    ans = collections.Counter(ans)
    t = 0
    for k, v in list(ans.items()):
        t += (v * (v - 1) // 2)
    print(t)


if __name__ == '__main__':
    slove()
# Original solution
def resolve():
    import math as m
    from collections import defaultdict
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    preSum = [0] * (N + 1)
    dd = defaultdict(int)
    dd[0] = 1
    for i in range(N):
        preSum[i + 1] = preSum[i] + A[i]
        dd[preSum[i] + A[i]] += 1
    sumA = 0
    for key in list(dd.keys()):
        if dd[key] > 1:
            sumA += m.factorial(dd[key]) // (m.factorial(dd[key] - 2) * 2)
    print(sumA)


resolve()


# Optimized solution
def resolve():
    from collections import defaultdict
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    preSum = [0] * (N + 1)
    dd = defaultdict(int)
    dd[0] = 1
    for i in range(N):
        preSum[i + 1] = preSum[i] + A[i]
        dd[preSum[i] + A[i]] += 1
    sumA = 0
    for key in list(dd.keys()):
        if dd[key] > 1:
            sumA += dd[key] * (dd[key] - 1) // 2
    print(sumA)


resolve()
# Original solution
from collections import Counter
import math

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


n = int(eval(input()))
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
ac = Counter(a_t[1:])
ans = 0
for i in ac:
    if i == 0:
        ans += ac[i]
    if ac[i] > 1:
        ans += nCr(ac[i], 2)
print(ans)

# Optimized solution
import collections

n = int(eval(input()))
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
a_t = collections.Counter(sorted(a_t))
ans = 0
for i in list(a_t.values()):
    ans += i * (i - 1) // 2
print(ans)
# Original solution
#AGC023 A: 部分和は先頭からの

#AGC023 A
'''
問題
長さNの整数列Aがある
Nは1以上20000以下
Aiは-10**9以上10**9以下
Aの空でない連続する部分列であって，その総和が0であるものの個数は？

考察1
区間[i,j]を取り出して0になるかどうかを試す
これを0<=i<=j<=20000について繰り返す
計算時間はO(N**2)
つまりループ回数が10**10になる->大丈夫?
-> 大丈夫ではない。予想通りTLEになった

考察2
思いつかない...

解説を読んでやり直し
S0 = 0
S1 = A1
S2 = A1 + A2
...
Si = A1 + ... + Ai
とすると, 0<=p<q<=Nとなる(p,q)を選んでSq-Spを計算することによって任意の部分和を構成できる
Sq-Sp=0であればA_(p+1) + ... + Aqの部分和が0である
したがって0<=p<q<=Nとなる(p,q)に対してSp=Sqとなる(p,q)の組を数えればよい
このためにはS0,S1,...をソートして
Siをソートするところがボトルネックとなり, 計算量はO(NlogN)
'''

'''
#考察1は失敗
N = int(input())
A = list(map(int,input().split(' ')))

ans = 0

for i in range(N):
	for j in range(i,N):
		if sum(A[i:(j+1)]) == 0:
			ans += 1
		else:
			continue
			
print(ans)
'''

N = int(eval(input()))
A = list(map(int,input().split(' ')))
S = [0]
Scount = []
ans = 0

for i in range(N):
	#print(A[0:i+1])
	#S.append(sum(A[0:i+1])) <- これは遅くなるのでNG
	S.append(S[-1]+A[i])
	#print(S)

S = sorted(S)

for s in list(dict.fromkeys(S)):
	Scount.append(S.count(s))

for n in Scount:
	ans += (n*(n-1)/2)

print((int(ans)))

# Optimized solution
#AGC023 A: 部分和は先頭からの

#AGC023 A
'''
問題
長さNの整数列Aがある
Nは1以上20000以下
Aiは-10**9以上10**9以下
Aの空でない連続する部分列であって，その総和が0であるものの個数は？

考察1
区間[i,j]を取り出して0になるかどうかを試す
これを0<=i<=j<=20000について繰り返す
計算時間はO(N**2)
つまりループ回数が10**10になる->大丈夫?
-> 大丈夫ではない。予想通りTLEになった

考察2
思いつかない...

解説を読んでやり直し
S0 = 0
S1 = A1
S2 = A1 + A2
...
Si = A1 + ... + Ai
とすると, 0<=p<q<=Nとなる(p,q)を選んでSq-Spを計算することによって任意の部分和を構成できる
Sq-Sp=0であればA_(p+1) + ... + Aqの部分和が0である
したがって0<=p<q<=Nとなる(p,q)に対してSp=Sqとなる(p,q)の組を数えればよい
このためにはS0,S1,...をソートして
Siをソートするところがボトルネックとなり, 計算量はO(NlogN)
'''

'''
#考察1は失敗
N = int(input())
A = list(map(int,input().split(' ')))

ans = 0

for i in range(N):
	for j in range(i,N):
		if sum(A[i:(j+1)]) == 0:
			ans += 1
		else:
			continue
			
print(ans)
'''

N = int(eval(input()))
A = list(map(int,input().split(' ')))
S = [0]
Scount = [1]
ans = 0

for i in range(N):
	#print(A[0:i+1])
	#S.append(sum(A[0:i+1])) <- これは遅くなるのでNG
	S.append(S[-1]+A[i])
	#print(S)

S = sorted(S)

#for s in list(dict.fromkeys(S)):
	#Scount.append(S.count(s)) <- これも遅くなるのでNG
	
for i in range(N+1):
	if i==0:
		continue
	elif S[i]==S[i-1]:
		Scount[-1] += 1
	else:
		Scount.append(1)

for n in Scount:
	ans += (n*(n-1)/2)

print((int(ans)))
# Original solution
n = int,eval(input())
a = list(map(int, input().split()))
wa = []
ans = 0
wa.append(a[0])
for i in range(1,len(a)):
    wa.append(wa[i-1] + a[i])
ans += wa.count(0)
for i in range(0,len(a)):
    wa2 = []
    wa2 = list([x-wa[i] for x in wa])
    wa3 = wa2[i+1:]
    ans += wa3.count(0)
print(ans)


# Optimized solution
n = int,eval(input())
a = list(map(int, input().split()))
total = []
ans = 0
dic = {0:1}
for i in range(0,len(a)):
    if(i == 0):
        total.append(a[0])
    else:
        total.append(total[i-1] + a[i])
    ans += dic.get(total[i],0)
    if total[i] in dic:
        dic[total[i]] += 1
    else:
        dic[total[i]] = 1
print(ans)
# Original solution
from collections import Counter
from itertools import accumulate

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

ans = 0

ruisekiwa = list(accumulate(inputs))
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)

for key, value in list(counter_ruiseki.items()):
    if key == 0 and value == 1:
        ans += value
        continue
    elif key == 0 and value > 1:
        ans += value
    if value > 1:
        ans += sum(list(range(value)))

print(ans)


# Optimized solution
from collections import Counter
from itertools import accumulate

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

ans = 0

ruisekiwa = list(accumulate(inputs))

for key, value in list(Counter(ruisekiwa).items()):
    if key == 0 and value == 1:
        ans += value
        continue
    elif key == 0 and value > 1:
        ans += value
    if value > 1:
        ans += value * (value - 1) // 2

print(ans)
# Original solution
from collections import defaultdict
n = int(eval(input()))
A = list(map(int, input().split()))
dd = defaultdict(int)
dd[0] += 1
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i]+A[i]
    dd[S[i+1]] += 1
print((sum(v*(v-1)//2 for v in list(dd.values()))))


# Optimized solution
from collections import defaultdict
from itertools import accumulate
n = int(eval(input()))
A = accumulate(list(map(int, input().split())))
cnt = defaultdict(int)
cnt[0] += 1
for a in A:
    cnt[a] += 1
print((sum(v*(v-1)//2 for v in list(cnt.values()))))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split(" ")))
b = [0 for a in range(n)]
b[0] = a[0]
answer = 0
for i in range(n-1):
    b[i+1] = b[i] + a[i+1]
# print(b)
for i in b:
    if i == 0:
        answer += 1;
minimum = min(b)
for i in range(n):
    b[i] -= minimum
# print(b)
c = [0 for a in range(max(b)+1)]
for i in range(n):
    c[b[i]] += 1

for i in c:
    if i > 1:
        answer += i * (i-1) // 2
# print(c)
# print(sum(c))
print(answer)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split(" ")))
b = [0 for a in range(n)]
b[0] = a[0]
answer = 0
for i in range(n-1):
    b[i+1] = b[i] + a[i+1]
# print(b)
for i in b:
    if i == 0:
        answer += 1;
minimum = min(b)
for i in range(n):
    b[i] -= minimum
# print(b)
# c = [0 for a in range(max(b)+1)]
setb = set(b)
# print(setb)
c = {}
for key in setb:
    c[str(key)] = 0

for i in range(n):
    c[str(b[i])] += 1

for v in list(c.values()):
    if v > 1:
        answer += v * (v-1) // 2
# print(c)
# print(sum(c))
print(answer)
# Original solution
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)

# Optimized solution
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)
# Original solution
# coding :utf-8

N = int(eval(input()))

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

ans = 0
for i in range(len(A)):
    sum = A[i]
    if sum == 0:
        ans += 1
    for j in range(i+1, len(A)):
        sum += A[j]
        if sum == 0:
            ans += 1

print(ans)

# Optimized solution
# coding: utf-8

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

# aの要素は1以上であるため、前方からの総和の数列sについて
# 同一の数値がでてきたとき、和が0になる連続する部分数列がある
# 例
# A = [1, 3, -4, 2, 2, -2]
# S = [1, 4, 0, 2, 4, 2]
# S_3:5 = S_5 - S_2 =(Sum(A_1:5) - Sum(A_1:2)) = 0
#


ans = 0
s = 0
# 総和順列の値について、値と個数の辞書を用意する
l ={0:1}


for i in a:
    # 数列の現在位置までの総和をカウント
    s += i
    if s in l:
        ans += l[s]
        l[s] += 1
    else:
        l[s] = 1

print(ans)
# Original solution
n = int(eval(input()))
a = list(int(i) for i in input().split())
sa = [0] * (n+1)
num_cnt = {}    
# 累積和
for i in range(n):
    sa[i+1] = sa[i] + a[i]

nums = list(set(sa))
for num in nums:
    num_cnt[num] = sa.count(num)
res = 0
for cnt in list(num_cnt.values()):
    res += cnt*(cnt-1)//2

print(res)

# Optimized solution

n = int(eval(input()))
a = list(int(i) for i in input().split())
sa = [0] * (n+1)
num_cnt = {}    
# 累積和
for i in range(n):
    sa[i + 1] = sa[i] + a[i]

for num in sa:
    if num in num_cnt:
        num_cnt[num] += 1
    else:
        num_cnt[num] = 1


res = 0
for cnt in list(num_cnt.values()):
    res += cnt*(cnt-1)//2

print(res)
# Original solution
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)


# Optimized solution
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)
# Original solution
n = int(eval(input()))

a = list(map(int, input().split()))
cnt = 0
b = 0
c = []
for i in range(n):
    b += a[i]
    c.append(b)
    if b == 0:
        cnt += 1
    for j in range(i):
        if b-c[j] == 0:
            cnt += 1
            
print(cnt)

# Optimized solution

n = int(eval(input()))

a = list(map(int, input().split()))
cnt = 0
b = 0
c = [0]
for i in range(n):
    b += a[i]
    c.append(b)

c.sort()
i=0
ncm=0
m = 1
while True:
    i += 1
    if i == n+1:
        ncm += m*(m-1)//2
        break        
    if c[i] == c[i-1]:
        m += 1
        continue
    else:
        ncm += m*(m-1)//2
        m = 1

print(ncm)
# Original solution
N = int(eval(input()))
A = [int(_) for _ in input().split()]
cumsum = [0]
for a in A:
    cumsum += [cumsum[-1] + a]
ans = 0
for i in range(N):
    for j in range(i + 1, N + 1):
        ans += cumsum[j] - cumsum[i] == 0
print(ans)


# Optimized solution
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)
# Original solution
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)


# Optimized solution
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)
# Original solution
#import numpy as np
import itertools
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))
#Z = np.zeros((N+1,N))
Z = [[0]*int(N+1) for i in range(N) ]
#Z[0,:] = np.array(A)
result = 0

for k in range(N):
        Z[0][k] = A[k]
        if A[k] == 0:
                result = result+1

for i,j in itertools.combinations_with_replacement(list(range(1,N)),2):
        tmp = Z[i-1][j-1]+Z[0][j]
        if tmp ==0:
                result = result+1
        Z[i][j] = tmp
print(result)

# Optimized solution
import itertools
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))
Z = [[0 for m in range(N+1)] for n in range(N) ]
result = 0

for k in range(N):
        Z[0][k] = A[k]
        if A[k] == 0:
                result = result+1

for i,j in itertools.combinations_with_replacement(list(range(1,N)),2):
        tmp = Z[i-1][j-1]+Z[0][j]
        if tmp ==0:
                result = result+1
        Z[i][j] = tmp
print(result)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = [0]
for i in range(n):
    b.append(a[i]+b[i])
ans = 0
for i in range(n+1):
    ans += b.count(b[0])-1
    b = b[1:]
print(ans)



# Optimized solution

n = int(eval(input()))
a = list(map(int,input().split()))
b = {0:0}
c = 0
for i in range(n):
    c = c+a[i]
    if c in b:
        b[c] += 1
    else:
        b[c] = 0
d = list(b.values())
ans = 0
for i in d:
    ans+= ((i+1)*i)//2
print(ans)