qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
A = [[int(i) for i in reversed(input().split())] for n in range(N)]
B = [[int(i) for i in input().split()] for n in range(N)]
A.sort(); A.reverse(); B.sort()
C = 0
i = 0
for b in B:
  found = False
  while not found:
    a = A[i]
    if a[1] < b[0] and a[0] < b[1]:
      found = True
      C += 1
      A.pop(i)
      i = 0
    elif i+1 == len(A):
      found = True
      i = 0
    else:
      i += 1
    print(a,b,found,C)
print(C)

Fixed code:
N = int(input())
A = [[int(i) for i in reversed(input().split())] for n in range(N)]
B = [[int(i) for i in input().split()] for n in range(N)]
A.sort(); A.reverse(); B.sort()
C = 0
i = 0
for b in B:
  found = False
  while not found:
    a = A[i]
    if a[1] < b[0] and a[0] < b[1]:
      found = True
      C += 1
      A.pop(i)
      i = 0
    elif i+1 == len(A):
      found = True
      i = 0
    else:
      i += 1
print(C)
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)]
ans = 0
red = sorted(red, key = lambda x:x[1] * -1)
blue = sorted(blue)
for b in blue:
	for r in red:
		if b[0] > r[0] and b[1] > r[1]:
			ans += 1
			red.remove(r)
print(ans)

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)]
ans = 0
red = sorted(red, key = lambda x: -1 * x[1])
blue = sorted(blue)
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			red.remove(r)
			break
print(ans)
Buggy code:
N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(N)]

ab.sort(key = lambda x: x[1], reverse=True)
cd.sort()

a = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            a += 1
            ab.remove([a, b])
            break

print(a)


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

ab.sort(key = lambda x: x[1], reverse=True)
cd.sort()

x = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            x += 1
            ab.remove([a, b])
            break

print(x)
Buggy code:
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
B=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
U=[0]*N

for c,d in B:
  i,mv,mi=0,-1,0
  for a,b in R:
    if a<c:
      if b<d and U[i]==0:
        if mv<d:
          mv,mi=d,i
      i+=1
    else:
      break

  if mv!=-1:
    U[mi]=1

print(sum(U))


Fixed code:
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
B=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
U=[0]*N

for c,d in B:
  i,mv,mi=0,-1,0
  for a,b in R:
    if a<c:
      if b<d and U[i]==0:
        if mv<b:
          mv,mi=b,i
      i+=1
    else:
      break

  if mv!=-1:
    U[mi]=1

print(sum(U))
Buggy code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x: -1*x[1])
blue = sorted(blue)
print(red)
print(blue)
cnt = 0
for j in range(n):
    for i in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)


Fixed code:
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x: -1*x[1])
blue = sorted(blue)
cnt = 0
for j in range(n):
    for i in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)
Buggy code:
N = int(input())
reds = sorted([list(map(int,input().split())) for i in range(n)])
blues = sorted([list(map(int,input().split()))])

reds = reds[::-1]
res = 0

for c,d in blues:
  for a,b in reds:
    if a<c and b<d:
      reds.remove([a,b])
      res+=1
      break
      
print(res)


Fixed code:
n = int(input())
reds = sorted([list(map(int,input().split())) for i in range(n)],key=lambda reds: -reds[1])
blues = sorted([list(map(int,input().split())) for i in range(n)])

res = 0

for c,d in blues:
  for a,b in reds:
    if a<c and b<d:
      reds.remove([a,b])
      res+=1
      break
      
print(res)
Buggy code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    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)]
    R.sort(key=lambda x:x[1])
    R.sort()
    B.sort(key=lambda x:x[1])
    B.sort()
    ret = 0
    for b in B:
        pairfg = False
        pair = None
        for r in R:
            if r[0] < b[0] and r[1] < b[1]:
                pairfg = True
                pair = r
            if r[0] > b[0]:
                break
        if pairfg:
            ret += 1
#            print(pair,b)
            R.remove(pair)
    print(ret)

if __name__ == '__main__':
    main()

Fixed code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    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)]
    R.sort(key=lambda x:x[1])
    R.sort()
    B.sort(key=lambda x:x[1])
    B.sort()
    ret = 0
    for b in B:
        pairfg = False
        pair = [1000, -1000]
        for r in R:
            if r[0] < b[0] and r[1] < b[1]:
                if r[1]>pair[1]:
                    pairfg = True
                    pair = r
        if pairfg:
            ret += 1
#            print(pair,b)
            R.remove(pair)
    print(ret)

if __name__ == '__main__':
    main()
