CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = [0]
for i, num in enumerate(a):
    b.append(b[i] + a[i])
count = []
for num in list(set(b)):
    count.append(b.count(num))
ans = int(sum([(i*(i-1))/2 for i in count]))
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = [0]
for i, num in enumerate(a):
    b.append(b[i] + a[i])
count = {}
for num in b:
    if num in count:
        count[num] += 1
    else:
        count[num] = 1
ans = int(sum([(i*(i-1))/2 for i in list(count.values())]))
print(ans)
# Original solution
import collections

def main(N,A):
    B=[0]
    count = 0
    for i in range(N):
        T = A[i] + B[i]

        B.append(T)
    c = collections.Counter(B)

    for i in range(len(c)):
        k, v = c.popitem()
        for z in range(v):
            count += z

    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))

    main(N,A)


# Optimized solution
def main(N,A):
    B=[0]
    count = 0
    for i in range(N):
        T = A[i] + B[i]





            #print('count:',count)
#


    # B = [A[i] +B[i] for i in range(N)]
    #
    # count = [ count + 1 for m in range(len(B)) if B[i] - B[i-m] == 0]

        # for m in range(len(B)):
        #     if T - B[m] == 0:
        #         # print(i, m)
        #         # print(B[i],B[i-m])
        #         # print(T)
        #         # print("kore",B[i],B[i-m])
        #         count += 1
        B.append(T)


    B = sorted(B)
    # print(B)
    c = 0
    for i in range(len(B)):
        if i==0:
            continue
        if B[i] == B[i-1]:
            c+=1
            count +=c
            # print(c)
            # 
            # print(count)
        else:
            c = 0

    #
    # c = collections.Counter(B)
    # for i in range(len(c)):
    #     k, v = c.popitem()
    #     for z in range(v):
    #         count += z


    #print(count)
    #print(B)
    return print(count)

if __name__ == "__main__":
    N=int(input())
    A=list(map(int,input().split()))

    main(N,A)
# Original solution
import collections
n = int(eval(input()))
a = list(map(int, input().split()))

memo = collections.defaultdict(int)
memo[0] += 1
total = 0
cnt = 0
for i in range(n):
    total += a[i]
    cnt += memo[total]
    memo[total] += 1
print(cnt)


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

cs = [0]*(n+1)
cs[0] = a[0]
for i in range(1, n+1):
    cs[i] += cs[i-1] + a[i-1]
cs.sort()
total = 0
focus = None
count = 0
for s in cs:
    if s == focus:
        count += 1
    else:
        total += count * (count-1)//2
        focus = s
        count = 1
total += count * (count-1)//2
print(total)
# Original solution
N = int(eval(input()))

A_list = list(map(int, input().split(' ')))
A_len = len(A_list)

result = 0
for i in range(A_len):
    tmp = 0
    for j in range(i, A_len):
        tmp += A_list[j]
        if tmp == 0:
            result += 1

print(result)

# Optimized solution
import math

def calc_combination(n):
    combination = math.factorial(n) / (math.factorial(2) * math.factorial(n - 2))

    return combination


N = int(eval(input()))

list_A = list(map(int, input().split(' ')))

tmp_sum = 0
sum_map = {}
for A in list_A:
    tmp_sum += A
    sum_map[tmp_sum] = sum_map.get(tmp_sum, 0) + 1

result = sum_map.get(0, 0)
for value in list(sum_map.values()):
    if value >= 2:
        result += calc_combination(value)

print((int(result)))
# Original solution
def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    count = 0

    s = [0 for _ in range(N)]
    for i in range(N):
        if i == 0:
            s[i] = A[i]
        else:
            s[i] = s[i-1] + A[i]
    count += s.count(0)

    for i in range(N-1):
        del s[0]
        for j in range(len(s)):
            s[j] -= A[i]
        count += s.count(0)

    return count

