Problem:
 Score : 400 points    Problem Statement On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i -th red point are (a_i, b_i) , and the coordinates of the i -th blue point are (c_i, d_i) .  A red point and a blue point can form a friendly pair when, the x -coordinate of the red point is smaller than that of the blue point, and the y -coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.      Constraints  All input values are integers.  1 \leq N \leq 100  0 \leq a_i, b_i, c_i, d_i < 2N  a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.  b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.         Input Input is given from Standard Input in the following format:  N  a_1  b_1  a_2  b_2  :  a_N  b_N  c_1  d_1  c_2  d_2  :  c_N  d_N       Output Print the maximum number of friendly pairs.        Sample Input 1 3
2 0
3 1
1 3
4 2
0 4
5 5      Sample Output 1 2  For example, you can pair (2, 0) and (4, 2) , then (3, 1) and (5, 5) .       Sample Input 2 3
0 0
1 1
5 2
2 3
3 4
4 5      Sample Output 2 2  For example, you can pair (0, 0) and (2, 3) , then (1, 1) and (3, 4) .       Sample Input 3 2
2 2
3 3
0 0
1 1      Sample Output 3 0  It is possible that no pair can be formed.       Sample Input 4 5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7      Sample Output 4 5       Sample Input 5 5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9      Sample Output 5 4

Solution (Python):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

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


flag1 = [False for _ in range(N)]
flag2 = [False for _ in range(N)]

res = 0
for i in range(N):
    for j in range(N):
        if A[i][0] < B[j][0] and A[i][1] < B[j][1] and flag1[i] == False and flag2[j] == False:
            res += 1
            flag1[i] = True
            flag2[j] = True

print(res)

Solution (Python):
from operator import itemgetter
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()
red2=sorted(red,key=itemgetter(1))
red3=[]
for x in red2[::-1]:
  red3.append(x)
count=0
for i in range(N):
  redlen=len(red3)
  j=0
  for j in range(redlen):
    if red3[j][0]<blue[i][0] and red3[j][1]<blue[i][1]:
      count+=1
      del red3[j]
      break
print(count)

Solution (Python):
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[1])
b.sort()
cnt = 0
for i in range(n):
    R = []
    for j in range(n):
        if 0 <= r[j][0] < b[i][0] and 0 <= r[j][1] < b[i][1]:
            R.append([r[j][1],j])
            
    R.sort(reverse=True)
    if len(R) >= 1:
        cnt += 1
        r[R[0][1]][0] = -1
        r[R[0][1]][1] = -1

print(cnt)

Solution (Python):
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])
res = 0
for i in range(len(blue)):
    index = -1
    maxy = -1
    for j in range(len(red)):
        if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            if red[j][1] > maxy:
                maxy = red[j][1]
                index = j
    if index != -1:
        red.pop(index)
        res += 1
print(res)

Solution (Python):
N = int(input())
AB = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x: -x[1])
CD = sorted([list(map(int,input().split())) for _ in range(N)])

cnt = 0
for c, d in CD:
  for a, b in AB:
    if(a < c and b < d):
      cnt += 1
      AB.remove([a,b])
      break
print(cnt)

Solution (Python):
n=int(input())
red=[tuple(map(int,input().split())) for i in range(n)]
blue=[tuple(map(int,input().split())) for i in range(n)]
red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue)
count=0
i=0
while i<len(blue):
    for j in range(len(red)):
        if red[j][0]<blue[i][0] and red[j][1]<blue[i][1]:
            count+=1
            del red[j]
            del blue[i]
            break
    else:
        i+=1
print(count)

Solution (Python):
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

class point:
    def __init__(self, x ,y):
        self.x = x
        self.y = y

n = int(input())

R_point = []
B_point = []

for i in range(n):
    temp = input_numbers()
    R_point += [point(temp[0], temp[1])]

for i in range(n):
    temp = input_numbers()
    B_point += [point(temp[0], temp[1])]

