qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
an=sorted(a, key=lambda x:(x[0],-x[1]))
bn=sorted(b, key=lambda x:(x[0],-x[1]))
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break
 
print(count)

Fixed code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
an=sorted(a, key=lambda x:-x[1])
bn=sorted(b)#, key=lambda x:(x[0],x[1]))
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break
 
print(count)
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)]
R.sort(key=lambda x:(-x[0],-x[1]))
B.sort()

ans = 0
for rx,ry in R:
    for bx,by in B:
        # print(rx,ry,bx,by)
        if rx<bx and ry<by:
            # print("ok")
            ans += 1
            B.remove([bx,by])
            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)]
R.sort(key=lambda x:(-x[0],-x[1]))
B.sort(key=lambda x:(x[1],x[0]))

ans = 0
for rx,ry in R:
    for bx,by in B:
        # print(rx,ry,bx,by)
        if rx<bx and ry<by:
            # print("ok")
            ans += 1
            B.remove([bx,by])
            break

print(ans)
Buggy code:
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
for i in range(N):
  a, b = map(int, input().split())
  B.append([a, b])
A = sorted(A, key=lambda x: (x[0], x[1]))
B = sorted(B, key=lambda x: (x[0], x[1]))
count = 0
for i in range(len(B) - 1, -1 ,-1):
  for j in range(len(A) - 1, -1, -1):
    if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
      A.pop()
      count += 1
      break
    else:
      A.pop()
print(count)

Fixed code:
N = int(input())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append([a, b])
for i in range(N):
  a, b = map(int, input().split())
  B.append([a, b])
A = sorted(A, key=lambda x: (-x[1]))
B = sorted(B, key=lambda x: (x[0]))
count = 0
for i in range(len(B)):
  for j in range(len(A)):
    if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
      A = A[:j] + A[j+1:]
      count += 1
      break
print(count)
Buggy code:
def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[0])
    bluedots = sorted(bluedots, key=lambda x: x[1], reverse=True)

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[0] = 201
                break

    print(ans)


if __name__ == '__main__':
    main()


Fixed code:

def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[1], reverse=True)
    bluedots = sorted(bluedots, key=lambda x: x[0])

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[0] = 201
                break

    print(ans)


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())

red = []
for i in range(n):
    red.append([int(j) for j in input().split()])
red.sort(key=lambda x : x[1], reverse=True)
print(red)

blue = []
for i in range(n):
    blue.append([int(j) for j in input().split()])
blue.sort()
print(blue)

count = 0
for b in blue:
    for r in red:
        if r[0] < b[0]:
            if r[1] < b[1]:
                count += 1
                red.remove(r)
                break
print(count)

Fixed code:
n = int(input())

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

blue = []
for i in range(n):
    blue.append([int(j) for j in input().split()])
blue.sort()

count = 0
for b in blue:
    for r in red:
        if r[0] < b[0] and r[1] < b[1]:
            count += 1
            red.remove(r)
            break
print(count)
Buggy code:
import operator
import bisect

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=operator.itemgetter(0,1))
blue.sort(key=operator.itemgetter(0,1))
#print(red)
#print(blue)
count=0
for i in range(n):
  for j in reversed(range(len(red))):
    #print("j",j)
    if not red:
      break
    if red[j][0]<blue[i][0]:
      tmp=red[:j+1]
      tmp.sort(key=lambda x:x[1],reverse=True)
      for t in tmp:
        if t[1]<blue[i][1]:
          count+=1
          red.pop(red.index(t))
          break
  else:
    continue
  break
      #max_y_idx=red.index(max(red[:j+1],key=lambda x:x[1]))
      #print("max_y_idx",max_y_idx,red[max_y_idx],"blue[i]",blue[i])
      #print("red",red)

print(count)
    

Fixed code:
import operator
import bisect

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=operator.itemgetter(0,1))
blue.sort(key=operator.itemgetter(0,1))
#print(red)
#print(blue)
count=0
for i in range(n):
  for j in reversed(range(len(red))):
    #print("j",j)
    if not red:
      break
    if red[j][0]<blue[i][0]:
      tmp=red[:j+1]
      tmp.sort(key=lambda x:x[1],reverse=True)
      for t in tmp:
        if t[1]<blue[i][1]:
          count+=1
          red.pop(red.index(t))
          #print("t",t,"blue[i]",blue[i])
          break
    else:
      continue
    break

