qyliang/CodeNanoFix huggingface dataset:
Buggy code:
a=[]
for i in range(int(input())):
  a+=input()
b=[]
for i in range(int(input())):
  b+=input()
ans=0
for i in range(len(a)):
  ans=max(ans,a.count(a[i])-b.count(a[i]))
print(ans)

Fixed code:
a=[]
for i in range(int(input())):
  a+=[input()]
b=[]
for i in range(int(input())):
  b+=[input()]
ans=0
for i in range(len(a)):
  ans=max(ans,a.count(a[i])-b.count(a[i]))
print(ans)
Buggy code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    red = []
    for _ in range(n):
        red.append(nl())
    blue = []
    for _ in range(n):
        blue.append(nl())

    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort(key=lambda x:x[0], reverse=True)

    #print(red, blue)
    ans = 0
    for _ in range(n):
        mn = blue.pop()
        for i in range(len(red)):
            if mn[0] > red[i][0] and mn[1] > red[i][1]:
                #print(mn, red.pop(i), 'pair')
                ans += 1
                break

    print(ans)
        

if __name__ == '__main__':
    main()

Fixed code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    red = []
    for _ in range(n):
        red.append(nl())
    blue = []
    for _ in range(n):
        blue.append(nl())

    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort(key=lambda x:x[0], reverse=True)

    #print(red, blue)
    ans = 0
    for _ in range(n):
        mn = blue.pop()
        for i in range(len(red)):
            if mn[0] > red[i][0] and mn[1] > red[i][1]:
                #print(mn, red.pop(i), 'pair')
                red.pop(i)
                ans += 1
                break

    print(ans)
        

if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
b = []
r = []
for i in range(n):
    r.append(list(map(int, input().split())))
for i in range(n):
    b.append(list(map(int, input().split())))
    
r = sorted(r)
b = sorted(b)

b_f = [-1] * n
r_f = [-1] * n

pair = []
count = 0
for i in range(n):
    if b_f[i] == -1:
        tmp = []
        for j in range(n):
            if b[i][0] > r[j][0] and b[i][1] > r[j][1] and b_f[j] == -1:
                tmp.append(j)
            
        if len(tmp) != 0:     
            pair_j = max(tmp, key=lambda j: b[j][1])
            count += 1
            b_f[i] = 1
            r_f[pair_j] = 1
print(count)

Fixed code:
n = int(input())
b = []
r = []
for i in range(n):
    r.append(list(map(int, input().split())))
for i in range(n):
    b.append(list(map(int, input().split())))
    
r = sorted(r)
b = sorted(b)

b_f = [-1] * n
r_f = [-1] * n

pair = []
count = 0
for i in range(n):
    if b_f[i] == -1:
        tmp = []
        for j in range(n):
            if b[i][0] > r[j][0] and b[i][1] > r[j][1] and r_f[j] == -1:
                tmp.append(j)
            
        if len(tmp) != 0:     
            pair_j = max(tmp, key=lambda j: r[j][1])
            count += 1
            b_f[i] = 1
            r_f[pair_j] = 1
print(count)
Buggy code:
n = int(input())
red = []
blue = []
B = [0]*(n+1)
for i in range(n):
  red.append(list(map(int,input().split())))

for i in range(n):
  blue.append(list(map(int,input().split())))
red.sort(key=lambda x: x[0])
blue.sort(key=lambda x: x[0])
cnt = 0

for i in range(n):
  for j in range(n):
    if (red[i][0] < blue[j][0] and red[i][1] < blue[j][1]) and B[j+1] == 0:
      B[j+1] = 1
      cnt += 1
      break

print(cnt)

Fixed code:
n = int(input())
red = []
blue = []
B = [0]*(n+1)
for i in range(n):
  red.append(list(map(int,input().split())))

for i in range(n):
  blue.append(list(map(int,input().split())))
red.sort(key=lambda x: x[1], reverse=True)
blue.sort(key=lambda x: x[0])
cnt = 0

for i in range(n):
  for j in range(n):
    if (red[j][0] < blue[i][0] and red[j][1] < blue[i][1]) and B[j+1] == 0:
      B[j+1] = 1
      cnt += 1
      break

print(cnt)
Buggy code:
from operator import itemgetter
from collections import deque

