qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import numpy as np

N, M = map(int, input().split())
H = [int(a) for a in input().split()]
good = np.zeros(N, dtype=int)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    print(H[a], H[b])
    if H[a] > H[b]:
        good[b] += 1
    elif H[a] < H[b]:
        good[a] += 1

ans = 0
print(good)
for i in good:
    if i == 0:
        ans += 1
print(ans)


Fixed code:
import numpy as np

N, M = map(int, input().split())
H = [int(a) for a in input().split()]
good = np.zeros(N, dtype=int)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] > H[b]:
        good[b] += 1
    elif H[a] < H[b]:
        good[a] += 1
    else:
        good[a] += 1
        good[b] += 1

ans = 0
for i in good:
    if i == 0:
        ans += 1
print(ans)
Buggy code:
n, m = map(int, input().split())
arr = [0] + list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
for i in range(1, n + 1):
    for j in g[i]:
        if arr[j] >= arr[i]:
            break
        else:
            ans += 1

print(ans)


Fixed code:
n, m = map(int, input().split())
arr = [0] + list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
for i in range(1, n + 1):
    for j in g[i]:
        if arr[j] >= arr[i]:
            break
    else:
        ans += 1

print(ans)
Buggy code:
N, M = map(int, input().split(" "))
height = list(map(int, input().split(" ")))
flag = [1 for i in height]
for i in range(M):
  a, b = map(int, input().split(" "))
  if height[a - 1] > height[b - 1]:
    flag[b - 1] = 0
  elif height[b - 1] > height[a - 1]:
    flag[a - 1] = 0
print(sum(flag))

Fixed code:
N, M = map(int, input().split(" "))
height = list(map(int, input().split(" ")))
flag = [1 for i in height]
for i in range(M):
  a, b = map(int, input().split(" "))
  if height[a - 1] > height[b - 1]:
    flag[b - 1] = 0
  elif height[b - 1] > height[a - 1]:
    flag[a - 1] = 0
  else:
    flag[a - 1] = 0
    flag[b - 1] = 0
print(sum(flag))
Buggy code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
nn = [1]*n
for _ in range(m):
    a,b	= map(int,input().split())

    if h[a-1] <	h[b-1]:
	nn[a-1]=0
    else:
	nn[b-1]=0

print(sum(nn))

Fixed code:
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
nn = [1]*n
for _ in range(m):
    a,b = map(int,input().split())
    if h[a-1] ==h[b-1]:
        nn[a-1]=0
        nn[b-1]=0
    elif h[a-1] < h[b-1]:
        nn[a-1]=0
    else:
        nn[b-1]=0

print(sum(nn))
Buggy code:
import numpy as np
import copy

def main():
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    maxH  = np.zeros(N)

    for itr in range(M):
        A, B = list(map(int, input().split()))
        if H[A- 1] == H[B- 1] :
            maxH[A- 1] = -1
            maxH[B- 1] = -1
        elif H[A- 1] > H[B- 1] :
            maxH[A- 1] = copy.copy(H[A- 1])
            maxH[B- 1] = copy.copy(H[A- 1])
        elif H[A- 1] < H[B- 1] :
            maxH[A- 1] = copy.copy(H[B- 1])
            maxH[B- 1] = copy.copy(H[B- 1])
    
    result = 0
    for itr in range(N):
        if H[itr] == maxH[itr] or maxH[itr] == 0:
            result += 1
    print(maxH)
    print(result)

if __name__ == "__main__":
    main()




Fixed code:
import numpy as np
import copy

def main():
    N, M  = list(map(int, input().split()))
    H     = list(map(int, input().split()))
    maxH  = np.zeros(N)

    for itr in range(M):
        A, B = list(map(int, input().split()))
        if H[A- 1] == H[B- 1] :
            maxH[A- 1] = copy.copy(H[A- 1]) + 1
            maxH[B- 1] = copy.copy(H[A- 1]) + 1
        elif H[A- 1] > H[B- 1] :
            if maxH[A- 1] < H[A- 1] :
                maxH[A- 1] = copy.copy(H[A- 1])
            if maxH[B- 1] < H[A- 1] :
                maxH[B- 1] = copy.copy(H[A- 1])
        elif H[A- 1] < H[B- 1] :
            if maxH[A- 1] < H[B- 1] :
                maxH[A- 1] = copy.copy(H[B- 1])
            if maxH[B- 1] < H[B- 1] :
                maxH[B- 1] = copy.copy(H[B- 1])
    
    result = 0
    for itr in range(N):
        if H[itr] == maxH[itr] or maxH[itr] == 0:
            result += 1
    #print(maxH)
    print(result)