B_point.sort(key = lambda point:point.x)
R_point.sort(key = lambda point:point.y)
R_point.reverse()

count = 0

for i in range(len(B_point)):
    for j in range(len(R_point)):
        if(R_point[j].x < B_point[i].x and R_point[j].y < B_point[i].y):
            R_point.pop(j)
            count += 1
            break
print(count)

Solution (Python):
n = int(input())
AB = sorted([[int(i) for i in input().split()] for i in range(n)], reverse = True)
CD = sorted([[int(i) for i in input().split()] for i in range(n)], key = lambda x: x[1])

cnt = 0
for a, b in AB:
    for cd in CD:
        if a < cd[0] and b < cd[1]:
            cnt += 1
            CD.remove(cd)
            break
            
print(n - len(CD))

Solution (Python):
import collections


class FordFulkerson:
    """
    Verified with http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A
    """

    def __init__(self):
        self.g = collections.defaultdict(lambda: collections.defaultdict(int))

    def add_edge(self, u, v, c):
        self.g[u][v] = c

    def dfs(self, u, t, f, used: set):
        """
        :param u: visiting node
        :param t: sink
        :param f: flow
        :param used: node u is used?
        :return: min(c, f)
        """
        if u == t:
            return f

        used.add(u)

        
        for v, c in self.g[u].items():
            if v not in used and c > 0:
                f = min(c, f)
                d = self.dfs(v, t, f, used)

                
                if d > 0:
                    self.g[u][v] -= d
                    self.g[v][u] += d
                    return d

        
        return 0

    def max_flow(self, s, t):
        """Calculate maximum flow from s to t on the network

        :param s: source
        :param t: sink
        :return: max flow on the network
        """
        f = 0
        while True:
            d = self.dfs(s, t, float("inf"), set())
            if d == 0:  
                break
            f += d
        return f


def bipartite_matching(pairs: list, X :int, Y: int):
    solver = FordFulkerson()
    s = X+Y
    t = s+1
    for x, y in pairs:
        solver.add_edge(x, X+y, 1)
    for x in range(X):
        solver.add_edge(s, x, 1)
    for y in range(Y):
        solver.add_edge(X+y, t, 1)

    return solver.max_flow(s, t)


def main():
    N = int(input())
    rs = []
    bs = []
    for i in range(N):
        x, y = map(int, input().split())
        rs.append((x, y))
    for i in range(N):
        x, y = map(int, input().split())
        bs.append((x, y))

    pairs = []
    for i in range(N):
        for j in range(N):
            r = rs[i]
            b = bs[j]
            if r[0]<b[0] and r[1]<b[1]:
                pairs.append((i, j))
    print(bipartite_matching(pairs, N, N))


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
R=[[0,0,0] for _ in range(N)]
B=[[0,0,0] for _ in range(N)]
for i in range(N):
    R[i][0],R[i][1]=map(int,input().split())
for i in range(N):
    B[i][0],B[i][1]=map(int,input().split())
R.sort(key=lambda x:x[1],reverse=True)
B.sort()
cnt=0
for b in B:
    for r in R:
        if b[0]>r[0] and b[1]>r[1] and r[2]==0:
            cnt+=1
            r[2]=1
            break
print(cnt)

Solution (Python):


N = int(input())
red = [tuple(map(int, input().split())) for _ in range(N)]
blu = [tuple(map(int, input().split())) for _ in range(N)]

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

pairs = []
for b in blu:
    for r in red:
        if r[0] < b[0] and r[1] < b[1] and not r in pairs:
            pairs.append(r)
            break

print(len(pairs))

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
rl = [list(map(int, input().split())) for i in range(n)]
bl = [list(map(int, input().split())) for i in range(n)]

rl.sort(key=lambda x: x[1], reverse=True)
bl.sort(key=lambda y: y[0])

ans=0



