qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import collections
import math

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

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

print(s)
ans = 0
for v in collections.Counter(s).values():
    if v >= 2:
        ans += math.factorial(v) // math.factorial(v - 2) * math.factorial(2)
print(ans)

Fixed code:
import collections
import math

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

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

ans = 0
for v in collections.Counter(s).values():
    if v >= 2:
        ans += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ans)
Buggy code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
ans=0
accum = [0]*(n+1)
accum[0]=0
for i in range(n):
    accum[i+1]=a[i]+accum[i]

z=Counter(accum)
for k,v in z:
    ans+=n(n-1)/2
    
print(ans)


Fixed code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
ans=0
accum = [0]*(n+1)
accum[0]=0
for i in range(n):
    accum[i+1]=a[i]+accum[i]

z=Counter(accum)
for k,v in z.items():
    ans+=v*(v-1)/2
    
print(int(ans))
Buggy code:
import math
N = int(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 = math.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]))

Fixed code:
N = int(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]))
Buggy code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]
l=list(Counter(b).values())
print(sum(l)-len(l))

Fixed code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]
l=list(Counter(b).values())
for i in range(len(l)):
  x=l[i]
  l[i]=(x**2-x)//2
print(sum(l))
Buggy code:
import collections
N = int(input())
A = list(map(int, input().split()))
S = [A[0]]
for i in range(len(A)-1):
  S.append(A[i+1]+S[i])