if __name__ == "__main__":
    main()
Buggy code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
tunagari=[[] for i in range(N)]
TF=[True for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]>H[B-1]:
    TF[B-1]=False
  elif H[A-1]<H[B-1]:
    TF[A-1]=False:
  else:
    TF[A-1]=False
    TF[B-1]=False
ans=0
for i in range(N):
  if TF[i]==True:
    ans+=1
print(ans)

Fixed code:
N,M=map(int,input().split())
H=list(map(int,input().split()))
tunagari=[[] for i in range(N)]
TF=[True for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  if H[A-1]>H[B-1]:
    TF[B-1]=False
  elif H[A-1]<H[B-1]:
    TF[A-1]=False
  else:
    TF[A-1]=False
    TF[B-1]=False
ans=0
for i in range(N):
  if TF[i]==True:
    ans+=1
print(ans)
Buggy code:
import numpy as np
N, M = map(int, input().split(' '))

height = np.array(list(map(int, input().split(' '))))
#height_all = height

for i in range(M):
  a, b = map(int, input().split(' '))
  #print(a, b, height[a - 1], height[b - 1])
  if height[a - 1] > height[b - 1]:
    height[b - 1] = 0
   
  else:
    height[a - 1] = 0
  
print(len(np.nonzero(height)))

Fixed code:
import numpy as np
N, M = map(int, input().split(' '))

height = np.array(list(map(int, input().split(' '))))
height_all = np.array(list(height))

for i in range(M):
  a, b = map(int, input().split(' '))
  #print(a, b, height[a - 1], height[b - 1])
  if height[a - 1] > height[b - 1]:
    height_all[b - 1] = 0
  
  elif height[a - 1] == height[b - 1]:
    height_all[a - 1] = 0
    height_all[b - 1] = 0
    
  else:
    height_all[a - 1] = 0
    
  #print(height_all)
  
print(len(np.nonzero(height_all)[0]))
Buggy code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import copy
n, m = map(int, input().split())
h = list(map(int, input().split()))
ok = [True for i in range(n)]
maxu=copy.copy(h)
for i in range(m):
    p = list(map(int, input().split()))
    if maxu[p[0]-1]<maxu[p[1]-1]:
        ok[p[0]-1]=False
        maxu[p[0]-1] = h[p[1]-1]
    elif maxu[p[0]-1] > maxu[p[1]-1]:
        ok[p[1]-1] = False
        maxu[p[1]-1] = h[p[0]-1]
    elif maxu[p[0]-1] == maxu[p[1]-1]:
        ok[p[1]-1]=False
        ok[p[0]-1]=False
cnt=0
for i in range(len(ok)):
    if ok[i]==True:
        cnt+=1
print(maxu)
print(cnt)



Fixed code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, m = map(int, input().split())
h = list(map(int, input().split()))
ok = [True for i in range(n)]

for i in range(m):
    p = list(map(int, input().split()))
    if h[p[0]-1]<h[p[1]-1]:
        ok[p[0]-1]=False
    elif h[p[0]-1] > h[p[1]-1]:
        ok[p[1]-1] = False
    elif h[p[0]-1] == h[p[1]-1]:
        ok[p[1]-1] = False
        ok[p[0]-1] = False
cnt=0
for i in range(len(ok)):
    if ok[i]==True:
        cnt+=1
#print(ok)
print(cnt)
Buggy code:
n,m=map(int,input().split())

h=list(map(int,input().split()))
ans=[0]*n

for i in range(m):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if a==b:
    ans[a]+=1
    ans[b]+=1
  elif a>b:
    ans[b]+=1
  else:
    ans[a]+=1

print(ans.count(0))

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

h=list(map(int,input().split()))
ans=[0]*n

for i in range(m):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if h[a]==h[b]:
    ans[a]+=1
    ans[b]+=1
  elif h[a]>h[b]:
    ans[b]+=1
  else:
    ans[a]+=1
#print(ans)
print(ans.count(0))
Buggy code:
n,m = map(int, input().split())
H = list(map(int, input().split()))
s = [[0]]*m

for i in range(m):
    a, b = map(int, input().split())
    s[a-1].append(H[b-1])
    s[b-1].append(H[a-1])

c = 0
for j in range(n):
    if H[j] > max(s[j]):
        c+= 1

print(c)    

Fixed code:
n,m = map(int, input().split())
H = list(map(int, input().split()))
s = [[0] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    s[a-1].append(H[b-1])
    s[b-1].append(H[a-1])
c = 0
for j in range(n):
    if H[j] > max(s[j]):
        c+= 1
print(c)
Buggy code:
def peak():
    condition = input()
    condition_list = condition.split()
    N = int(condition_list[0])
    M = int(condition_list[1])
    
    height_str = input()
    height_list_str = height_str.split()
    height_list = [0]
    for i in height_list_str:
        height_list.append(int(i))
    
    road_list = []
    for i in range(0, M):
        road_str = input()
        road_set_str = road_str.split()
        road_set = []
        for i in road_set_str:
            road_set.append(int(i))
        road_list.append(road_set)
    
    #road_list = []
    #for i in road_list_str:
        #road_list.append(int(i))
    
    good_point = set()
    for i in range(1, N+1):
        good_point.add(i)
    
    for road_set in road_list:
        i = road_set[0]
        j = road_set[1]
        if height_list[i] < height_list[j]:
            good_point.discard(i)
        elif height_list[i] > height_list[j]:
            good_point.discard(j)
    
    print(len(good_point))
    return

peak()

Fixed code:
def peak():
    condition = input()
    condition_list = condition.split()
    N = int(condition_list[0])
    M = int(condition_list[1])
    
    height_str = input()
    height_list_str = height_str.split()
    height_list = [0]
    for i in height_list_str:
        height_list.append(int(i))
    
    road_list = []
    for i in range(0, M):
        road_str = input()
        road_set_str = road_str.split()
        road_set = []
        for i in road_set_str:
            road_set.append(int(i))
        road_list.append(road_set)
    
    #road_list = []
    #for i in road_list_str:
        #road_list.append(int(i))
    
    good_point = set()
    for i in range(1, N+1):
        good_point.add(i)
    
    for road_set in road_list:
        i = road_set[0]
        j = road_set[1]
        if height_list[i] < height_list[j]:
            good_point.discard(i)
        elif height_list[i] > height_list[j]:
            good_point.discard(j)
        elif height_list[i] == height_list[j]:
            good_point.discard(i)
            good_point.discard(j)
    
    #print(good_point)
    print(len(good_point))
    return

peak()
Buggy code:
N,M=map(int,input().split())

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

tower=[0]*N



for i in range(M):
    A,B=map(int,input().split())
    if height[A-1]<height[B-1]:
        tower[A-1]=1
    else:
        tower[B-1]=1
        
    print(tower)
    
print(tower.count(0))
        

Fixed code:
N,M=map(int,input().split())

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

tower=[0]*N

for i in range(M):
    A,B=map(int,input().split())
    if height[A-1]<height[B-1]:
        tower[A-1]=1
    elif height[A-1]>height[B-1]:
        tower[B-1]=1
    else:
        tower[A-1]=1
        tower[B-1]=1
    
print(tower.count(0))
Buggy code:
N = int(input())

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

L = {}
R = {}

for i in range(N):
  t = A[i]+i
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  s = i - A[i]
  if s in R:
    R[s] += 1
  else:
    R[s] = 1  
print(L,R)
ans = 0
for i in range(N):
  t = A[i]+i
  #ans += R[t]
  if t in R.keys():
    ans += R[t]
    print(t,R[t])
print(ans)

Fixed code:
N = int(input())

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

L = {}
R = {}

for i in range(N):
  t = A[i]+i
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  s = i - A[i]
  if s in R:
    R[s] += 1
  else:
    R[s] = 1  
#print(L,R)
ans = 0
for i in range(N):
  t = A[i]+i
  #ans += R[t]
  if t in R.keys():
    ans += R[t]
    #print(t,R[t])
print(ans)
Buggy code:
import collections
N = int(input())
A = list((map(int,input().split())))

index = list(range(1,N+1))

R = [index[i] - A[i] for i in range(N)]
L = [index[j] + A[j] for j in range(N)]

R_dict = collections.Counter(R)
L_dict = collections.Counter(L)

ans=0
for i in R_dict.keys()&L_dict.keys():
    ans+=max(R_dict[i], L_dict[i])

print(ans)

Fixed code:
import collections
N = int(input())
A = list((map(int,input().split())))

index = list(range(1,N+1))

R = [index[i] - A[i] for i in range(N)]
L = [index[j] + A[j] for j in range(N)]

R_dict = collections.Counter(R)
L_dict = collections.Counter(L)

ans=0
for i in R_dict.keys()&L_dict.keys():
    ans+=R_dict[i]*L_dict[i]

print(ans)
Buggy code:
import collections

input()
p = list(map(int, input().split()))
map1 = collections.defualtdict(lambda:0)
map2 = collections.defaultdict(lambda:0)

for i, v in enumerate(p):
  map1[i+v] += 1
  map2[i-v] += 1

ans = 0
for i in map1:
  if i in map2:
    ans += map2[i]
print(i)

Fixed code:
import collections
 
input()
p = list(map(int, input().split()))
map1 = collections.defaultdict(lambda:0)
map2 = collections.defaultdict(lambda:0)
 
for i, v in enumerate(p):
  map1[i+v] += 1
  map2[i-v] += 1

ans = 0
for i in map1:
  if i in map2:
    ans += map1[i] * map2[i]

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

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

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

L = [i + A[i] for i in range(N)]
R = [i - A[i] for i in range(N)]

countL = collections.Counter(L)

countR = collections.Counter(R)


print([countL[n] * countR[n] for n in countL.keys()])

Fixed code:
import collections

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

L = [i + A[i] for i in range(N)]
R = [i - A[i] for i in range(N)]

countL = collections.Counter(L)

countR = collections.Counter(R)


print(sum([countL[n] * countR[n] for n in countL.keys()]))
Buggy code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
input = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if Asum[i] == Adif[j]:
            ans += 1

print(ans)


Fixed code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
d = defaultdict(int)
for i in range(N):
    ans += d[Adif[i]]
    d[Asum[i]] += 1

print(ans)
Buggy code:
import collections

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

# N = 32
# A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5]

# N = 6
# A = [2, 3, 3, 1, 3, 1]

i = [k for k in range(1,N+1)]
j = [k for k in range(1,N+1)]

Li = [i[k]+A[k] for k in range(N)]
Rj = [j[k]-A[k] for k in range(N)]

Li = collections.Counter(Li)

counter = 0
for r in Rj:
    counter += Li[r]

Fixed code:
import collections

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

# N = 32
# A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5]

# N = 6
# A = [2, 3, 3, 1, 3, 1]

i = [k for k in range(1,N+1)]
j = [k for k in range(1,N+1)]

Li = [i[k]+A[k] for k in range(N)]
Rj = [j[k]-A[k] for k in range(N)]

Li = collections.Counter(Li)

counter = 0
for r in Rj:
    counter += Li[r]
print(counter)
Buggy code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
ans = 0

for i, x in enumerate(A, 1):
    ans += D[i-x]
    D[x+i] += 1

print(ans, D)

Fixed code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
ans = 0

for i, x in enumerate(A, 1):
    ans += D[i-x]
    D[x+i] += 1

print(ans)
Buggy code:
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)
for key in a:
    d[key] += 1

for i in range(n):
    cnt += d[i-a[i]]
    d[i + a[i]] += 1

print(cnt)


Fixed code:
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)