for b in bl:
    for r in rl:
        if r[0] < b[0] and r[1] < b[1]:
            rl.remove(r)
            ans += 1
            break
print(ans)

Solution (Python):
n = int(input())

red = []
blue = []
for i in range(n):
    a,b = map(int,input().split())
    red.append((a,b))
for i in range(n):
    c,d = map(int,input().split())
    blue.append((c,d))
    
red_sorted = sorted(red,reverse=True)
blue_sorted = sorted(blue,key=lambda x: x[1])

count = 0
check = []
for i in red_sorted:
    for j,k in enumerate(blue_sorted):
        if (i[0] < k[0]) and (i[1] < k[1]):
            blue_sorted.pop(j)
            count += 1
            break
print(count)

Solution (Python):
n = int(input())
r = sorted([list(map(int, input().split())) for i in range(n)], reverse=True)
b = sorted([list(map(int, input().split())) for i in range(n)])

rd = set()

for i in range(n):
    p = []
    for j in range(n):
        if j in rd:
            continue
        if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
            p.append(r[j] + [j])
    if len(p) > 0:
        p.sort(key=lambda x: x[1], reverse=True)
        rd.add(p[0][2])
print(len(rd))

Solution (Python):
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(" ")])

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:
        
        if redPoint[0] < bluePoint[0] and redPoint[1] < bluePoint[1]:
            result += 1
            redPoints.remove(redPoint)
            
            break

print(result)

Solution (Python):
N = int(input())
red = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x:-x[1])
blue = sorted([list(map(int,input().split())) for _ in range(N)])

ans = 0
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)

Solution (Python):
from operator import itemgetter

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(reverse=True, key=itemgetter(1))
B.sort()

ans = 0
for b in B:
    for r in R:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            R.remove(r)
            break
print(ans)

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

count = 0
B = sorted(B)
for b in B:
    y_max = -1
    for i,r in enumerate(R):
        if r[0]<b[0] and r[1]<b[1] and y_max < r[1]:
            y_max = r[1]
            r_num = i
    if y_max != -1:
        R.pop(r_num)
        count += 1
print(count)

Solution (Python):
N = input()

B = [map(int,raw_input().split()) for i in range(N)]

A = [map(int,raw_input().split()) for i in range(N)]


A.sort()
B.sort()

for i in A:
    maxy = -1
    for j in B:
        if i[0] > j[0]:
            if maxy < j[1] and i[1] > j[1]:
                maxy = j[1]
                memory = j
        else:
            break
    if maxy != -1:
        B.remove(memory)

print len(A)-len(B)

Solution (Python):
N = int(input())
R = []
B = []
for i in range(N):
    r = list(map(int,input().split()))
    r.append(0)
    R.append(r)                                       
for i in range(N):
    b = list(map(int,input().split()))
    b.append(0)
    B.append(b)                                       

R.sort(reverse=True,key=lambda r: r[0])
B.sort(key=lambda b: b[1])

ans = 0
for b in B:
    for r in R:
        if(r[2]==1):
            continue
        elif((r[0]<b[0])and(r[1]<b[1])):
            ans += 1
            r[2]=1
            break
print(ans)

Solution (Python):
import queue

class Dinic:
    def __init__(self, v, inf = 1000000007):
        self.V = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [0 for _ in range(v)]
        self.iter = [0 for _ in range(v)]

    def add_edge(self, from_, to, cap):
        
        self.G[from_].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
        self.G[to].append({'to':from_, 'cap':0, 'rev':len(self.G[from_])-1})

    
    def bfs(self, s):
        self.level = [-1 for _ in range(self.V)]
        self.level[s] = 0
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e['cap'] > 0 and self.level[e['to']] < 0:
                    self.level[e['to']] = self.level[v] + 1
                    que.put(e['to'])

    
    def dfs(self, v, t, f):
        if v == t: return f
        for i in range(self.iter[v], len(self.G[v])):
            self.iter[v] = i
            e = self.G[v][i]
            if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
                d = self.dfs(e['to'], t, min(f, e['cap']))
                if d > 0:
                    e['cap'] -= d
                    self.G[e['to']][e['rev']]['cap'] += d
                    return d

        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            
            if self.level[t] < 0 : return flow
            self.iter = [0 for _ in range(self.V)]
            f = self.dfs(s, t, self.inf)
            while f > 0:
                flow += f
                f = self.dfs(s,t, self.inf)