if __name__ == '__main__':
    print((main()))


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

    s = [0 for _ in range(N+1)]
    for i in range(N):
        s[i+1] = s[i] + A[i]
    s.sort()
    n = 1
    for i in range(N):
        if s[i+1] == s[i]:
            n+=1
        else:
            count += n*(n-1)//2
            n = 1
    count += n*(n-1)//2
    return count

if __name__ == '__main__':
    print((main()))
# Original solution
N = int(eval(input()))
a = [int(i) for i in input().split()] 
b =[0]
i = 1
num = 0
while i < N+1:
    b.append(sum(a[0:i]))
    i = i+1
b.sort()
j = 0
num = 0
v = 0
while j < N:
    if b[j+1] == b[j]:
        v = v+1
    else:
        num = num + (v*(v+1))//2
        v = 0
    j = j +1
num = num + (v*(v+1))//2
print(num)

# Optimized solution
N = int(eval(input()))
a = [int(i) for i in input().split()] 
b =[0]*(N+1)
for i in range(N):
    b[i+1]= b[i] + a[i]
b.sort()
j = 0
num = 0
v = 0
while j < N:
    if b[j+1] == b[j]:
        v = v+1
    else:
        num = num + (v*(v+1))//2
        v = 0
    j = j +1
num = num + (v*(v+1))//2
print(num)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

sums = [[None for j in range(N-i)] for i in range(N)]

for i in range(N):
    for j in range(N-i):
        if j == 0:
            sums[i][j] = A[i]
        else:
            sums[i][j] = sums[i][j-1] + A[j+i]

count = 0
for line in sums:
    count += line.count(0)
    
print(count)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
sums_dic = {}
a = sum(A)
sums_dic[a] = 1

for n in range(1,N):
    a -= A[n-1]
    sums_dic[a] = sums_dic.setdefault(a, 0) + 1 

count = 0
for key, value in list(sums_dic.items()):
    if key == 0:
        count += value
    
    if value >= 2:
        count += value * (value - 1) // 2
    
print(count)
# Original solution
import sys
input=sys.stdin.readline

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

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

B = {}
for i in range(len(A)):
    x = sum(A[0:i+1])
    if x not in B:
        B[x] = 1
    else:
        B[x] += 1

ans = 0
for i in list(B.values()):
    if i >= 2:
        ans += combinations_count(i,2)

print(ans)


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

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

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

B = {}
x = 0
for i in A:
    x += i
    if x not in B:
        B[x] = 1
    else:
        B[x] += 1

ans = 0
for i in list(B.values()):
    if i >= 2:
        ans += combinations_count(i,2)

print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
    list_S.append(list_S[i] + a[i])

list_S.sort() # 昇順に並び替え 計算量はO(NlogN)
pre = list_S[0] # 前の数字
acc = 1 # 今まで何個同じ数字が連続したか
for i in range(1,n+1): # i番目の数字を見る．ちなみに0番目の数字は上2行でもう見た
    if list_S[i] == pre: # 今見ている数字が前の数字と同じなら，accに1加算
        acc += 1
    else: # 違うなら，ansに(acc個の中から2個選ぶ場合の数)を加算
        ans += acc * (acc-1) // 2
        pre = list_S[i]
        acc = 1 # accを初期化

ans += acc * (acc-1) // 2 # 一番最後に連続している数字群を足せていないので，ここで補正

    
print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
    list_S.append(list_S[i] + a[i])

dict_S = {}
for i in list_S:
    if i in dict_S:
        dict_S[i] += 1
    else:
        dict_S[i] = 1

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

print(ans)
# Original solution
# AGC023A - Zero-Sum Ranges
from collections import Counter
from itertools import accumulate