for i in range(n):
    cnt += d[i-a[i]]
    d[i + a[i]] += 1

print(cnt)
Buggy code:
N = int(input())
# N = int(input())
A = list(map(int, input().split()))


ans = 0

d1 = {}
d2 = {}
for i in range(N):
    if i+1 + A[i] in d1:
        d1[i+1 + A[i]] += 1
    else:
        d1[i+1 + A[i]] = 1
    if i+1 - A[i] in d2:
        d2[i+1 - A[i]] += 1
    else:
        d2[i+1 - A[i]] = 1


for a in d1.keys():
    if a in d2:
        # print(d2[a])
        ans += d2[a]
        ans += d1[a]-1


# print(d1)
# print(d2)
print(ans)




Fixed code:
N = int(input())
# N = int(input())
A = list(map(int, input().split()))


ans = 0

d1 = {}
d2 = {}
for i in range(N):
    if i+1 + A[i] in d1:
        d1[i+1 + A[i]] += 1
    else:
        d1[i+1 + A[i]] = 1
    if i+1 - A[i] in d2:
        d2[i+1 - A[i]] += 1
    else:
        d2[i+1 - A[i]] = 1


for a in d1.keys():
    if a in d2:
        # print(d2[a])
        ans += d2[a]*d1[a]


# print(d1)
# print(d2)
print(ans)
Buggy code:
import sys
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
a = Li()
x = [0]*n
ans = 0
for i in range(n): 
  print(x)
  if a[i]+i < n:
    x[a[i]+i] += 1
  if i-a[i] >= 0:
    ans += x[i-a[i]]
      