N = int(input())
A = [] 
B = [] 
C = [] 
D = [] 

for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
for i in range(N):
    c,d = map(int, input().split())
    C.append(c)
    D.append(d)


s = 0
e = 1
r_top = 2
b_top = N+2

dinic = Dinic(2 + 2*N)
for i in range(N):
    dinic.add_edge(s, r_top+i, 1)
    for j in range(N):
        if ((A[i] < C[j]) & (B[i] < D[j])):
            dinic.add_edge(r_top+i, b_top+j, 1)
            
    dinic.add_edge(b_top+i, e, 1)

f = dinic.max_flow(s, e)

print(f)

Solution (Python):
n=int(input())
red=[list(map(int, input().split())) for _ in range(n)]
blue=[list(map(int, input().split())) for _ in range(n)]
blue=sorted(blue, key=lambda x:x[0])
ans=0 
for b in blue:
    for r in sorted([r_ for r_ in red if r_[0]<b[0]], key=lambda x:x[1], reverse = True):
        if r[1]<b[1]:
            ans+=1
            red.pop(red.index(r))
            break
print(ans)

Solution (Python):
n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[0])

def beFriend(red, blue):
    if red[0] < blue[0] and red[1] < blue[1]:
        return 1
    else:
        return 0

res = 0

for b in blue:
    for r in sorted([sr for sr in red if sr[0] < b[0]], key=lambda x:x[1], reverse = True):
        if beFriend(r, b):
            res += 1
            red.pop(red.index(r))
            break

print(res)

Solution (Python):


import numpy as np
import random
import copy

def select_ok(r_list,b_position):
    pass_list = []
    for i in range(len(r_list)):
        if r_list[i][0] < b_position[0] and r_list[i][1] < b_position[1]:
            pass_list.append(r_list[i])

    return pass_list



n = int(input())
r = []
b = []

for i in range(n):
    position = list(map(int, input().split()))
    r.append(position)

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

b_sorted = sorted(b,key=lambda x:x[0])
count = 0
for i in range(n):
    pairs = select_ok(r,b_sorted[i])
    if len(pairs) > 0:
        sorted_pairs = sorted(pairs,key=lambda x:x[1],reverse=True)
        
        count += 1
        r.remove(sorted_pairs[0])

print(count)

Solution (Python):
n = int(input())
Ps = [tuple(map(int, input().split())) for i in range(n)]
Qs = [tuple(map(int, input().split())) for i in range(n)]

Qs.sort()

ans = 0
for i in range(n):
    
    l = [(Ps[j], j)
         for j in range(len(Ps))
         if Ps[j][0] <= Qs[i][0] and Ps[j][1] <= Qs[i][1]]

    
    if l == []: continue

    
    E = max(l, key=(lambda e: e[0][1]))
    del Ps[E[1]]
    ans += 1
print(ans)

Solution (Python):
from copy import deepcopy


def main() -> None:
    n = int(input())
    red_points = [[int(r) for r in input().split()] for _ in range(n)]
    blue_points = [[int(b) for b in input().split()] for _ in range(n)]
    ans = 0

    for i in range(2):
        for j in range(2):
            red_points.sort(key=lambda x: x[i ^ 1])
            red_points.sort(key=lambda x: x[i])

            blue_points.sort(key=lambda x: -x[j ^ 1])
            blue_points.sort(key=lambda x: -x[j])

            rps = deepcopy(red_points)
            bps = deepcopy(blue_points)

            cnt = 0
            while len(rps) > 0:
                for k in range(len(bps) - 1, -1, -1):
                    if rps[-1][0] < bps[k][0] and rps[-1][1] < bps[k][1]:
                        rps.pop()
                        bps.pop(k)
                        cnt += 1
                        break
                    if k == 0:
                        rps.pop()
                ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