def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    C = list(Counter(list(accumulate(A)) + [0]).values())
    ans = sum(i * (i - 1) // 2 for i in C)
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# AGC023A - Zero-Sum Ranges
from collections import Counter
from itertools import accumulate


def main():
    n = int(eval(input()))
    A = [0] + list(map(int, input().split()))
    C = list(Counter(accumulate(A)).values())
    ans = sum(i * (i - 1) // 2 for i in C if i >= 2)
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from collections import defaultdict

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

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

d = defaultdict(int)
for i in range(len(S)):
  d[S[i]] += 1

ans = 0
for key, val in list(d.items()):
  ans += val * (val-1) // 2
print(ans)

# Optimized solution
from collections import defaultdict

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

d = defaultdict(int)
S = [0]*(N+1)
S[0], d[0] = 0, 1
for i in range(1, N+1):
  S[i] = S[i-1] + A[i-1]
  d[S[i]] += 1

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

print(ans)
# Original solution

n = int(eval(input()))
a = list(map(int,input().split()))
ans = 0
b = []

for i in range(n):
    for j in range(i+1,n+1):
        b = a[i:j]
#        print(b)

        if sum(b) == 0:
            ans += 1

print(ans)


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=[0]
for i in range(n):
  b.append(b[-1]+a[i])
#print(b)
ans = 0
b.sort()
for i in range(n+1):
  if i == 0:
    x=b[0]
    m=1
  else:
    if x==b[i]:
      m+=1
      if i==n:
        ans += m*(m-1)//2
    else:
      if m!=1:
        ans += m*(m-1)//2
        m=1
      x=b[i]
print(ans)
# Original solution
import bisect
 
N = int(eval(input()))
A = [int(i) for i in input().split()]
 
B = [0]
X = [0]
ans = 0
for i in range(N):
    X.append(X[i]+A[i])
    insert_index = bisect.bisect_left(B,X[i+1])
    ans += bisect.bisect_right(B,X[i+1])-insert_index
    B.insert(insert_index,X[i+1])
 
print(ans)

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

B = {}
B[0] = 1

s = 0
ans = 0

for a in A:
    s += a
    ans += B.get(s,0)
    B[s] = B.get(s,0)+1

print(ans)
# Original solution
n = int(eval(input()))
As = input().split()
As = [int(A) for A in As]
ss = [0]
sss = 0
for i in range(n):
        sss += As[i]
        ss.append(sss)
ans = 0
for i in range(0, n):
    for j in range(i + 1, n + 1):
        if ss[j] - ss[i] == 0:
            ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))
As = input().split()
As = [int(A) for A in As]
ss = [0]
sss = 0
nd = {0: 1}
for i in range(n):
        sss += As[i]
        ss.append(sss)
        if sss in nd:
            nd[sss] += 1
        else:
            nd[sss] = 1
ans = 0
for k in nd:
    if nd[k] > 0:
        ans += (nd[k] * (nd[k] - 1) // 2)
#for i in range(0, n):
#    for j in range(i + 1, n + 1):
#        if ss[j] - ss[i] == 0:
#            ans += 1
print(ans)
# Original solution
import sys
from collections import defaultdict as dd
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
cs = [0] * (N + 1)
d = dd(list)
res = 0
for i in range(N):
  cs[i + 1] = cs[i] + A[i]
for i in range(1, N + 1):
  d[cs[i]].append(i)
for i in range(N):
  x = bl(d[cs[i]], i + 1)
  res += max(len(d[cs[i]]) - x, 0)
  #print(res, i)
#print(d)
#print(cs)
print(res)

# Optimized solution
import sys
from collections import defaultdict as dd
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
cs = [0] * (N + 1)
res = 0
for i in range(N): cs[i + 1] = cs[i] + a[i]
d = dd(list)

for i in range(N + 1): d[cs[i]].append(i)
for i in range(N):
  s = cs[i]
  j = br(d[s], i)
  res += len(d[s]) - j
print(res)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
import math
s=[0]*(n+1)#累積和法
a.insert(0,0)
for i in range(1,n+1):
    s[i]=s[i-1]+a[i]
from collections import Counter
data=Counter(s)
def combination_cout(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))#組み合わせ計算
ans=[]
for i in list(data.values()):
    if 2<=i:#同じ文字が2個以上ある時の文字数
        ans.append(i)