print(ans)

Fixed code:
import sys
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
a = Li()
x = [0]*n
ans = 0
for i in range(n): 
  if a[i]+i < n:
    x[a[i]+i] += 1
  if i-a[i] >= 0:
    ans += x[i-a[i]]
      
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
plus_lis = [A[i] + i for i in range(N)]
minus_lis = [k - A[k] for k in range(N)]
plus_lis.sort()
minus_lis.sort()

ans_lis = [0] * 10 ** 6
for x in plus_lis:
    if x < 10 ** 6:
        ans_lis[x-1] += 1
for y in minus_lis:
    if y > 0:
        ans += ans_lis[x-1]
print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
plus_lis = [A[i] + i for i in range(N)]
minus_lis = [k - A[k] for k in range(N)]

ans_lis = [0] * 10 ** 6
for x in plus_lis:
    if x < 10 ** 6:
        ans_lis[x-1] += 1
for y in minus_lis:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)
Buggy code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    A = LI()

    memo = {}
    ans = 0
    for j in range(n):
        sa = j - A[j]
        ans += memo.get(sa, 0)
        wa = j + A[j]
        memo[wa] = memo.get(wa, 0) + 1
        print(memo)
    print(ans)


if __name__ == '__main__':
    solve()


Fixed code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    A = LI()

    memo = {}
    ans = 0
    for j in range(n):
        sa = j - A[j]
        ans += memo.get(sa, 0)
        wa = j + A[j]
        memo[wa] = memo.get(wa, 0) + 1
        # print(memo)
    print(ans)