ab = sorted([[int(i) for i in input().split()] for i in range(n)], reverse = True, key = lambda x: x[1])
cd = sorted([[int(i) for i in input().split()] for i in range(n)])

count = 0
for i in range(n):
    for j in range(len(cd)):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            count += 1
            del cd[j]
            break

print(count)

Solution (Python):

n=int(input())
aa=[[int(i) for i in input().split()] for i in range(n)]
bb=[[int(i) for i in input().split()] for i in range(n)]




import operator
aa.sort(key=operator.itemgetter(1),reverse=True)
bb.sort()
  



answer=0
for b in bb:
  xb,yb=b
  for a in aa:
    xa,ya=a
    if xa<xb and ya<yb:
      answer=answer+1
      aa. remove (a)
      
      
      
      break
      
print(answer)

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

red = sorted(red,key=lambda x:(-x[1]))
blue = [list(map(int,input().split())) for i in range(N)]

blue = sorted(blue,key=lambda x:(x[0]))
cnt = 0
pair = []
for i in range(N):
    b_x = blue[i][0]
    b_y = blue[i][1]
    for j in range(N):
        index = 0
        for e in red:
            a_x = e[0]
            a_y = e[1]
            if b_x > a_x and b_y > a_y:
                cnt += 1
                pair.append([blue[i],e])
                del red[index]
                break
            index += 1
        else:
            continue
        break
print(cnt)

Solution (Python):
N = int(input())
red = [[int(i) for i in input().split()] for j in range(N)]
blue = [[int(i) for i in input().split()] for j in range(N)]

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

ans = 0

while blue:
    bA = blue.pop(0)
    for i in range(len(red)):
        rA = red[i]
        if bA[0]>rA[0] and bA[1]>rA[1]:
            red.pop(i)
            ans += 1
            break

print(ans)

Solution (Python):
N=int(input())
red=sorted([list(map(int,input().split())) for i in range(N)], key=lambda x:-1*x[1])
blue=sorted([list(map(int,input().split())) for i in range(N)])
red = sorted(red, key = lambda x:x[1] * -1)
count=0
for i in red:
    for n,j in enumerate(blue):
        if i[0]<j[0] and i[1]<j[1]:
            count+=1
            del blue[n]
            break
print(count)

Solution (Python):


def main():
    N = int(input())
    pa = []
    for i in range(N):
        s = input().split()
        a, b = int(s[0]), int(s[1])
        pa.append((0, a, b))
    for i in range(N):
        s = input().split()
        c, d = int(s[0]), int(s[1])
        pa.append((1, c, d))

    pa.sort(key = lambda v: v[1])

    c = 0
    st = []
    for v in pa:
        if v[0] == 0:
            if len(st) == 0 or st[-1][2] > v[2]:
                st.append(v)
            else:
                for i, w in enumerate(st):
                    if v[2] > w[2]:
                        st.insert(i, v)
                        break
        else:
            for i in range(len(st)):
                if v[2] > st[i][2]:
                    st.pop(i)
                    c += 1
                    break


    print(c)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
red=sorted([list(map(int,input().split())) for i in range(N)], key=lambda x:-1*x[1])
blue=sorted([list(map(int,input().split())) for i in range(N)])
red = sorted(red, key = lambda x:x[1] * -1)
count=0
for i in red:
    for n,j in enumerate(blue):
        if i[0]<j[0] and i[1]<j[1]:
            count+=1
            del blue[n]
            break
print(count)

Solution (Python):
import collections
N = int(input())
red = []
for i in range(N):
    red.append(list(map(int, input().split())))