print(count)
Buggy code:
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
print(R)
print(B)
ans=0
for c,d in B:
  for a,b in R:
    if a<c and b<d:
      R.remove([a,b]);ans+=1
      break
print(ans)

Fixed code:
n=int(input())
R=sorted([list(map(int,input().split())) for i in range(n)], key=lambda R: -R[1])
B=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for c,d in B:
  for a,b in R:
    if a<c and b<d:
      R.remove([a,b]);ans+=1
      break
print(ans)
Buggy code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

for _ in range(N):
    a,b = map(int,input().split())
    B.append([a,b])

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B:
    index = bisect_left(R_tmp,x[0])
    tmp = R[:index]
    tmp = sorted(tmp)
    for i in range(index)[::-1]:
        if tmp[i][1] < x[1]:
            R.remove([tmp[i][0],tmp[i][1]])
            R_tmp.remove(tmp[i][0])
            ans += 1
            break
print(ans)



Fixed code:
N = int(input())
R = []
B = []
R_tmp = []
for _ in range(N):
    a,b = map(int,input().split())
    R_tmp.append(a)
    R.append([a,b])

for _ in range(N):
    a,b = map(int,input().split())
    B.append([a,b])

B = sorted(B)
R = sorted(R)
R_tmp.sort()
from bisect import bisect_left
ans = 0
for x in B:
    index = bisect_left(R_tmp,x[0])
    tmp = R[:index]
    tmp = sorted(tmp,key=lambda x:x[1])
    for i in range(index)[::-1]:
        if tmp[i][1] < x[1]:
            R.remove([tmp[i][0],tmp[i][1]])
            R_tmp.remove(tmp[i][0])
            ans += 1
            break
print(ans)
Buggy code:
from operator import itemgetter

n = int(input())
r = [tuple(map(int, input().split())) for i in range(n)]
b = [tuple(map(int, input().split())) for i in range(n)]

r = sorted(r, key=itemgetter(1), reverse=True)
b.sort()

ans = 0
pair = [False]*n

for i in range(n):
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1] and pair[j] == False:
            pair[i] = True
            ans += 1
            break

print(ans)


Fixed code:
from operator import itemgetter

n = int(input())
r = [tuple(map(int, input().split())) for i in range(n)]
b = [tuple(map(int, input().split())) for i in range(n)]

r = sorted(r, key=itemgetter(1), reverse=True)
b.sort()

ans = 0
pair = [False]*n

for i in range(n):
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1] and pair[j] == False:
            pair[j] = True
            ans += 1
            break

print(ans)
Buggy code:
N = int(input())
red = [list(map(int, input().split())) for i in range (N)]
blue = [list(map(int, input().split())) for i in range (N)]
blue.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1])
pairs = 0
flag = [True for i in range(N)]
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1] and flag[j]:
            pairs += 1
            flag[j] = False
            break
print(pairs)

Fixed code:
N = int(input())
red = [list(map(int, input().split())) for i in range (N)]
blue = [list(map(int, input().split())) for i in range (N)]
blue.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1], reverse=True)
pairs = 0
flag = [True for i in range(N)]
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1] and flag[j]:
            pairs += 1
            flag[j] = False
            break
print(pairs)
Buggy code:
n = int(input())

redPoints = []
bluePoints = []

for i in range(n):
    redPoints.append([int(x) for x in input().split(" ")])
for i in range(n):
    bluePoints.append([int(x) for x in input().split(" ")])
# deletation
for bluePoint in bluePoints:
    if bluePoint[0] == 0 or bluePoint[1] == 0:
        bluePoints.remove(bluePoint)

result = 0

for bluePoint in bluePoints:
    for redPoint in redPoints:
        # print("See:", redPoint, bluePoint)
        if redPoint[0] < bluePoint[0] and redPoint[1] < bluePoint[1]:
            result += 1
            # print(redPoint, " is inner of ", bluePoint)
            break

print(result)


Fixed code:
n = int(input())