Buggy code:
import bisect
n=int(input())
ab=[[int(i) for i in input().split()] for j in range(n)]
cd=[[int(i) for i in input().split()] for j in range(n)]
ab.sort()
cd.sort()

ans=0

for c,d in cd:
    now_y=-1
    check=False
    for a,b in ab:
        if a>=c:
            break
        if b<d and b>now_y:
            now_id=bisect.bisect_left(ab,[a,b])
            check=True

    if check:
        ans+=1
        ab.pop(now_id)
print(ans)
            
        


Fixed code:
import bisect
n=int(input())
ab=[[int(i) for i in input().split()] for j in range(n)]
cd=[[int(i) for i in input().split()] for j in range(n)]
ab.sort()
cd.sort()

ans=0

for c,d in cd:
    now_y=-1
    check=False
    for a,b in ab:
        if a>=c:
            break
        if b<d and b>now_y:
            now_id=bisect.bisect_left(ab,[a,b])
            now_y=b
            check=True

    if check:
        ans+=1
        ab.pop(now_id)
print(ans)
Buggy code:
#coding :utf-8
N = int(input())

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


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


memo = [0 for i in range(N)]
memoB = [0 for i in range(N)]

_aka = sorted(aka, key=lambda x: x[0])
_ao = sorted(ao, key=lambda x: x[0])
ans = 0
for j in range(N):
    _i = -1
    _y = -1
    flag = 0
    for i in range(N): 
        if _ao[j][0] > _aka[N-i-1][0] and _ao[j][1] > _aka[N-i-1][1] and memo[N-i-1] == 0:
            if _y < _aka[N-i-1][1]:
                _y = _aka[N-i-1][1]
                _i = N-i-1
    if not _i == -1:
        ans += 1
        memo[N-i-1] = 1
        

print(memo.count(1))


Fixed code:
#coding :utf-8
N = int(input())

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


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


memo = [0 for i in range(N)]
memoB = [0 for i in range(N)]

_aka = sorted(aka, key=lambda x: x[0])
_ao = sorted(ao, key=lambda x: x[0])
ans = 0
for j in range(N):
    _i = -1
    _y = -1
    for i in range(N): 
        if _ao[j][0] > _aka[i][0] and _ao[j][1] > _aka[i][1] and memo[i] == 0:
            if _y < _aka[i][1]:
                _y = _aka[i][1]
                _i = i
    if not _i == -1:
        ans += 1
        memo[_i] = 1
        

print(ans)
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)]
v=[]
r.sort()
b.sort()
print(r)
print(b)
count=0

for i in range(n):
    for j in range(n):
        if b[i][0]<=r[j][0] or b[i][1]<=r[j][1]:
            break
        else:
            v.append(r[j])    
    if v!=[]:
        v.sort(key=lambda x:x[1])
        print(v)
        r.remove(v[0])
        
            
        v=[]
        count+=1
print(count)
        

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)]
v=[]
r.sort()
b.sort()
count=0
 
for i in range(n):
    for j in range(len(r)):
        if b[i][0]<=r[j][0] or b[i][1]<=r[j][1]:
            pass
        else:
            v.append(r[j])    
    if v!=[]:
        v.sort(key=lambda x:x[1])
        v.reverse()
        r.remove(v[0])
        
            
        v=[]
        count+=1
print(count)
Buggy code:
#ABC091-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[0])
B.sort(key=lambda x:x[0])
Rb=[True]*n
Bb=[True]*n

ans=0
for i in range(n):
    rx,ry,rz=R[i]
    for j in range(n):
        bx,by,bz=B[j]
        if rx<bx and ry<by and Rb[i] and Bb[j]:
            ans+=1
            Rb[i]=False
            Bb[j]=False
print(ans)

Fixed code:
#ABC091-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[1])
B.sort(key=lambda x:x[0])
Rb=[True]*n
Bb=[True]*n

ans=0
for i in range(n):
    bx,by,bz=B[i]
    for j in range(n):
        rx,ry,rz=R[j]
        if rx<bx and ry<by and Rb[j] and Bb[i]:
            ans+=1
            Rb[j]=False
            Bb[i]=False
print(ans)
Buggy code:
    num=int(input())
    a_array=[]
    b_array=[]
    for n in range(2*num):
        elem=[int(n) for n in input().split()]
        if n < num:
            a_array.append(elem)
        else:
            b_array.append(elem)
    a_array.sort(key=lambda x:x[1])
    a_array.reverse()
    b_array.sort(key=lambda x: x[0])
    answer=0
    for b_x, b_y in b_array:
        for a_x, a_y in a_array:
            if b_x > a_x and b_y > a_y:
                answer=answer+1
                a_array.remove([a_x,a_y])
    print(answer)