blue = []
for i in range(N):
    blue.append(list(map(int, input().split())))

ans = 0
blue.sort()

for i in range(N):
    index = -1
    red_y_max = -1
    for j in range(len(red)):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            if red_y_max < red[j][1]:
                index = j
                red_y_max = red[j][1]
    if index != -1:
        red.pop(index)
        ans += 1

print(ans)

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]
B = [[int(i) for i in input().split()] for i in range(n)]
A.sort(reverse=True)
B.sort(key=lambda x: x[1])

count = 0
for i in range(n):
    for j in range(len(B)):
        if A[i][0] < B[j][0] and A[i][1] < B[j][1]:
            count += 1
            B.pop(j)
            break
        
print(count)

Solution (Python):
n = int(input())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(n)]
sortAB = sorted(AB, reverse=True)
sortCD = sorted(CD, key=lambda x: x[1])

for i in range(n):
    for j in range(len(sortCD)):
        if sortAB[i][0] < sortCD[j][0] and sortAB[i][1] < sortCD[j][1]:
            sortCD.pop(j)
            break
            
print(n - len(sortCD))

Solution (Python):
n = int(input())

AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(n)]

AB = sorted(AB, reverse=True, key=lambda x: x[1])
CD = sorted(CD)

for i in range(n):
    for j in range(len(CD)):
        if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
            CD.pop(j)
            break
            
print(n - len(CD))

Solution (Python):
N = int(input())
reds = [tuple(map(int, input().strip().split())) for _ in range(N)]
blues = [tuple(map(int, input().strip().split())) for _ in range(N)]
redset = set()
for b in sorted(blues, key=lambda x: x[0]):
  for r in sorted(reds, key=lambda x: -x[1]):
    if r not in redset and b[0] > r[0] and b[1] > r[1]:
      redset.add(r)
      break
print(len(redset))

Solution (Python):
N = int(input())
Blue = []
Red = []
for i in range(N) :
    a,b = map(int,input().split())
    Red.append([a,b])
for i in range(N) :
    c,d = map(int,input().split())
    Blue.append([c,d])

Blue = sorted(Blue)
Red = list(reversed(sorted(Red,key=lambda x: x[1])))

ans = 0
for i in range(N) :
    for j in range(N) :
        if j >= len(Red) :
            break
        if (Blue[i][0] > Red[j][0]) and (Blue[i][1] > Red[j][1]) :
            ans += 1
            Red.pop(j)
            break
print(ans)

Solution (Python):
N = int(input())
R = []
B = []

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

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

B.sort()

pair = [0] * N
ans = 0

for i in range(N):
    bx, by = B[i]
    d = -1
    d_j = -1
    for j in range(N):
        ax, ay = R[j]
        if ax < bx and ay < by and pair[j] == 0:
            if ay > d:
                d = ay
                d_j = j
    if d_j != -1:
        pair[d_j] = 1
        ans += 1

print(ans)

Solution (Python):
import sys

N = int(input())

R = []
for i in range(N):
    a, b = [int(x) for x in input().split()]
    R.append((a, b))

B = []
for i in range(N):
    c, d = [int(x) for x in input().split()]
    B.append((c, d))

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

ans = 0
used_idx = []
for b in B:
    idx = -1
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            if used_idx.count(i) == 0:
                idx = i
                break
    if idx != -1:
        used_idx.append(idx)
        ans += 1
        

print(ans)

Solution (Python):
n = int(input())
pairs_ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[1], reverse=True) 
pairs_cd = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[0]) 

cnt = 0
for pair_b in pairs_cd:
  for pair_a in pairs_ab:
    if pair_b[1] > pair_a[1] and pair_b[0] > pair_a[0]:
      cnt += 1
      pair_a[0] = pair_a[1] = float('inf')
      break

print(cnt)

Solution (Python):
n = int(input())

AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(n)]

AB = sorted(AB, reverse=True)
CD = sorted(CD, key=lambda x: x[1])