total=0
for i in ans:
    total+=combination_cout(i,2)
print(total)
        


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
from collections import Counter
a.insert(0,0)
s=[0]*(n+1)
for i in range(1,n+1):
    s[i]=s[i-1]+a[i]
data=Counter(s)
cnt=[]
for i in list(data.values()):
    if 2<=i:
        cnt.append(i)
def combination_cnt(n):
    return n*(n-1)//2
ans=0
for i in range(len(cnt)):
    ans+=combination_cnt(cnt[i])
print(ans)
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
ca = [A[0]] + [0]*(N-1)

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

count = 1
number = 0
number += ca.count(0)
sca = sorted(ca) + ['hoge']
for i in range(1,N+1):
    if sca[i] == sca[i-1]:
        count += 1
    else:
        number += count*(count - 1)/2
        count = 1


print((int(number)))

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

dic = {}
S = 0
dic[0] = 1

for i in range(N):
    S += A[i]
    if S in dic:
        dic[S] += 1
    else:
        dic[S] = 1

number = 0

for i in dic:
    N = dic[i]
    number += N * (N - 1) / 2

print((int(number)))
# Original solution
N = int(eval(input()))
A_li = list(map(int, input().split()))
s_li = [0]
for i in range(N) :
    s_li.append(s_li[i] + A_li[i])
s_num = set(s_li)
ans = 0
for sn in s_num :
    cnt = s_li.count(sn)
    ans += cnt * (cnt - 1) // 2
print(ans)

# Optimized solution
N = int(eval(input()))
A_li = list(map(int, input().split()))
s_li = [0]
for i in range(N) :
    s_li.append(s_li[i] + A_li[i])
s_dic = {}
for s in s_li :
    if s in s_dic :
        s_dic[s] += 1
    else :
        s_dic[s] = 1
ans = 0
for sd in list(s_dic.values()) :
    ans += sd * (sd - 1) // 2
print(ans)
# Original solution
n=int(eval(input()))
arr=list(map(int,input().split()))
acum=[0]*(n+1)
acum[1]=arr[0]
cnt=0
for i in range(2,n+1):
  acum[i]=acum[i-1]+arr[i-1]
for i in range(n):
  for j in range(1,n-i+1):
    if acum[i+j]-acum[i]==0:
      cnt+=1
print(cnt)

# Optimized solution
n=int(eval(input()))
arr=list(map(int,input().split()))
acum=[0]*(n+1)
cnt=0
for i in range(1,n+1):
  acum[i]=acum[i-1]+arr[i-1]
acum=sorted(acum)
acum.append(10**10)
tmp=1
for i in range(1,len(acum)):
  if  acum[i]==acum[i-1]:
    tmp+=1
  else:
    cnt+=tmp*(tmp-1)//2
    tmp=1
print(cnt)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
s = [0]*(len(a)+1)
for i in range(len(a)):
    s[i+1] = s[i] + a[i]
s.sort()
n = 0
for x in set(s):
    l = s.count(x)
    n += l*(l-1)/2
print((int(n)))

# Optimized solution
N = int(eval(input()))
a = list(map(int,input().split()))
s = [0]*(len(a)+1)
for i in range(len(a)):
    s[i+1] = s[i] + a[i]
b = {}
for x in s:
    if str(x) not in b:
        b[str(x)] = 1
    else:
        b[str(x)] += 1
n = 0
for x in b:
    n += b[x]*(b[x]-1)/2
print((int(n)))
# Original solution
n = int(eval(input()))
s = list(map(int, input().split()))
count = 0
cl = []
sm = 0
for i in range(n):
  sm+=s[i]
  cl.append(sm)

        
m = set(cl)
st = set(cl)
for x in st:
  t = cl.count(x)
  count+=int(t*(t-1)/2)

count+=cl.count(0)
print(count)