redPoints = []
bluePoints = []

for i in range(n):
    redPoints.append([int(x) for x in input().split(" ")])
for i in range(n):
    bluePoints.append([int(x) for x in input().split(" ")])
# deletation
for bluePoint in bluePoints:
    if bluePoint[0] == 0 or bluePoint[1] == 0:
        bluePoints.remove(bluePoint)

result = 0
bluePoints = sorted(bluePoints)
redPoints = sorted(redPoints, key=lambda x: -x[1])
for bluePoint in bluePoints:
    for redPoint in redPoints:
        # print("See:", redPoint, bluePoint)
        if redPoint[0] < bluePoint[0] and redPoint[1] < bluePoint[1]:
            result += 1
            redPoints.remove(redPoint)
            # print(redPoint, " is inner of ", bluePoint)
            break

print(result)
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[1], reverse=True)
Blue.sort(key=lambda x: x[0])

ans = 1
for blue in Blue:
    for red in Red:
        if red[0] < b[0] and red[1] < b[1]:
            ans += 1
            Red.remove(red)
            break

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

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

ans = 0
for blue in Blue:
    for red in Red:
        if red[0] < blue[0] and red[1] < blue[1]:
            ans += 1
            Red.remove(red)
            break

print(ans)
Buggy code:
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort(key=lambda a: a[1])
r=r[::-1]
ans=0
chk=[1]*n
for i in range(n):
    for j in range(n):
        if l[i][0]<r[j][0] and l[i][1]<r[j][1] and chk[j]:
            chk[j]=0
            ans+=1
print(ans)


Fixed code:
n=int(input())
l,r=[],[]
for i in range(n):
    x,y=map(int,input().split())
    l.append((x,y))
l.sort()
l.sort(key=lambda a: a[1],reverse=True)
for i in range(n):
    x,y=map(int,input().split())
    r.append((x,y))
r.sort()
ans=0
chk=[1]*n
for i in range(n):
    for j in range(n):
        if l[i][0]<r[j][0] and l[i][1]<r[j][1] and chk[j]:
            chk[j]=0
            ans+=1
            break
print(ans)
Buggy code:
#coding=utf-8

def solve(abs, cds):
    abs = sorted(abs, key = lambda x: -1 * x[1]) #sorted by y
    cds = sorted(cds, key = lambda x: x[0]) #sorted by x 

    count = 0
    for r in cds:
        print(r)
        _abs = list(filter(lambda x: r[0] > x[0] and r[1] > x[1], abs))
        if len(_abs) == 0:
            continue
        del abs[abs.index(_abs[0])]
        count += 1
    return count

if __name__ == '__main__':
    N = int(input())
    abs = []
    cds = []
    for _ in range(N):
        abs = abs + [list(map(lambda x: int(x), input().split()))] 
    for _ in range(N):
        cds = cds + [list(map(lambda x: int(x), input().split()))] 

    print(solve(abs, cds))


Fixed code:
#coding=utf-8

def solve(abs, cds):
    abs = sorted(abs, key = lambda x: -1 * x[1]) #sorted by y
    cds = sorted(cds, key = lambda x: x[0]) #sorted by x 

    count = 0
    for r in cds:
        _abs = list(filter(lambda x: r[0] > x[0] and r[1] > x[1], abs))
        if len(_abs) == 0:
            continue
        del abs[abs.index(_abs[0])]
        count += 1
    return count

if __name__ == '__main__':
    N = int(input())
    abs = []
    cds = []
    for _ in range(N):
        abs = abs + [list(map(lambda x: int(x), input().split()))] 
    for _ in range(N):
        cds = cds + [list(map(lambda x: int(x), input().split()))] 

    print(solve(abs, cds))
Buggy code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

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

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[1][0] > a[1][0] and b[1][1] > a[1][1] and not a[0]:
			b[0] = True
			a[0] = True
			count += 1

print(count)

Fixed code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

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

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[0] or a[0] : continue
		#print(b[1],a[1])
		if b[1][0] > a[1][0] and b[1][1] > a[1][1]:
			#print('make pair')
			b[0] = True
			a[0] = True
			count += 1

print(count)
Buggy code:
dat_r = []
dat_b = []