for i in range(n):
    for j in range(len(CD)):
        if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
            CD.pop(j)
            break
            
print(n - len(CD))

Solution (Python):
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1],
            reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
 
count = 0
for i in range(N):
    for j in range(len(AB)):
        if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
            del AB[j]
            count += 1
            break
print(count)

Solution (Python):
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1],
            reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
 
for i in range(N):
    for j in range(len(AB)):
        if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
            del AB[j]
            break
print(N - len(AB))

Solution (Python):
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1],
            reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
 
for i in range(N):
    for j in range(len(AB)):
        if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
            AB.pop(j)
            break
print(N - len(AB))

Solution (Python):
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1],
            reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
 
for i in range(N):
    p = -1
    for j in range(len(AB)):
        if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
            p = j
            break
    if p > -1:
        AB.pop(p)
print(N - len(AB))

Solution (Python):
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1],
            reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])

for i in range(N):
    p = -1
    for j in range(len(AB)):
        if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
            p = j
            break
    if p > -1:
        AB.pop(p)
print(N - len(AB))

Solution (Python):
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep=" ",end="")
    print()
    

from operator import itemgetter
n = int(input())
a=[]
b=[]
arr = [[0]*n for _ in range(n)]
for i in range(n):
    a.append(list(map(int,input().split())))
    a[-1].append(0)
for i in range(n):
    b.append(list(map(int,input().split())))
    b[-1].append(0)
b.sort(key=itemgetter(0))
a.sort(key=itemgetter(1))
a = a[::-1]
count = 0
for i in range(n):
    for j in range(n):
        if a[j][2] == 0 and b[i][2] == 0:
            if b[i][0] - a[j][0] > 0 and b[i][1] - a[j][1] > 0:
                count += 1
                a[j][2] = 1
                b[i][2] = 1
                continue
            
print(count)

Solution (Python):
n = int(input())
red = []
for i in range(n):
    a, b = map(int, input().split())
    red.append((a, b))

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

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

count = 0
while len(blue) >= 1:
    c, d = blue.pop(0)
    tmp = []
    r = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            r.append((a, b))
        else:
            tmp.append((a, b))
    if len(r) >= 1:
        count += 1
        r = sorted(r, key=lambda x:x[1])
        r.pop()
        tmp.extend(r)
    red.extend(tmp)
print(count)

Solution (Python):
n = int(input())
red = []
for i in range(n):
    a, b = map(int, input().split())
    red.append((a, b))

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

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

count = 0
while len(blue) >= 1:
    c, d = blue.pop(0)
    tmp = []
    r = []
    while len(red) >= 1:
        a, b = red.pop()
        if a < c and b < d:
            r.append((a, b))
        else:
            tmp.append((a, b))
    if len(r) >= 1:
        count += 1
        r = sorted(r, key=lambda x:x[1])
        r.pop()
        tmp.extend(r)
    red.extend(tmp)
print(count)

Solution (Python):
n = (int)(input())

r = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    r.append([x, y])

for _ in range(n):
    x, y = map(int, input().split())
    b.append([x, y])

r.sort(key=lambda x: (x[1], x[0]))
b.sort(key=lambda x: (x[0], x[1]))



ans = 0
used_r = []
for i in range(n):
    
    cnd = [v for v in r if v[0] < b[i][0]]
    cnd.sort(key=lambda x: x[1])
    pair = -1
    for j in range(len(cnd)):
        if cnd[j][1] < b[i][1]:
            pair = cnd[j]

    
    
    if pair != -1:
        r.remove(pair)
        ans += 1

print(ans)

Solution (Python):
from operator import itemgetter

n = int(input())
r = []
b = []
c = 0
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.sort(key = itemgetter(1),reverse = True)
b.sort(key = itemgetter(0))
for i in range(n):
  for j in range(n):
    if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
      r[j] = [10**6,10**6]
      c += 1
      break
print(c)