# Optimized solution
n = int(eval(input()))
s = list(map(int, input().split()))
count = 0
dic = {}
cl = []
sm = 0
for i in range(n):
  sm+=s[i]
  if sm not in list(dic.keys()):
    dic.update({sm:1})
  else:
    dic[sm]+=1

        
for x in list(dic.keys()):
  t = dic[x]
  if x==0:
    count+=dic[x]
  count+=int(t*(t-1)/2)

print(count)
# Original solution
from collections import defaultdict
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0] -q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

#　aの逆元を求める
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def combination(m,k):
    res = 1
    for i in range(1,m+1):
        res = res*i%(10**9+7)
    for i in range(1,k+1):
        res = res*mod_inv(i,10**9+7)
    for i in range(1,m-k+1):
        res = res*mod_inv(i,10**9+7)
    return res%(10**9+7)

def main():
    n = int(eval(input()))
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in list(cnt.values()):
        if i==1:
            continue
        ans += combination(i,2)
    print(ans)



if __name__ == '__main__':
    main()

# Optimized solution
from collections import defaultdict
def main():
    n = int(eval(input()))
    ls = [int(x) for x in input().split()]
    cumsum = [0]*(n+1)
    for i in range(1,n+1):
        cumsum[i] = cumsum[i-1]+ls[i-1]
    cnt = defaultdict(int)
    for i in cumsum:
        cnt[i] +=1
    ans = 0
    for i in list(cnt.values()):
        if i==1:
            continue
        ans += int(i*(i-1)/2)
    print(ans)



if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = [0]
for i in range(n):
    x = 0
    x += b[i] + a[i]
    b.append(x)
b.sort()
check = 1000000000000
ans = 0
for i in range(n+1):
    if b[i] != check:
        y = b.count(b[i])
        ans += y * (y - 1) //2
        check = b[i]
print(ans)
    



# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = [0]
for i in range(n):
    x = 0
    x += b[i] + a[i]
    b.append(x)
b.sort()
check = b[0]
count = 1
ans = 0
for i in range(1,n+1):
    if b[i] == check:
        count += 1
    else:
        ans += count * (count - 1) // 2
        check = b[i]
        count = 1
ans += count * (count - 1) // 2            
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
s = [0]
sum = 0
for i in range(len(a)):
    sum += a[i]
    s.append(sum)
ans = 0
for s_ in set(s):
    k = s.count(s_)
    ans += k*(k-1)//2
print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
s = [0]
sum = 0
for i in range(len(a)):
    sum += a[i]
    s += [sum]
s.sort()
ans = 0
k = 1
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        k+=1
        if i==len(s)-1:
            ans += k*(k-1)//2
    else:
        if k>1:
            ans += k*(k-1)//2
        k = 1
print(ans)
# Original solution
from itertools import accumulate
from collections import Counter

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

b = list(accumulate(a))
b = [0]+b

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

print(ans)

# Optimized solution
from itertools import accumulate
from collections import Counter

n = eval(input())
c = Counter(accumulate(list(map(int, input().split()))))
c[0]+=1
ans = 0
for x in c:
    ans += c[x]*(c[x]-1)//2

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

cnt = 0


for i in range(N):
    now = 0
    for j in A[i:]:
        now += j
        if now == 0:
            cnt += 1

print(cnt)

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

cnt = 0

DP = [0] * (N + 1)

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

dic = {}

for i in DP:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

for i in list(dic.values()):
    cnt += (i * (i - 1)) // 2

print(cnt)
# Original solution
from collections import Counter

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

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

ans = 0
for i in range(n):
    if l_sum[i] == 0:
        ans += 1
    for j in range(i+1, n):
        if l_sum[i] == l_sum[j]:
            ans += 1

print(ans)

# Optimized solution
from collections import Counter

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

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

c_sum = Counter(l_sum)

# print(c_sum)
ans = 0
for i in c_sum:
    if c_sum[i] > 1:
        ans += c_sum[i] * (c_sum[i] - 1) // 2

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

d = defaultdict(int)

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

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

print(ans)