Fixed code:
num=int(input())
a_array=[]
b_array=[]
for n in range(2*num):
    elem=[int(n) for n in input().split()]
    if n < num:
        a_array.append(elem)
    else:
        b_array.append(elem)
a_array.sort(key=lambda x:x[1])
a_array.reverse()
b_array.sort(key=lambda x: x[0])
answer=0
for b_x, b_y in b_array:
    for a_x, a_y in a_array:
        if b_x > a_x and b_y > a_y:
            answer=answer+1
            a_array.remove([a_x,a_y])
            break;
print(answer)
Buggy code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

sys.setrecursionlimit(10000000)

N = int(input())
AB = []
CD = []

for i in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))

for i in range(N):
    C, D = map(int, input().split())
    CD.append((C, D))

AB.sort()
CD.sort()

used = [False] * N
cnt = 0

for i in range(N):
    m = -1
    for j in range(N):
        if CD[i][0] > AB[j][0] and CD[i][1] > AB[j][1]:
            if m < 0 or AB[m][1] < AB[j][1]:
                m = j

    if m >= 0:
        used[m] = True
        cnt += 1

print(cnt)

Fixed code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

sys.setrecursionlimit(10000000)

N = int(input())
AB = []
CD = []

for i in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))

for i in range(N):
    C, D = map(int, input().split())
    CD.append((C, D))

AB.sort()
CD.sort()

used = [False] * N
cnt = 0

for i in range(N):
    m = -1
    for j in range(N):
        if not used[j] and CD[i][0] > AB[j][0] and CD[i][1] > AB[j][1]:
            if m < 0 or AB[m][1] < AB[j][1]:
                m = j

    if m >= 0:
        used[m] = True
        cnt += 1

print(cnt)
Buggy code:
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
red.sort()
print(red)
blue = [list(map(int, input().split())) for _ in range(N)]
flg = [0]*N
for i in range(N):
    tmp_y = -1
    tmp_index = -1
    for k in range(N):
        if blue[i][0] > red[k][0] and flg[k] == 0:
            if tmp_y < red[k][1] and blue[i][1] > red[k][1]:
                tmp_y = red[k][1]
                tmp_index = k
    if tmp_index != -1:
        flg[tmp_index] = 1
print(flg.count(1))

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)]
blue.sort()
flg = [0]*N
for i in range(N):
    tmp_y = -1
    tmp_index = -1
    for k in range(N):
        if blue[i][0] > red[k][0] and flg[k] == 0:
            if tmp_y < red[k][1] and blue[i][1] > red[k][1]:
                tmp_y = red[k][1]
                tmp_index = k
    if tmp_index != -1:
        flg[tmp_index] = 1
print(flg.count(1))
Buggy code:
N=int(input())
A = [0] * N
B = [0] * N
for n in range(N):
  A[n] = [int(x) for x in input().split()]
for n in range(N):
  B[n] = [int(x) for x in input().split()]

B.sort(key=lambda x:x[1])
B.sort()
print(A)
print(B)
ans = 0
for b in B:
  A.sort(key=lambda x:x[1])
  A.sort()
  q = [a for a in A if a[0] < b[0] and a[1] < b[1]]
  q_ = [a for a in A if a[0] >= b[0] or a[1] >= b[1]]
  maxa = -1
  if q:
    for i, qq in enumerate(q):
      if qq[1] > maxa:
        maxi = i
        maxa = qq[1]
    q.pop(maxi)
    ans += 1
  A = q[:] + q_[:]

print(ans)

Fixed code:
N=int(input())
A = [0] * N
B = [0] * N
for n in range(N):
  A[n] = [int(x) for x in input().split()]
for n in range(N):
  B[n] = [int(x) for x in input().split()]

B.sort(key=lambda x:x[1])
B.sort()
ans = 0
for b in B:
  A.sort(key=lambda x:x[1])
  A.sort()
  q = [a for a in A if a[0] < b[0] and a[1] < b[1]]
  q_ = [a for a in A if a[0] >= b[0] or a[1] >= b[1]]
  maxa = -1
  if q:
    for i, qq in enumerate(q):
      if qq[1] > maxa:
        maxi = i
        maxa = qq[1]
    q.pop(maxi)
    ans += 1
  A = q[:] + q_[:]

print(ans)
Buggy code:
import numpy as np