n = int(input())
for i in range(n):
    a,b = map(int, input().split())
    dat_r.append((a, b))

for i in range(n):
    c,d = map(int, input().split())
    dat_b.append((c, d))

dat_r.sort(key=lambda x: (-x[0]-x[1], -x[1], -x[0]))
dat_b.sort(key=lambda x: (x[0]+x[1],+x[1], +x[0]))
print("")
print(dat_r)
print(dat_b)
res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        #print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            #print("ok")
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)


Fixed code:
dat_r = []
dat_b = []

n = int(input())
for i in range(n):
    a,b = map(int, input().split())
    dat_r.append((a, b))

for i in range(n):
    c,d = map(int, input().split())
    dat_b.append((c, d))

dat_r.sort(key=lambda x: ( -x[1], -x[0]-x[1]))
dat_b.sort(key=lambda x: ( +x[0],  x[0]+x[1]))
#print("")
#print(dat_r)
#print(dat_b)
res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        # print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            # print("ok")
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        #print("{0} < {1} vs {2} < {3}".format(dat_r[i][0] ,dat_b[j][0] ,dat_r[i][1] ,dat_b[j][1]))
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            #print("ok")
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)
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 = sorted(A, key=lambda x: (x[0], x[1]))
B_sorted = sorted(B, key=lambda x: (x[0], x[1]))


def func():
    global A_sorted, B_sorted
    count = 0
    for b in B_sorted:
        a = None
        A_sorted_cp = A_sorted[:]
        while True:
            if len(A_sorted_cp) == 0:
                break
            a = A_sorted_cp.pop(0)
            if a[0] < b[0] and a[1]<b[1]:
                count += 1
                A_sorted.pop(A_sorted.index(a))
                break
    return count
            
    

print(func())

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 = sorted(A, key=lambda x: x[1], reverse=True)
B_sorted = sorted(B, key=lambda x: x[0])


def func():
    global A_sorted, B_sorted
    count = 0
    for b in B_sorted:
        a = None
        A_sorted_cp = A_sorted[:]
        while True:
            if len(A_sorted_cp) == 0:
                break
            a = A_sorted_cp.pop(0)
            if a[0] < b[0] and a[1]<b[1]:
                count += 1
                A_sorted.pop(A_sorted.index(a))
                break
    return count
            
    

print(func())
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 = sorted(ab, key = lambda x:x[0], reverse = True)
cd_sorted = sorted(cd, key = lambda x:x[0], reverse = True)


for i in range(len(ab_sorted)):
    candidate = -10e+10
    nearest_size = -10e+10
    for j in range(len(cd_sorted)):
        if cd_sorted[j][0] > ab_sorted[i][0] and cd_sorted[j][1] > ab_sorted[i][1] and nearest_size < cd_sorted[j][1]:
            candidate = j
            nearest_size = cd_sorted[j][1]
    if candidate != -10e+10:
        del cd_sorted[candidate]

print(len(ab_sorted) - len(cd_sorted))

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 = sorted(ab, key = lambda x:x[0], reverse = True)
cd_sorted = sorted(cd, key = lambda x:x[0], reverse = True)


for i in range(len(ab_sorted)):
    candidate = -10e+10
    minimum_size = 10e+10
    for j in range(len(cd_sorted)):
        if cd_sorted[j][0] > ab_sorted[i][0] and cd_sorted[j][1] > ab_sorted[i][1] and minimum_size > cd_sorted[j][1]:
            candidate = j
            minimum_size = cd_sorted[j][1]
    if candidate != -10e+10:
        del cd_sorted[candidate]
print(len(ab_sorted) - len(cd_sorted))
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)]
inab=[sum(map(lambda x:x[0]>a and x[1]>b,cd)) for a,b in ab]
incd=[sum(map(lambda x:x[0]<c and x[1]<d,ab)) for c,d in cd]
ans=0
while 1:
  f=1
  mab=1000
  for i in range(n):
    if inab[i] > 0 and mab > inab[i]:
      f=0
      mab=inab[i]
  if f:
    break
  mcd=1000
  tmp=(-1,-1)
  ans+=1
  for i in range(n):
    if mab==inab[i]:
      a,b=ab[i]
      for j in range(n):
        if incd[j]==0:continue
        c,d=cd[j]
        if a<c and b<d and mcd>incd[j]:
          mcd=incd[j]
          tmp=(i,j)
  ta,tb=ab[tmp[0]]
  tc,td=cd[tmp[1]]
  for i in range(n):
    a,b=ab[i]
    c,d=cd[i]    
    if inab[i]:
      if a<tc and b<td:
        inab[i]-=1
    if incd[i]:
      if c<ta and d<tb:
        incd[i]-=1  