# Optimized solution
import collections
N = int(eval(input()))
A = [int(i) for i in input().split()]

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

C = collections.Counter(S)

ans = 0
for v in list(C.values()):
    if v >= 2:
        ans += v*(v-1)//2
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
a=[0]+a
for i in range(1,n+1):
    a[i]+=a[i-1]
#print(a)
dic={}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
ans=0
for i in list(dic.values()):
    #print(i)
    ans+=i*(i-1)//2
print(ans)

# Optimized solution
import itertools
n=int(eval(input()))
a=list(map(int,input().split()))
b=[0]+[i for i in itertools.accumulate(a)]
dic={}
for i in b:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
ans=0
for i in list(dic.values()):
    ans+=i*(i-1)//2
print(ans)
# Original solution
import itertools
def aCb(a,b):return len(list(itertools.combinations([0]*a,b)))#組み合わせ
n,a=int(eval(input())),list(map(int,input().split()));b=[0]#入力
b+=list(itertools.accumulate(a))#累積和
b.sort();c=1;ans=0
for i in range(n):#2個以上存在する要素があるとき、cC2を加える
  if b[i]==b[i+1]:c+=1
  else:
    if c>=2:ans+=aCb(c,2)
    c=1
if c>=2:ans+=aCb(c,2)#アレ対策
print(ans)

# Optimized solution
n,a=int(eval(input())),list(map(int,input().split()));b=[0]
for i in range(n):b.append(b[i]+a[i])
b.sort();c=1;ans=0
for i in range(n):
  if b[i]==b[i+1]:c+=1
  else:
    if c>=2:ans+=(c*(c-1))//2
    c=1
if c>=2:ans+=(c*(c-1))//2
print(ans)
# Original solution
from collections import Counter

n = int(eval(input()))
a = [int(i) for i in input().split()]

a_ = [0]

for i in range(n):
    a_.append(a_[i] + a[i])

cnt = 0

def sum(i):
    return int((i + 1) / 2 * i)

for i in list(Counter(a_).values()):
    cnt += sum(i-1)

print(cnt)

# Optimized solution
from collections import Counter

n = int(eval(input()))
a = [int(i) for i in input().split()]

a_ = [0]

for i in range(n):
    a_.append(a_[i] + a[i])

cnt = 0

def sum(i):
    return i * (i-1) // 2

for i in list(Counter(a_).values()):
    cnt += sum(i)

print(cnt)
# Original solution
def get_input():
    N = int(eval(input()))
    numbers = [int(i) for i in input().split()]
    return N, numbers


def DPsolve(N, numbers):
    count = 0
    dp = [[1 for i in range(len(numbers))] for j in range(len(numbers))]
    for i in range(N):
        for j in range(N-i):
            if j == 0:
                dp[i][j] = numbers[i]
            else:
                dp[i][j] = dp[i][j-1] + numbers[i+j]
            if dp[i][j] == 0:
                count += 1
    return dp, count

if __name__ == '__main__':
    N, numbers = get_input()
    dp, count = DPsolve(N, numbers)
    print(count)

# Optimized solution
def get_input():
    N = int(eval(input()))
    numbers = [int(i) for i in input().split()]
    return N, numbers

def DPsolve(N, numbers):
    count = 0
    dp = [[1 for i in range(len(numbers))] for j in range(len(numbers))]
    for i in range(N):
        for j in range(N-i):
            if j == 0:
                dp[i][j] = numbers[i]
            else:
                dp[i][j] = dp[i][j-1] + numbers[i+j]
            if dp[i][j] == 0:
                count += 1
    return dp, count

if __name__ == '__main__':
    N, numbers = get_input()
    s = [0]
    for i in range(N):
        s.append(s[-1] + numbers[i])
    s.sort()
    count = 1
    result = 0
    for i in range(N):
        if(s[i] == s[i+1]):
            count += 1
        else:
            result += count * (count -1 ) // 2
            count = 1
    result += count * (count -1 ) // 2
    print(result)