if __name__ == '__main__':
    solve()
Buggy code:
from collections import Counter

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

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

Ap = [A[i]+i for i in range(len(A))]
Am = [i-A[i] for i in range(len(A))]

S = set(Ap) & set(Am)

Cp = Counter(Ap)
Cm = Counter(Am)

cnt = 0
for i in S:
  cnt += Cp[i]*Cm[i]

Fixed code:
from collections import Counter

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

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

Ap = [A[i]+i for i in range(len(A))]
Am = [i-A[i] for i in range(len(A))]

S = set(Ap) & set(Am)

Cp = Counter(Ap)
Cm = Counter(Am)

cnt = 0
for i in S:
  cnt += Cp[i]*Cm[i]
  
print(cnt)
Buggy code:
from collections import Counter

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

r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

ans = 0
b = Counter(r)
for i in l:
   ans += b.get(i, 0)

print(ans)


Fixed code:
from collections import Counter

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

l = []
r = []
for i, ai in enumerate(a):
   l.append(i+ai)
   r.append(i-ai)

ans = 0
b = Counter(r)
for i in l:
   ans += b.get(i, 0)

print(ans)
Buggy code:
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
B = [0] * (n)
C = [0] * (n)
kouho = defaultdict(int)
ans = 0
for i in range(n):
    kouho[A[i] - i] += 1
    ans += kouho[A[i] + i]
print(ans)


Fixed code:
from collections import defaultdict

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

kouho = defaultdict(int)
ans = 0
for i in range(n):
    kouho[A[i] + (i + 1)] += 1
    ans += kouho[(i + 1) - A[i]]

print(ans)
Buggy code:
from collections import Counter

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

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

Fixed code:
from collections import Counter

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

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

print(r)
Buggy code:
n = int(input())
A=list(map(int,input().split()))
cnt=0
B=[]
C=[]
for i,a in enumerate(A):
    B.append(A[i]+i)
    C.append(A[i]-i)
from collections import Counter
Bd=dict(Counter(B))
Cd=dict(Counter(C))
cnt=0
for k in Bd.keys():
    b=Bd.get(k)
    c=Cd.get(k)
    if b and c:
        cnt+=b*c
print(cnt)


Fixed code:
n = int(input())
A=list(map(int,input().split()))
cnt=0
B=[]
C=[]
for i,a in enumerate(A):
    B.append(A[i]+i)
    C.append(A[i]-i)
from collections import Counter
Bd=dict(Counter(B))
Cd=dict(Counter(C))
cnt=0
for k in Bd.keys():
    b=Bd.get(k)
    c=Cd.get(-k)
    if b and c:
        cnt+=b*c
print(cnt)