def main():
    N = int(input())
    red = np.zeros([N, 3])
    blue = np.zeros([N, 3])

    for i in range(N):
        red[i, 0:2] = list(map(int, input().split()))

    for i in range(N):
        blue[i, 0:2] = list(map(int, input().split()))

    blue = blue[np.argsort(blue[:, 0])]

    d = np.zeros([N, 3])
    cnt = 0

    for i in range(N):
        d[0:N, 0:2] = blue[i, 0:2] - red[0:N, 0:2]
        d[:, 2] = d[:, 0] + d[:, 1]

        if np.any((d[:, 0] > 0) & (d[:, 1] > 0)):
            dd = d[(d[:, 0] > 0) & (d[:, 1] > 0)]
            dd = dd[np.argsort(dd[:, 1])]
            ind = np.where(d == dd[-1])
            row = ind[0][0]
            red[row, :] = 10**9
            cnt += 1

    print(cnt)


main()


Fixed code:
import numpy as np


def main():
    N = int(input())
    red = np.zeros([N, 2])
    blue = np.zeros([N, 2])

    for i in range(N):
        red[i, 0:2] = list(map(int, input().split()))

    for i in range(N):
        blue[i, 0:2] = list(map(int, input().split()))

    blue = blue[np.argsort(blue[:, 0])]
    red = red[np.argsort(red[:, 1])[::-1]]

    d = np.zeros([N, 2])
    cnt = 0

    for i in range(N):
        d[0:N, 0:2] = blue[i, 0:2] - red[0:N, 0:2]

        if np.any((d[:, 0] > 0) & (d[:, 1] > 0)):
            dd = d[(d[:, 0] > 0) & (d[:, 1] > 0)]
            dd = dd[np.argsort(dd[:, 1])]
            ind = list(zip(*np.where(d == dd[0])))
            row = ind[0][0]
            red[row, :] = 10**9
            cnt += 1

    print(cnt)


main()
Buggy code:
N=int(input())

ab=[]
cd=[]

for i in range(N):
    e,f=map(int,input().split())
    tmp=[e+f,e,f]
    ab.append(tmp)

for i in range(N):
    e,f=map(int,input().split())
    tmp=[e+f,e,f]
    cd.append(tmp)

ab.sort()
cd.sort()


ans=0

for i in range(N):
    L=len(cd)
    mi=1000000
    num=-1
    for j in range(L):
        if ab[i][1]<cd[j][1] and ab[i][2]<cd[j][2]:
            tmp=abs(ab[i][1]-cd[j][1])+abs(ab[i][2]-cd[j][2])
            if tmp<mi:
                mi=tmp
                num=j
    if not num<0:
        del cd[num]
        ans+=1


print(ans)

Fixed code:
N=int(input())

ab=[]
cd=[]

for i in range(N):
    e,f=map(int,input().split())
    tmp=[e,e,f]
    ab.append(tmp)

for i in range(N):
    e,f=map(int,input().split())
    tmp=[e,e,f]
    cd.append(tmp)

ab.sort()
cd.sort()

#ab.reverse()
#cd.reverse()

ans=0

for i in range(N):
    L=len(ab)
    mi=1000000
    num=-1
    for j in range(L):
        if ab[j][1]<cd[i][1] and ab[j][2]<cd[i][2]:
            tmp=abs(ab[j][2]-cd[i][2])
            if tmp<mi:
                mi=tmp
                num=j
    if not num<0:
        del ab[num]
        ans+=1


print(ans)
Buggy code:
n = int(input())
red  = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
red.sort(key=lambda x:-x[1])
blue.sort()
count = 0
for xb, yb in blue:
    for xr, yr in red:
        if xb > xr and yb > yr:
            red[max_i] = (201, 201)
            count += 1
            break
print(count)

Fixed code:
n = int(input())
red  = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]

red.sort(key=lambda x:x[1])
blue.sort()

count = 0
for xb, yb in blue:
    max_y = -1
    max_i = -1
    for i in range(n):
        xr, yr = red[i]
        if xb > xr and yb > yr and max_y < yr:
            max_y, max_i = yr, i
    if max_y >= 0:
        red[max_i] = (201, 201)
        count += 1
print(count)
Buggy code:

def main():
    num = int(input())
    aka_data = [list(map(int, input().split())) for i in range(num)]
    ao_data = [list(map(int, input().split())) for i in range(num)]

    aka_data.sort(key=lambda x:(x[0],x[1]))
    ao_data.sort(key=lambda x: (x[0], x[1]))

    ans = 0
    for i in range(num):
        for j in range(len(ao_data)):
            if aka_data[i][0] < ao_data[j][0] and aka_data[i][1] < ao_data[j][1]:
                ao_data.pop(j)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()