n = int(input())
ab = deque(sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(1),reverse=True))
cd = sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(0))
print(ab)
print(cd)
ans = 0
for i in range(n):
    for j in range(len(cd)):
        if ab[0][0] < cd[j][0] and ab[0][1] < cd[j][1]:
            ans += 1
            ab.popleft()
            cd.pop(j)
            break
    else:
        ab.popleft()

print(ans)


Fixed code:
from operator import itemgetter
from collections import deque

n = int(input())
ab = deque(sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(1),reverse=True))
cd = sorted((list(map(int, input().split())) for _ in range(n)), key=itemgetter(0))

ans = 0
for i in range(n):
    for j in range(len(cd)):
        if ab[0][0] < cd[j][0] and ab[0][1] < cd[j][1]:
            ans += 1
            ab.popleft()
            cd.pop(j)
            break
    else:
        ab.popleft()

print(ans)
Buggy code:
from operator import itemgetter

N=int(input())
A=[]
B=[]
for i in range(N):
  temp=list(map(int, input().split()))
  A.append(temp)
for i in range(N):
  temp=list(map(int, input().split()))
  B.append(temp)
  

def main():
  A.sort(key=itemgetter(0,1))
  B.sort(key=itemgetter(0,1))
  cnt=0
  while B!=[]:
    idx=-1
    for i in range(len(A)):
      if A[i][0]>=B[0][0]:
        break
      if A[i][0]<B[0][0] and A[i][1]<B[0][1]:
        idx=i
    if idx!=-1:
      cnt+=1
      del A[i]
      del B[0]
    else:
      del B[0]
  print(cnt)

main()


Fixed code:
from operator import itemgetter

N=int(input())
A=[]
B=[]
for i in range(N):
  temp=list(map(int, input().split()))
  A.append(temp)
for i in range(N):
  temp=list(map(int, input().split()))
  B.append(temp)
  

def main():
  A.sort(key=itemgetter(0,1))
  B.sort(key=itemgetter(0,1))
  #print(A)
  #print(B)
  cnt=0
  while B!=[]:
    idx=-1
    y=-1
    for i in range(len(A)):
      if A[i][0]>=B[0][0]:
        break
      if A[i][1]<B[0][1] and y<=A[i][1]:
        idx=i
        y=A[i][1]
    if idx!=-1:
      cnt+=1
      #print(A[idx],B[0])
      del A[idx]
      del B[0]
    else:
      del B[0]
  print(cnt)

main()
Buggy code:
N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
B = sorted(B, key = lambda x:x[0])
ans = 0
for b in B:
    tmp = 1000000000
    rp = -1
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            if tmp > r[1]:
                tmp = r[1]
                rp = i
    if rp >= 0:
        R.pop(rp)
        ans += 1
print(ans)

Fixed code:
N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
B = sorted(B, key = lambda x:x[0])
ans = 0
for b in B:
    tmp = -1
    rp = -1
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            if r[1] > tmp:
                tmp = r[1]
                rp = i
    if rp >= 0:
        R.pop(rp)
        ans += 1
print(ans)
Buggy code:
if __name__ == '__main__':
    N = int(input())
    ab_list = [list(map(int, input().split())) for i in range(N)]
    cd_list = [list(map(int, input().split())) for i in range(N)]

    ab_list = sorted(ab_list, key=lambda x : x[1], reverse=True)
    cd_list = sorted(cd_list, key=lambda x : x[0])

    print(ab_list)
    print(cd_list)

    answer = 0
    for b in cd_list:
        for r in ab_list:
            if b[0]>r[0] and b[1]>r[1]:
                answer += 1
                ab_list.remove(r)
                print(b)
                print(r)
                print("------")
                break
    print(answer)

Fixed code:
if __name__ == '__main__':
    N = int(input())
    ab_list = [list(map(int, input().split())) for i in range(N)]
    cd_list = [list(map(int, input().split())) for i in range(N)]

    ab_list = sorted(ab_list, key=lambda x : x[1], reverse=True)
    cd_list = sorted(cd_list, key=lambda x : x[0])

    answer = 0
    for b in cd_list:
        for r in ab_list:
            if b[0]>r[0] and b[1]>r[1]:
                answer += 1
                ab_list.remove(r)
                break
    print(answer)
Buggy code:
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
blue.sort()
red.sort(key=lambda x: x[1])
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if (r[0] < b[0]) & (r[1] < b[1]):
            ans += 1
            red.pop(i)
            break