print(ans)


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)]
inab=[sum(map(lambda x:x[0]>a and x[1]>b,cd)) for a,b in ab]
incd=[sum(map(lambda x:x[0]<c and x[1]<d,ab)) for c,d in cd]
ans=0
while 1:
  f=1
  mab=1000
  for i in range(n):
    if inab[i] > 0 and mab > inab[i]:
      f=0
      mab=inab[i]
  if f:
    break
  mcd=1000
  tmp=(-1,-1)
  ans+=1
  for i in range(n):
    if mab==inab[i]:
      a,b=ab[i]
      for j in range(n):
        if incd[j]==0:continue
        c,d=cd[j]
        if a<c and b<d and mcd>incd[j]:
          mcd=incd[j]
          tmp=(i,j)
  ta,tb=ab[tmp[0]]
  tc,td=cd[tmp[1]]
  inab[tmp[0]]=0
  incd[tmp[1]]=0
  for i in range(n):
    a,b=ab[i]
    c,d=cd[i]    
    if inab[i]:
      if a<tc and b<td:
        inab[i]-=1
    if incd[i]:
      if c>ta and d>tb:
        incd[i]-=1  
print(ans)
Buggy code:
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
red = []
blue = []
for i in range(n):
    li = na()
    li.append(0)
    red.append(li)
for i in range(n):
    li = na()
    li.append(0)
    blue.append(li)
red = sorted(red, key=itemgetter(0))
blue = sorted(blue, key=itemgetter(0))
ct = 0
for i in range(n):
    a, b, r = red[i]
    for j in range(n):
        c, d, l = blue[j]
        if r == 0 and l == 0 and a < c and b < d:
            ct += 1
            red[i][2] = 1
            blue[j][2] = 1
            break
print(ct)


Fixed code:
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
red = []
blue = []
for i in range(n):
    li = na()
    li.append(0)
    red.append(li)
for i in range(n):
    li = na()
    li.append(0)
    blue.append(li)
red = sorted(red, key=itemgetter(1))
blue = sorted(blue, key=itemgetter(0))
ct = 0
for i in range(n):
    c, d, r = blue[i]
    for j in range(n)[::-1]:
        a, b, l = red[j]
        if r == 0 and l == 0 and a < c and b < d:
            ct += 1
            red[j][2] = 1
            blue[i][2] = 1
            break
print(ct)
Buggy code:
N = int(input())
R = []
for i in range(N):
    R.append(input().split())
    R[i].append(0)
R.sort(key=lambda x:(int(x[0]),-int(x[1])))

B = []
for i in range(N):
    B.append(input().split())
    B[i].append(0)
B.sort(key=lambda x:(int(x[0]),int(x[1])))

a = 0
for i in range(N):
    for j in range(N):
        if int(R[j][0]) < int(B[i][0]) and int(R[j][1]) < int(B[i][1]) and R[j][2] == 0 and B[i][2] == 0:
            a += 1
            R[j][2] = 1
            B[i][2] = 1
            break

print(a)


Fixed code:
N = int(input())
R = []
for i in range(N):
    R.append(input().split())
    R[i].append(0)
R.sort(key=lambda x:(-int(x[1])))

B = []
for i in range(N):
    B.append(input().split())
    B[i].append(0)
B.sort(key=lambda x:(int(x[0]),int(x[1])))

a = 0
for i in range(N):
    for j in range(N):
        if int(R[j][0]) < int(B[i][0]) and int(R[j][1]) < int(B[i][1]) and R[j][2] == 0 and B[i][2] == 0:
            a += 1
            R[j][2] = j+1
            B[i][2] = j+1
            break

print(a)