L = list(collections.Counter(S).values())
s = 0
for l in L:
  s += int((l-1)*l//2)
print(s)

Fixed code:
import collections
N = int(input())
A = list(map(int, input().split()))
S = [0]
for i in range(len(A)):
  S.append(A[i]+S[i])
L = list(collections.Counter(S).values())
s = 0
for l in L:
  s += int((l-1)*l//2)
print(s)
Buggy code:
from itertools import accumulate
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
S=list(accumulate(A))
C=Counter(S)

def num(m):
    return m*(m-1)//2

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

Fixed code:
from itertools import accumulate
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
S=list(accumulate(A))
C=Counter(S)

def num(m):
    return m*(m-1)//2

ans=0
for k,v in C.items():
    if k==0:
        ans+=v
    if v>1:
        ans+=num(v)
print(ans)
Buggy code:
def main():
    n = int(input())
    a = list(map(int,input().split()))

    # ruiseki
    rui = [0]*(n+1)
    for i in range(n):
        rui[i+1] = rui[i] + a[i]
    from collections import Counter
    c = Counter(rui)
    
    # Query
    res = 0
    for v in c:
        res += v*(v-1)//2
    print(res)

if __name__ == '__main__':
    main()


Fixed code:
def main():
    n = int(input())
    a = list(map(int,input().split()))

    # ruiseki
    rui = [0]*(n+1)
    for i in range(n):
        rui[i+1] = rui[i] + a[i]
    from collections import Counter
    c = Counter(rui)
    
    # Query
    res = 0
    for v in c.values():
        res += v*(v-1)//2
    print(res)

if __name__ == '__main__':
    main()
Buggy code:

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

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
print(ans)


Fixed code:
n=int(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)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans=0
s=0
dic={}
for i in a:
  s+=i
  dic.get(s,0)+=1
  ans+=dic[s]-s!=0
print(ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
ans=0
s=0
dic={}
for i in a:
  s+=i
  dic[s]=dic.get(s,0)+1
  ans+=dic[s]
  if s!=0:
      ans-=1
print(ans)
Buggy code:
from itertools import accumulate
from collections import Counter
n = int(input())
nums = list(map(int,input().split()))
s = [0]+list(accumulate(nums))
ans = 0
for i in Counter(S).values():
    if i > 1:
        ans += i * (i - 1) // 2
print(ans)

Fixed code:
from itertools import accumulate
from collections import Counter
n = int(input())
nums = list(map(int,input().split()))
s = [0]+list(accumulate(nums))
ans = 0
for i in Counter(s).values():
    if i > 1:
        ans += i * (i - 1) // 2
print(ans)
Buggy code:
import collections

def comb2(n):
    return (n*n-1)//2

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

sums=[0]
for i in range(n):
    sums.append(sums[i]+a[i])
print(sums)
counts=collections.Counter(sums)
print(counts)

res=0

for i in counts:
    res += comb2(counts[i])
print(res)

Fixed code:
import collections

def comb2(n):
    return (n*(n-1))//2

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

sums=[0]
for i in range(n):
    sums.append(sums[i]+a[i])
counts=collections.Counter(sums)

res=0

for i in counts:
    res += comb2(counts[i])
print(res)
Buggy code:
from itertools import accumulate
n = int(input())
a_list = list(map(int,input.split()))
cumsum = accumulate(a_list)
num_dict = {0:1}
for s in cumsum :
  if str(s) in num_list.keys:
    num_dict[str(s)] += 1
  else:
    num_dict[str(s)] = 1

res = 0
for val in numdict:
  res += val * (val - 1)/2
  
print(res)
  

Fixed code:
from itertools import accumulate
n = int(input())
a_list = list(map(int,input().split()))
cumsum = list(accumulate(a_list))
num_dict = {0:1}
for s in cumsum :
  if s in num_dict.keys():
    num_dict[s] += 1
  else:
    num_dict[s] = 1

res = 0
for val in num_dict.values():
  res += val * (val - 1)//2
  
print(res)
Buggy code:
N = int(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']
print(sca)
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))

Fixed code:
N = int(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))
Buggy code:
n = int(input())
a = list(map(int,input().split()))

s = []
p = 0

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

x = 0
import collections
s = collections.Counter(s)


for i in range(len(s)):
    x += (s[i][1]*(z[i][1]-1))//2
print(x)


Fixed code:
n = int(input())
a = list(map(int,input().split()))

s = []
p = 0

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

x = 0
import collections
s = collections.Counter(s)

y,z = zip(*s.most_common())

for i in range(len(z)):
    x += (z[i]*(z[i]-1))//2
print(x)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
S = [0]
for i, a in enumerate(A):
    S.append(S[i]+a)
S = sorted(S)
prev = 0
ans = 0
tmp_count = S[0]
for s in S[1:]:
    if s==prev:
        tmp_count += 1
    else:
        ans += tmp_count*(tmp_count+1)//2
        tmp_count = 0
    prev = s
ans += tmp_count*(tmp_count+1)//2
print(ans)


Fixed code:
N = int(input())
A = list(map(int, input().split()))
S = [0]
for i, a in enumerate(A):
    S.append(S[i]+a)
S = sorted(S)
prev = S[0]
ans = 0
tmp_count = 0
for s in S[1:]:
    if s==prev:
        tmp_count += 1
    else:
        ans += tmp_count*(tmp_count+1)//2
        tmp_count = 0
    prev = s
ans += tmp_count*(tmp_count+1)//2
print(ans)
Buggy code:
N = int(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]
if x == 0:
    ans += 1
for i in range(1,N):
    y = S[i]
    if y == 0:
        ans += 1
    if x == y:
        ans += 1
    else:
        x = y
print(ans)

Fixed code:
N = int(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)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
d={}
sum=0
d[sum]=1
for i in range(N):
    sum+=A[i]
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
ans=0
print(d)
for x in d:
        ans+=d[x]*(d[x]-1)//2 # 1*0//2=0
print(ans)

Fixed code:
N=int(input())
A=list(map(int,input().split()))
d={}
sum=0
d[sum]=1
for i in range(N):
    sum+=A[i]
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
ans=0
for x in d:
        ans+=d[x]*(d[x]-1)//2 # 1*0//2=0
print(ans)
Buggy code:
n = int(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:
        m += 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)

Fixed code:

n = int(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)
Buggy code:
from collections import defaultdict

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

s = [0 for i in range(n+1)]
nums = {}
nums = defaultdict(int)
for i in range(0,n):
	s[i+1] = s[i] + a[i]

for i in range(0,n):
	nums[s[i]]+=1

res = 0
for key in nums:
	#print("key ",key," value ",nums[key])
	res += nums[key] * (nums[key] - 1) / 2

print(int(res))

Fixed code:
from collections import defaultdict

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

s = [0 for i in range(n+1)]
nums = {}
nums = defaultdict(int)
for i in range(0,n):
	s[i+1] = s[i] + a[i]

for i in range(0,n+1):
	nums[s[i]]+=1

res = 0
for key in nums:
	#print("key ",key," value ",nums[key])
	res += nums[key] * (nums[key] - 1) / 2

print(int(res))
Buggy code:
n = int(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 D.values():
    res += v*(v-1)//2
print(res)

Fixed code:
n = int(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 D.values():
    res += v*(v-1)//2
print(res)
Buggy code:
N = input()

A = raw_input().split(' ')

total = 0
B = [0]
dic = {}

for i in range(N):
    total += int(A[i])
    B.append(total)

for b in B:
    if b in dic:
        dic[b] +=1
    else:
        dic[b] = 1
def C(n):
    return int(n*(n-1)/2)

ans = 0;

for k,v in dic.items():
    ans += C(v)

print(ans)


Fixed code:
N = int(input())

A = input().split(' ')

total = 0
B = [0]
dic = {}

for i in range(N):
    total += int(A[i])
    B.append(total)

for b in B:
    if b in dic:
        dic[b] +=1
    else:
        dic[b] = 1
def C(n):
    return int(n*(n-1)/2)

ans = 0;

for k,v in dic.items():
    ans += C(v)

print(ans)
Buggy code:
# https://agc023.contest.atcoder.jp/tasks/agc023_a

import math


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


def convert_map(l):
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


N = list(map(int, input()))[0]

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

counter = [0]
for i in li:
    counter.append(counter[-1] + i)

print(counter)

d = convert_map(counter)

print(d)

patterns = 0
for key, value in d.items():
    if value >= 2:
        patterns += combinations_count(value, 2)

print(patterns)


Fixed code:
# https://agc023.contest.atcoder.jp/tasks/agc023_a

import math


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


def convert_map(l):
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


N = list(map(int, input()))[0]

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

counter = [0]
for i in li:
    counter.append(counter[-1] + i)

# print(counter)

d = convert_map(counter)

# print(d)

patterns = 0
for key, value in d.items():
    if value >= 2:
        patterns += combinations_count(value, 2)

print(patterns)
Buggy code:
n=int(input())
l=list(map(int,input().split()))
c=0
l1=[]
for i in l:
  c+=i
  l1.append(c)
l2={}
for i in l1:
  if i in l2:
    l2[i]+=1
  else:
    l2[i]=1
s=0
for i in l2:
  s+=l2[i]*(l2[i]-1)/2
print(s)

Fixed code:
n=int(input())
l=list(map(int,input().split()))
c=0
l1=[]
for i in l:
  c+=i
  l1.append(c)
l2={}
for i in l1:
  if i in l2:
    l2[i]+=1
  else:
    l2[i]=1
s=0
for i in l2:
  if i==0:
    s+=l2[i]
  s+=l2[i]*(l2[i]-1)//2
print(s)
Buggy code:
def subarraySum(nums, k):
  count = total = 0
  cache = collections.defaultdict(int)
  cache[0] = 1
  for num in nums:
    total += num
    count += cache[total - k]
    cache[total] += 1
    return count
A = input()
nums = list(map(int,input().split()))
k = 0
print(subarraySum(nums, 0))

Fixed code:
import collections
def subarraySum(nums, k):
    count = total = 0
    cache = collections.defaultdict(int)
    cache[0] = 1
    for num in nums:
        total += num
        count += cache[total - k]
        cache[total] += 1
    return count
A = input()
nums = list(map(int,input().split()))
k = 0
print(subarraySum(nums, 0))
Buggy code:
n = int(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 = d[0]
for k in d:
  if d[k] != 1:
    result += d[k] * (d[k] - 1) // 2
print(result)


Fixed code:
n = int(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)
Buggy code:
from collections import Counter

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

S = []

for i, a in enumerate(S):
    S.append(S[0] + a)

S.sort()
a = Counter(S).most_common()

cnt = 0

for i in range(len(a)):
    cnt += ((a[i][1]-1)*a[i][1])//2

print(cnt)


Fixed code:
from collections import Counter

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

S = [0]

for i, a in enumerate(A):
    S.append(S[i] + a)

S = sorted(S)
a = Counter(S).most_common()
cnt = 0

for i in range(len(a)):
    cnt += ((a[i][1]-1)*a[i][1])//2

print(cnt)
Buggy code:
from collections import Counter

N=int(input())
s=list(map(int,input().split()))

result=[0]
for i in s:
	result.append(result[-1]+i)

print(result)    

a=Counter(result)
ans=0
for j in a.values():
	ans+=j*(j-1)//2

print(ans)

Fixed code:
from collections import Counter

N=int(input())
s=list(map(int,input().split()))

result=[0]
for i in s:
	result.append(result[-1]+i)

a=Counter(result)
ans=0
for j in a.values():
	ans+=j*(j-1)//2

print(ans)
Buggy code:
from itertools import accumulate
from collections import Counter
N,*A = map(int, open('0').read().split())
B = accumulate(A)
c = Counter(B)
ans = c[0]+sum(v*(v-1)//2 for v in c.values())
print(ans)

Fixed code:
from itertools import accumulate
from collections import Counter
N,*A = map(int, open(0).read().split())
B = accumulate(A)
c = Counter(B)
ans = c[0]+sum(v*(v-1)//2 for v in c.values())
print(ans)
Buggy code:
n=int(input())
l=list(map(int,input().split()))
r[0]*(n+1)
for i in range(n):
    r[i+1]=r[i]+l[i]
r.sort()
r.append(100000000000)
f=1
ans=0
for i in range(n+1):
    if r[i]==r[i+1]:
        f+=1
    else:
        ans+=f*(f-1)//2
        f=1
print(ans)

Fixed code:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n+1)
for i in range(n):
    r[i+1]=r[i]+l[i]
r.sort()
r.append(100000000000)
f=1
ans=0
for i in range(n+1):
    if r[i]==r[i+1]:
        f+=1
    else:
        ans+=f*(f-1)//2
        f=1
print(ans)
Buggy code:
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_list = [0]
memo_dict = {}
for i in range(0,n):
    memo += list_a[i]
    memo_list.append(memo)
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))


Fixed code:
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_dict = {0:1}
for i in range(0,n):
    memo += list_a[i]
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))
Buggy code:
N = int(input())
A = list(map(int, input()))
S = [0]
ans = 0
for i in range(len(A)):
  S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
  if S[i-1] == S[i]:
    count += 1
  else:
    ans += count * (count-1) / 2
    count = 1
ans += count * (count-1) / 2
print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
S = [0]
ans = 0
for i in range(len(A)):
	S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
	if S[i-1] == S[i]:
		count += 1
	else:
		ans += (count * (count - 1)) / 2
		count = 1
ans += (count * (count - 1)) / 2
print(int(ans))
Buggy code:
N = int(input())
S = list(map(int, input().split()))
A = {}
t = 0
ans = 0
for s in S:
  t+=s
  if s in A:
    ans+=A[s]
    A[s]+=1
  else:
    A[s]=0

print(ans)

Fixed code:
N = int(input())
S = list(map(int, input().split()))
A = {}
t = 0
ans = 0
for s in S:
    t+=s
    if t == 0:
        ans+=1
    if t in A:
        A[t]+=1
        ans+=A[t]
    else:
        A[t]=0

print(ans)
Buggy code:
n=int(input())
lists=list(map(int,input().split()))
listsa=[0]
s=0
for i in range(n):
    s+=lists[i]
 
    listsa.append(s)
uselists=sorted(listsa)
print(uselists)
import collections
ans=collections.Counter(uselists)
a=0
for i in ans.values():
    a+=i-1
print(a)

Fixed code:
n=int(input())
lists=list(map(int,input().split()))
listsa=[0]
s=0
for i in range(n):
    s+=lists[i]
 
    listsa.append(s)

uselists=sorted(listsa)

import collections
ans=collections.Counter(uselists)
a=0
for i in ans.values():
    a+=(i-1)*(i)//2
print(a)
Buggy code:
from collections import Counter
import numpy as np

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

cumulative_sum = [0] + np.cumsum(A)
counts = Counter(cumulative_sum)
ans = 0
for v in counts.values():
    ans += v * (v-1) // 2
    
print(ans)

Fixed code:
from collections import Counter
import numpy as np

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

cumulative_sum = np.cumsum(A)
counts = Counter(cumulative_sum)
ans = 0
for v in counts.values():
    ans += v * (v-1) // 2
    
print(ans)
Buggy code:
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, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

Fixed code:
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, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n,*a=map(int,open(0).read().split())
print(sum(cmb(v,2)for k,v in Counter(accumulate(a)).items() if v>1)+list(accumulate(a)).count(0))
Buggy code:
N = int(input())
A = list(int(i) for i in input().split())
B = []
B.append(0)
n = 1
cnt = 0

for i in A:
    B[0] += i
    B.append(B[0])
B[0] = 0
B.sort()

for i in range(1,N+1):
    if B[i] == B[i-1]:
        n += 1
    else:
        cnt += int(n*(n-1)/2)
        n = 1

cnt += int(n*(n-1)/2)6

print(cnt)

Fixed code:
N = int(input())
A = list(int(i) for i in input().split())
B = []
B.append(0)
n = 1
cnt = 0

for i in A:
    B[0] += i
    B.append(B[0])
B[0] = 0
B.sort()

for i in range(1,N+1):
    if B[i] == B[i-1]:
        n += 1
    else:
        cnt += int(n*(n-1)/2)
        n = 1

cnt += int(n*(n-1)/2)

print(cnt)
Buggy code:
import itertools
import collections
n = int(input())
a = list(map(int,input().split()))

b = [0] + a
s = list(itertools.accumulate(b))


c = collections.Counter(s)
cm = c.most_common()
print(cm)
cnt = 0
for v in cm:
    if v[1] > 1:
        cnt += (v[1]*(v[1]-1) // 2) 
print(cnt)

Fixed code:
import itertools
import collections
n = int(input())
a = list(map(int,input().split()))

b = [0] + a
s = list(itertools.accumulate(b))


c = collections.Counter(s)
cm = c.most_common()
cnt = 0
for v in cm:
    if v[1] > 1:
        cnt += (v[1]*(v[1]-1) // 2)
print(cnt)
Buggy code:
N = int(input())
numbers = list(map(int, input().split()))
 
sums = [0] * (N + 1)
for i in range(len(numbers)):
  sums[i] = sums[i-1]+numbers[i]
sums = sorted(sums)

temp = ""
count = 0
res = 0
for i in range(len(sums)):
  if temp == sums[i]:
    count += 1
  else:
    if count >= 2:
      print(count)
      c = 1
      for j in range(count-1, count+1):
        c *= j
      res += c/2
    count = 1
    temp = sums[i]
    
if count >= 2:
  c = 1
  for i in range(count-1, count+1):
    c *= i
  res += c/2
    
print(int(res))

Fixed code:
N = int(input())
numbers = list(map(int, input().split()))
 
sums = [0] * (N + 1)
for i in range(len(numbers)):
  sums[i] = sums[i-1]+numbers[i]
sums = sorted(sums)

temp = ""
count = 0
res = 0
for i in range(len(sums)):
  if temp == sums[i]:
    count += 1
  else:
    if count >= 2:
      c = 1
      for j in range(count-1, count+1):
        c *= j
      res += c/2
    count = 1
    temp = sums[i]
    
if count >= 2:
  c = 1
  for i in range(count-1, count+1):
    c *= i
  res += c/2
    
print(int(res))
Buggy code:
a=int(input())
b=list(map(int, input().split(" ")))
c=0
d=0
e={0:1}
for i in b:
 c+=i
 d+=e.get(c,0)
 e[c]=e.get(c,0)+1


Fixed code:
a=int(input())
b=list(map(int, input().split(" ")))
c=0
d=0
e={0:1}
for i in b:
 c+=i
 d+=e.get(c,0)
 e[c]=e.get(c,0)+1

print(d)