print(ans)

Fixed code:
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
blue.sort()
red.sort(key=lambda x: x[1], reverse=True)
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if (r[0] < b[0]) & (r[1] < b[1]):
            ans += 1
            red.pop(i)
            break
print(ans)
Buggy code:
N = int(input())
A = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  A.append((x,y))

B = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  B.append((x,y))

A = sorted(A, key=lambda x: -x[1])
B = sorted(B, key=lambda x: x[0])
cnt = 0

for bx,by in B:
  can = None
  for i in range(len(A)):
    if A[i][0] < bx and A[i][1] < by:
      can = i
      break

  if can is not None:
    cnt += 1

print(cnt)


Fixed code:
N = int(input())
A = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  A.append((x,y))

B = []
for _ in range(N):
  x,y = list(map(int, input().split()))
  B.append((x,y))

A = sorted(A, key=lambda x: -x[1])
B = sorted(B, key=lambda x: x[0])
cnt = 0

for bx,by in B:
  can = None
  for i in range(len(A)):
    if A[i][0] < bx and A[i][1] < by:
      can = i
      break

  if can is not None:
    A.pop(can)
    cnt += 1

print(cnt)
Buggy code:
N = int(input())

A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
A = sorted(A, key=lambda x: -x[1])  # sort by y-axis [max,..., min]
B = sorted(B, key=lambda x: x[0])   # sort by x-axis [min,..., max]

for i in range(N):
    for j in range(len(A)):
        if A[j][0] < B[i][0] and A[j][1] < B[i][0]:
            A.pop(j)
            break

print(N - len(A))


Fixed code:
N = int(input())

A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
A = sorted(A, key=lambda x: -x[1])  # sort by y-axis [max,..., min]
B = sorted(B, key=lambda x: x[0])   # sort by x-axis [min,..., max]

for i in range(N):
    for j in range(len(A)):
        if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
            A.pop(j)
            break

print(N - len(A))
Buggy code:
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) > 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
           R.remove(s)
           pair += 1
           
print(pair)

Fixed code:
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) != 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
       R.remove(s)
       pair += 1
           
print(pair)
Buggy code:
n = int(input())
red = [[0,0] for _ in range(n)]
blue = [[0,0] for _ in range(n)]

for i in range(n):
    red[i][0], red[i][1] = map(int,input().split())
for i in range(n):
    blue[i][0], blue[i][1] = map(int,input().split())

flag = [True]*n

red.sort(key = lambda x:(min(x),x[0]))
red = [red[n-i-1] for i in range(n)]

blue.sort(key = lambda x:(min(x),x[0]))

for i in range(n):
    for j in range(n):
        if flag[j] and red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            flag[j] = False
            break

ans = 0
for i in range(n):
    if not flag[i]:
        ans += 1

print(ans)

Fixed code:
n = int(input())
red = [[0,0] for _ in range(n)]
blue = [[0,0] for _ in range(n)]

for i in range(n):
    red[i][0], red[i][1] = map(int,input().split())
for i in range(n):
    blue[i][0], blue[i][1] = map(int,input().split())
    
red.sort(key = lambda x:-x[1])
blue.sort(key = lambda x:x[0])

flag = [True] * n

for i in range(n):
    for j in range(n):
        if flag[j] and red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            flag[j] = False
            break

ans = 0
for i in range(n):
    if not flag[i]:
        ans += 1

print(ans)
Buggy code:
from operator import itemgetter

N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(1))
B = sorted(B, key=itemgetter(0))

count = 0
for c, d in B:
    for a, b in R:
        if (a < c) & (b < d):
            count += 1
            R.remove((a, b))
            break
print(count)


Fixed code:
from operator import itemgetter

N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]
R = sorted(R, key=itemgetter(1), reverse=True)
B = sorted(B, key=itemgetter(0))

count = 0
for c, d in B:
    for a, b in R:
        if (a < c) & (b < d):
            count += 1
            R.remove((a, b))
            break
print(count)
Buggy code:
n = int(input())
ab, cd = [], []
for _ in range(n):
    ab.append([int(x) for x in input().split()])
for _ in range(n):
    cd.append([int(x) for x in input().split()])
ab.sort(key=lambda x: x[0])
cd.sort(key=lambda x: x[1], reverse=True)
pair_cnt = 0
for cdleftmost in cd:
    for abi in ab:
        if(abi[0] < cdleftmost[0] and abi[1] < cdleftmost[1]):
            ab.remove(abi)
            pair_cnt += 1
            break