Fixed code:
def main():
    num = int(input())
    aka_data = [list(map(int, input().split())) for i in range(num)]
    ao_data = [list(map(int, input().split())) for i in range(num)]

    aka_data.sort(key=lambda x:-x[1])
    ao_data.sort(key=lambda x: x[0])

    ans = 0
    for j in range(num):
        for i in range(len(aka_data)):
            if aka_data[i][0] < ao_data[j][0] and aka_data[i][1] < ao_data[j][1]:
                aka_data.pop(i)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()
Buggy code:
N=int(input())
R=[list(map(int,input().split())) for n in range(N)]
B=[list(map(int,input().split())) for n in range(N)]

sorted(R,key=itemgetter(1),reverse=True)
B.sort()
ans=0

for c,d in B :
    for a,b in R :
        if a<c and b<d :
            ans+=1
            R.remove([a,b])
            break

print(ans)

Fixed code:
from operator import itemgetter
N=int(input())
R=[list(map(int,input().split())) for n in range(N)]
B=[list(map(int,input().split())) for n in range(N)]
R.sort(key=itemgetter(1),reverse=True)
B.sort()
ans=0

for c,d in B :
    for a,b in R :
        if a<c and b<d :
            ans+=1
            R.remove([a,b])
            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)]

from operator import itemgetter
ab.sort(key=itemgetter(1))
cd.sort(key=itemgetter(0))

C = [0] * N
cnt = 0
for i in range(N):
    for j in range(N):
        if C[j] == 0 and ab[- j - 1][0] < cd[i][0] and ab[ - j - 1][1] < cd[i][1]:
            C[i] = 1
            cnt += 1
            break
print(cnt)

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)]

from operator import itemgetter
ab.sort(key=itemgetter(1))
cd.sort(key=itemgetter(0))

C = [0] * N
cnt = 0
for i in range(N):
    for j in range(N):
        if C[j] == 0 and ab[- j - 1][0] < cd[i][0] and ab[ - j - 1][1] < cd[i][1]:
            C[j] = 1
            cnt += 1
            break
print(cnt)
Buggy code:
import heapq

n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]
cd = [[int(i) for i in input().split()] for j in range(n)]

ab.sort(reverse=True)
cd.sort(reverse=True)

#print(ab,cd)

hq = []
tmp = 0
ans = 0

for i in range(n):
    while tmp <= n-1 and ab[i][0] < cd[tmp][0]:
        hq.append(cd[tmp][1])
        hq.sort(reverse=True)
        tmp += 1
    #print(hq)
    if len(hq) > 0:
        for j in range(len(hq)):
            if hq[j] > ab[i][1]:
                del hq[j]
                ans += 1
                break
            elif hq[j] <= ab[i][1]:
                break
            else:
                continue
        
print(ans)

Fixed code:
import heapq

n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]
cd = [[int(i) for i in input().split()] for j in range(n)]

ab.sort(reverse=True)
cd.sort(reverse=True)

#print(ab,cd)

hq = []
tmp = 0
ans = 0

for i in range(n):
    while tmp <= n-1 and ab[i][0] < cd[tmp][0]:
        hq.append(cd[tmp][1])
        hq.sort()
        tmp += 1
    #print(hq)
    if len(hq) > 0:
        for j in range(len(hq)):
            if hq[j] > ab[i][1]:
                del hq[j]
                ans += 1
                break
            """
            elif hq[j] <= ab[i][1]:
                break
            else:
                continue
            """
        
print(ans)
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from bisect import bisect_right
N = int(input())
ab = [list(mapint()) for _ in range(N)]
cd = [list(mapint()) for _ in range(N)]
ab.sort()
cd.sort(key=lambda x: x[1])
clis = [c for c, d in cd]
checked = [0]*N

cdidx = 0
ans = 0
for n in range(N):
    a, b = ab[n]
    cdidx = bisect_right(clis, a)
    if cdidx>=N:
        break
    for i in range(cdidx, N):
        if checked[i]:
            continue
        c, d = cd[i]
        if a<c and b<d:
            ans += 1
            checked[i] = 1
            break

print(ans)

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from bisect import bisect_right
N = int(input())
ab = [list(mapint()) for _ in range(N)]
cd = [list(mapint()) for _ in range(N)]
ab.sort(reverse=True)
cd.sort(key=lambda x: x[1])
checked = [0]*N

ans = 0
for n in range(N):
    a, b = ab[n]
    for i in range(N):
        if checked[i]:
            continue
        c, d = cd[i]
        if a<c and b<d:
            ans += 1
            checked[i] = 1
            break

print(ans)