print(pair_cnt)

Fixed code:
n = int(input())
ab, cd = [], []
for _ in range(n):
    ab.append([int(x) for x in input().split()])
for _ in range(n):
    cd.append([int(x) for x in input().split()])
cd.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1], reverse=True)
pair_cnt = 0
for cdleftmost in cd:
    for abi in ab:
        if(abi[0] < cdleftmost[0] and abi[1] < cdleftmost[1]):
            ab.remove(abi)
            pair_cnt += 1
            break
print(pair_cnt)
Buggy code:
from operator import itemgetter
# N = 5
# R = [[0, 0],
#      [7, 3],
#      [2, 2],
#      [4, 8],
#      [1, 6]]

# B = [[8, 5], 
#      [6, 9], 
#      [5, 4], 
#      [9, 1],
#      [3, 7]]
N = int(input())
R = []
for i in range(N):
    a, b = map(int, input().split())
    R.append([a, b])
B = []
for i in range(N):
    c, d = map(int, input().split())
    B.append([c, d])
R.sort(key=itemgetter(0))
B.sort(key=itemgetter(0))
print(R)
print(B)
res = 0
for r in R:
    rx, ry = r[0], r[1]
    flag1 = False
    flag2 = False
    
    for i, b in enumerate(B):
        if b[0] > rx:
            flag1 = True
            break
    
    if flag1:
        B_tmp = B.copy()[i:]
        B_tmp.sort(key=itemgetter(1))
        for ii, b in enumerate(B_tmp):
            if b[1] > ry:
                flag2 = True
                break
        if flag2:
            res += 1
            B.remove(b)
print(res)

Fixed code:
from operator import itemgetter
# N = 5
# R = [[0, 0],
#      [7, 3],
#      [2, 2],
#      [4, 8],
#      [1, 6]]

# B = [[8, 5], 
#      [6, 9], 
#      [5, 4], 
#      [9, 1],
#      [3, 7]]
N = int(input())
R = []
for i in range(N):
    a, b = map(int, input().split())
    R.append([a, b])
B = []
for i in range(N):
    c, d = map(int, input().split())
    B.append([c, d])
R.sort(key=itemgetter(0))
B.sort(key=itemgetter(0))
# print(R)
# print(B)
res = 0
for r in R[::-1]:
    rx, ry = r[0], r[1]
    flag1 = False
    flag2 = False
    
    for i, b in enumerate(B):
        if b[0] > rx:
            flag1 = True
            break
    
    if flag1:
        B_tmp = B.copy()[i:]
        B_tmp.sort(key=itemgetter(1))
        for ii, b in enumerate(B_tmp):
            if b[1] > ry:
                flag2 = True
                break
        if flag2:
            res += 1
            B.remove(b)
print(res)
Buggy code:
N=int(input())
red=[list(map(int, input().split())) for _ in range(N)]
blue=[list(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[0])
ct=0
for j in reversed(red):
    for i in blue:
        if i[0]>j[0] and i[1]>j[1]:
            red.remove(j)
            blue.remove(i)
            ct+=1
            break
print(ct)


Fixed code:
N=int(input())
red=[list(map(int, input().split())) for _ in range(N)]
blue=[list(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])
ct=0
for i in blue:
    for j in reversed(red):
        if i[0]>j[0] and i[1]>j[1]:
            red.remove(j)

            ct+=1
            break
print(ct)
Buggy code:
my_input = input

def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]

n = int(my_input())
a = []
b = []
for _ in range(n):
    ax, ay = my_input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = my_input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:x[1], reverse=True)
b = sorted(b, key=lambda x:x[0], reverse=False)
ans = 0
ii = set()
for j in range(n):
    for i in range(n):
        if i in ii:
            continue
        if less_than(a[i], b[j]):
            ans += 1
            ii.add(j)
            break
print(ans)

Fixed code:
my_input = input

def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]

n = int(my_input())
a = []
b = []
for _ in range(n):
    ax, ay = my_input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = my_input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:x[1], reverse=True)
b = sorted(b, key=lambda x:x[0], reverse=False)
ans = 0
ii = set()
for j in range(n):
    for i in range(n):
        if i in ii:
            continue
        if less_than(a[i], b[j]):
            ans += 1
            ii.add(i)
            break
print(ans)
Buggy code:
n = int(input())
r = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(n)]
b.sort()
r = sorted(r,key=lambda x:-x[1])
ans = 0
for i,b_ in enumerate(b):
    print(r)
    for j,r_ in enumerate(r):
        if b_[0]>r_[0] and b_[1]>r_[1]:
            ans+=1
            del r[j]
            break

print(ans)

Fixed code:
n = int(input())
r = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(n)]
b.sort()
r = sorted(r,key=lambda x:-x[1])
ans = 0
for i,b_ in enumerate(b):
    for j,r_ in enumerate(r):
        if b_[0]>r_[0] and b_[1]>r_[1]:
            ans+=1
            del r[j]
            break

print(ans)
Buggy code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))
red.sort(reverse = True)
blue.sort(reverse = True)
print(red)
print(blue)
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        print(blue)
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(0)
            break
print(ans)

Fixed code:
n = int(input())
red = []
blue = []
for i in range(n):
    red.append(list(map(int,input().split())))
for i in range(n):
    blue.append(list(map(int,input().split())))
red.sort(reverse = True)
blue.sort(key=lambda x:x[1])
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(j)
            break
print(ans)
Buggy code:
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], x[0]))
cd.sort(key=lambda x: (x[0], x[1]))
s = [0] * n
print(ab)
print(cd)

for i in range(n):
    for j in range(n):
        if s[j] == 0 and ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
            s[j] = 1
            break
print(sum(s))


Fixed code:
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
cd = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], x[0]))
cd.sort(key=lambda x: (x[0], x[1]))
s = [0] * n

for i in range(n):
    for j in range(n):
        if s[j] == 0 and ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
            s[j] = 1
            break
print(sum(s))
Buggy code:
N = int(input())

AB = [[int(_) for _ in input().split()] for i in range(N)]
CD = [[int(_) for _ in input().split()] + [0, ] for i in range(N)]
AB.sort(reverse=True)
CD.sort(reverse=True)
ans = 0
for a, b in AB:
    # for c, d, f in CD:
    min_idx = -1
    min_val = 1e10

    for i in range(N):
        c, d, f = CD[i]
        if f: continue
        if c <= a and d <= b: break
        if min_val > d:
            min_val = d
            min_idx = i
    if min_idx >= 0:
        ans += 1
        CD[min_idx][2] = 1
        # print('pare:', (a, b), CD[min_idx])
print(ans)

Fixed code:
N = int(input())

AB = [[int(_) for _ in input().split()] for i in range(N)]
CD = [[int(_) for _ in input().split()] + [0, ] for i in range(N)]
AB.sort(reverse=True)
CD.sort(reverse=True)
ans = 0
for a, b in AB:
    # for c, d, f in CD:
    min_idx = -1
    min_val = 1e10

    for i in range(N):
        c, d, f = CD[i]
        if f: continue
        if c <= a and d <= b: break
        if c <= a or d <= b: continue
        if min_val > d:
            min_val = d
            min_idx = i
    if min_idx >= 0:
        ans += 1
        CD[min_idx][2] = 1
        #print('pare:', (a, b), CD[min_idx])
print(ans)
Buggy code:
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]

ab = sorted(ab, key=lambda x:x[1])
cd.sort()
print(ab)
print(cd)
  
count = 0
for i in range(N):
  idx = -1
  for j in range(len(ab)):
    if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
      idx = j
  if idx >= 0:
    count += 1
    ab.pop(idx)
  
print(count)

Fixed code:
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]

ab = sorted(ab, key=lambda x:x[1])
cd.sort()
  
count = 0
for i in range(N):
  idx = -1
  for j in range(len(ab)):
    if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
      idx = j
  if idx >= 0:
    count += 1
    ab.pop(idx)
  
print(count)
Buggy code:
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort()
cd.sort(key=lambda x:x[1])
cd.sort()
ans=0
for i in range(n):
    for a in ab:
        if a[0]<cd[i][0] and a[1]<cd[i][1]:
            ans+=1
            ab.remove(a)
            break
print(ans)



Fixed code:
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1], reverse=True)
cd.sort()
ans=0
for i in range(n):
    for a in ab:
        if a[0]<cd[i][0] and a[1]<cd[i][1]:
            ab.remove(a)
            ans+=1
            break
print(ans)