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):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import deque
class HopcroftKarp:
    def __init__(self, N0, N1):
        self.N0 = N0
        self.N1 = N1
        self.N = N = 2+N0+N1
        self.G = [[] for i in range(N)]
        for i in range(N0):
            forward = [2+i, 1, None]
            forward[2] = backward = [0, 0, forward]
            self.G[0].append(forward)
            self.G[2+i].append(backward)
        self.backwards = bs = []
        for i in range(N1):
            forward = [1, 1, None]
            forward[2] = backward = [2+N0+i, 0, forward]
            bs.append(backward)
            self.G[2+N0+i].append(forward)
            self.G[1].append(backward)

    def add_edge(self, fr, to):
        
        
        v0 = 2 + fr
        v1 = 2 + self.N0 + to
        forward = [v1, 1, None]
        forward[2] = backward = [v0, 0, forward]
        self.G[v0].append(forward)
        self.G[v1].append(backward)

    def bfs(self):
        G = self.G
        level = [None]*self.N
        deq = deque([0])
        level[0] = 0
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        self.level = level
        return level[1] is not None

    def dfs(self, v, t):
        if v == t:
            return 1
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w] and self.dfs(w, t):
                e[1] = 0
                rev[1] = 1
                return 1
        return 0

    def flow(self):
        flow = 0
        G = self.G
        bfs = self.bfs; dfs = self.dfs
        while bfs():
            *self.it, = map(iter, G)
            while dfs(0, 1):
                flow += 1
        return flow

    def matching(self):
        return [cap for _, cap, _ in self.backwards]

def resolve():
    n=int(input())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    CD=[tuple(map(int,input().split())) for _ in range(n)]

    mm=HopcroftKarp(n,n)
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                mm.add_edge(i,j)
    print(mm.flow())
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import deque
class Dinic(object):
    def __init__(self,n):
        self.__n=n
        self.__E=[[] for _ in range(n)]
        self.__level=None
        self.__iter=None

    def add_link(self,u,v,w):
        self.__E[u].append([v,w,len(self.__E[v])])
        self.__E[v].append([u,0,len(self.__E[u])-1])

    def __bfs(self,s):
        level=[-1]*self.__n
        level[s]=0
        Q=deque([s])
        while(Q):
            v=Q.popleft()
            for nv,w,rev in self.__E[v]:
                if(w>0 and level[nv]<0):
                    level[nv]=level[v]+1
                    Q.append(nv)
        self.__level=level

    def __dfs(self,v,t,flow):
        if(v==t): return flow
        for i in range(self.__iter[v],len(self.__E[v])):
            self.__iter[v]=i
            nv,w,rev=self.__E[v][i]
            if(w==0 or self.__level[v]>=self.__level[nv]): continue
            d=self.__dfs(nv,t,min(flow,w))
            if(d==0): continue
            self.__E[v][i][1]-=d
            self.__E[nv][rev][1]+=d
            return d
        return 0

    def flow(self,s,t):
        flow=0
        while(True):
            self.__bfs(s)
            if(self.__level[t]<0): return flow
            self.__iter=[0]*self.__n
            current_flow=self.__dfs(s,t,INF)
            while(current_flow):
                flow+=current_flow
                current_flow=self.__dfs(s,t,INF)

def resolve():
    n=int(input())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    CD=[tuple(map(int,input().split())) for _ in range(n)]

    
    mf=Dinic(2*n+2)
    for i in range(n):
        mf.add_link(0,i+1,1)
        mf.add_link(n+i+1,2*n+1,1)
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                mf.add_link(i+1,n+j+1,1)

    print(mf.flow(0,2*n+1))
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import deque
class Dinic:
    def __init__(self,n):
        self.__n=n
        self.__E=[[] for _ in range(n)]
        self.__depth=None
        self.__progress=None

    def add_link(self,u,v,w):
        self.__E[u].append([v,w,len(self.__E[v])])
        self.__E[v].append([u,0,len(self.__E[u])-1])

    def __bfs(self,s):
        depth=[-1]*self.__n
        depth[s]=0
        Q=deque([s])
        while(Q):
            v=Q.popleft()
            for nv,w,rev in self.__E[v]:
                if(w>0 and depth[nv]<0):
                    depth[nv]=depth[v]+1
                    Q.append(nv)
        self.__depth=depth

    def __dfs(self,v,t,flow):
        if(v==t): return flow
        for i in range(self.__progress[v],len(self.__E[v])):
            self.__progress[v]=i
            nv,w,rev=self.__E[v][i]
            if(w==0 or self.__depth[v]>=self.__depth[nv]): continue
            d=self.__dfs(nv,t,min(flow,w))
            if(d==0): continue
            self.__E[v][i][1]-=d
            self.__E[nv][rev][1]+=d
            return d
        return 0

    def flow(self,s,t):
        flow=0
        while(True):
            self.__bfs(s)
            if(self.__depth[t]<0): return flow
            self.__progress=[0]*self.__n
            current_flow=self.__dfs(s,t,INF)
            while(current_flow):
                flow+=current_flow
                current_flow=self.__dfs(s,t,INF)

def resolve():
    n=int(input())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    CD=[tuple(map(int,input().split())) for _ in range(n)]

    
    mf=Dinic(2*n+2)
    for i in range(n):
        mf.add_link(0,i+1,1)
        mf.add_link(n+i+1,2*n+1,1)
    for i in range(n):
        a,b=AB[i]
        for j in range(n):
            c,d=CD[j]
            if(a<c and b<d):
                mf.add_link(i+1,n+j+1,1)

    print(mf.flow(0,2*n+1))
resolve()

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

ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[1])

mm=sorted([list(map(int,input().split())) for _ in range(n)])
count_num=0
for i,j in mm:
  for k,h in ll:
    if k<=i and h<=j:
      count_num+=1
      ll.remove([k,h])
      break
print(count_num)

Solution (Python):
n=int(input())
l=[]
for i in range(n):
  l1=list(map(int,input().split()))
  l.append(l1+["a",0])
for i in range(n):
  l1=list(map(int,input().split()))
  l.append(l1+["b"])
count=0
l=sorted(l)
for i in range(2*n):
  if l[i][2]=="a":
    pass
  else:
    num=l[i][1]
    min=100
    index=-1
    if i==0:
      pass
    else: 
      for j in range(0,i):
        if l[j][2]=="a":
          if l[j][3]==0:
            if min>num-l[j][1] and num>l[j][1]:
              min=num-l[j][1]
              index=j
      if index!=-1:
        l[index][3]=1
        count+=1
print(count)

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

Solution (Python):
n = int(input())
list_r = [list(map(int, input().split())) for _ in range(n)]
list_b = [list(map(int, input().split())) for _ in range(n)]
list_b.sort(key=lambda x:(x[0], x[1]))

count = 0
for one_b in list_b:
  idx = -1
  max_y = -1
  for i, one_r in enumerate(list_r):
    if one_r[0] < one_b[0] and max_y < one_r[1] < one_b[1]:
      max_y = one_r[1]
      idx = i
  if idx != -1:
    count += 1
    list_r.pop(idx)
print(count)

Solution (Python):
N = int(input())
R = [[int(a) for a in input().split()] for _ in range(N)]
B = [[int(c) for c in input().split()] for _ in range(N)]

B.sort()
used = [0]*N

for i in range(N):
    y = -1
    idx = -1
    for j in range(N):
        if R[j][0] < B[i][0] and R[j][1] < B[i][1] and used[j] == 0:
            if R[j][1] > y:
                y = R[j][1]
                idx = j
                
    if idx >= 0:
        used[idx] = 1
        
print(sum(used))

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

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

print(cnt)

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

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    ab = [list(map(int, readline().split())) for _ in range(n)]
    ab = sorted(ab)
    ab = sorted(ab, key=lambda x: x[1], reverse=True)
    cd = [list(map(int, readline().split())) for _ in range(n)]
    cd = sorted(cd)
    cnt = 0
    for i in range(n):
        for j in range(n):
            if ab[i][0] <= cd[j][0] and ab[i][1] <= cd[j][1]:
                cnt += 1
                cd[j][0] = cd[j][1] = 0
                break
    print(cnt)


if __name__ == '__main__':
    solve()

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

counter = 0
i = 0
while i < len(Blue):
  for j in range(len(Red)):

    if Blue[i][1] > Red[j][1] and Blue[i][0] > Red[j][0]:

      Blue.remove(Blue[i])
      Red.remove(Red[j])
      counter += 1
      break
  else:
    i += 1
print(counter)

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)]
res = 0
red.sort(key=lambda x: x[1],reverse=True)
blue.sort()
for i in range(n):
    for j in range(len(red)):
        if red[j][0]<blue[i][0] and red[j][1]<blue[i][1]:
            red.pop(j)
            res += 1
            break
print(res)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
def FF(E, s, t):
    NN = 2*N+2
    G = [[] for _ in range(NN)]
    for a, b, f in E:
        G[a].append([b, f, len(G[b])])
        G[b].append([a, 0, len(G[a])-1])
    
    def dfs(s, t, f):
        if s == t:
            return f
        used[s] = 1
        for i, (b, _f, r) in enumerate(G[s]):
            if used[b] or _f == 0: continue
            d = dfs(b, t, min(f, _f))
            if d > 0:
                G[s][i][1] -= d
                G[b][r][1] += d
                return d
        return 0
    
    flow = 0
    while 1:
        used = [0] * NN
        f = dfs(s, t, 10**100)
        if f == 0:
            return flow
        flow += f

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

E = []
for i in range(N):
    E.append((2*N, i, 1))
for i in range(N):
    E.append((N+i, 2*N+1, 1))

for i in range(N):
    for j in range(N):
        if R[i][0] < B[j][0] and R[i][1] < B[j][1]:
            E.append((i, N+j, 1))

print(FF(E, 2*N, 2*N+1))

Solution (Python):


import sys










def main():
    n = int(sys.stdin.readline().rstrip())
    red = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]
    blue = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]
    reversed_b_sorted_by_a= [ab[1] for ab in sorted(red, reverse=1)]
    bd_sorted_by_ac = [acbd[1] for acbd in sorted(red + blue)]


    count = 0
    for b in reversed_b_sorted_by_a:
        b_index = bd_sorted_by_ac.index(b)
        if b_index == len(bd_sorted_by_ac) - 1:
            bd_sorted_by_ac.remove(b)
            continue
        
        range_to_scope = bd_sorted_by_ac[b_index+1:]
        possible_elements = [x for x in range_to_scope if x > b]
        if not possible_elements:
            bd_sorted_by_ac.remove(b)
            continue

        bd_sorted_by_ac.remove(min(possible_elements))
        bd_sorted_by_ac.remove(b)
        count += 1
    print(count)


if __name__ == "__main__":
    
    main()

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

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

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[1])
red.sort()
blue.sort(key=lambda x: x[1])
blue.sort()
answer = 0
for bx, by in blue:
    l = []
    for i in range(len(red)):
        rx, ry = red[i]
        if rx < bx and ry < by:
            l.append((ry, rx, i))
    if len(l) >= 1:
        l.sort(reverse=True)
        answer += 1
        red.pop(l[0][2])
print(answer)

Solution (Python):
n=int(input())
r=[list(map(int,input().split())) for i in range(n)]
b=sorted([list(map(int,input().split())) for i in range(n)], key=lambda x:x[0])
cnt=0
for bb in b:
    t_r=[-1,-1]
    for rr in r:
        if rr[0]<bb[0] and t_r[1]<rr[1]<bb[1]:
            t_r=rr
    if t_r!=[-1,-1]:
        cnt+=1
        r.remove(t_r)
print(cnt)

Solution (Python):
def main():
    n=int(input())
    ab=[]
    cd=[]
    for _ in range(n):
        ab.append(list(map(int,input().split())))
    for _ in range(n):
        cd.append(list(map(int,input().split())))
    ab.sort(reverse=True , key=lambda y:y[1])
    cd.sort(key=lambda y:y[0])
    ans=0
    for i in range(n):
        [x,y]=cd[i]
        for j in range(len(ab)):
            if x>ab[j][0] and y>ab[j][1]:
                ab.pop(j)
                ans+=1
                break
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
V = 2*N
Red = [list(map(int, input().split())) for _ in range(N)]
Blue = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(V)]
for i in range(N):
    for j in range(N):
        a, b = Red[i]
        c, d = Blue[j]
        if a < c and b < d:
            j += N
            graph[i].append(j)
            graph[j].append(i)

match = [-1]*V 
used = [False]*V 


def dfs(v):
    used[v] = True
    for nv in graph[v]:
        w = match[nv]
        if w < 0 or (not used[w] and dfs(w)):
            match[v] = nv
            match[nv] = v
            return True
    return False


def bipartite_matching():
    res = 0
    global match
    match = [-1]*V
    for v in range(V):
        if match[v] < 0:
            global used
            used = [0]*V
            if dfs(v):
                res += 1
    return res


if __name__ == '__main__':
    print(bipartite_matching())

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

Solution (Python):
import bisect
n=int(input())
r=[]
b=[]
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()
b.sort()

ans=0
for i in range(n):
    j=(n-1)-i
    bc,bd=list(zip(*b))

    bj_morethan_aj = bisect.bisect_left(bc, r[j][0])
    more_bi = b[bj_morethan_aj:]
    least_bd_k=-1
    least_bd=10000000
    for k in range(len(more_bi)):
        if(r[j][1] < more_bi[k][1] and more_bi[k][1] < least_bd):
            least_bd = more_bi[k][1]
            least_bd_k = k

    if(least_bd_k != -1):
        ans+=1

        del b[bj_morethan_aj+least_bd_k]
print(ans)

Solution (Python):
N=int(input())
A,B,C,D=[0]*N,[0]*N,[0]*N,[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
for i in range(N):
  C[i],D[i]=map(int,input().split())
R=[0]*N
for i in range(N):
  R[i]=A[i]*1000+B[i]
B=[0]*N
for i in range(N):
  B[i]=C[i]*1000+D[i]
B.sort()
X=[0]*N
ans=0
for i in range(N):
  BX,BY=B[i]//1000,B[i]%1000
  M=-1
  for j in range(N):
    if(X[j]==0):
      RX,RY=R[j]//1000,R[j]%1000
      if(RX<BX and RY<BY):
        if(M==-1):
          M=j
        elif(RY>R[M]%1000):
          M=j
  if(M!=-1):
    X[M]=1
    ans+=1
print(ans)

Solution (Python):
from heapq import *
from bisect import *
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    hp = []
    for _ in range(n):
        a, b = map(int, input().split())
        heappush(hp, [a, 1, b])
    for _ in range(n):
        a, b = map(int, input().split())
        heappush(hp, [a, 0, b])
    yy = []
    ans = 0
    while hp:
        x, q, y = heappop(hp)
        if q:
            insort(yy, y)
        else:
            i = bisect_left(yy, y)
            if i > 0:
                del yy[i - 1]
                ans += 1
    print(ans)

main()

Solution (Python):

import sys
import bisect

def main():
    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],x[1]))
    red_x = [r[0] for r in red]
    blue.sort(key= lambda x:x[0])
    answer = 0
    for i  in range(N):
        b = blue[i][0]
        max_x_index = bisect.bisect_left(red_x,b)
        search_target_red = red[:max_x_index]
        max_y = 0 
        max_index = -1

        for j,r in enumerate(search_target_red):
            if blue[i][1]>r[1]>=max_y:
                max_y = r[1]
                max_index=j
 
        if max_index!=-1:
            answer+=1
            red.pop(max_index)
            red_x.pop(max_index)
    
    print(answer)










if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
R = [(-1, -1)] * N
for n in range(N):
    x, y = map(int, input().split())
    R[n] = (x, y)
B = [(-1, -1)] * N
for n in range(N):
    x, y = map(int, input().split())
    B[n] = (x, y)

B = sorted(B)
R = sorted(R, reverse=True)

ans = 0
for i, b in enumerate(B):
    tmp = []
    for j, r in enumerate(R):
        if r[0] == -1:
            continue
        if r[0] < b[0] and r[1] < b[1]:
            tmp.append((j, r))
    if tmp:
        tmp = sorted(tmp, key=lambda x: x[1][1], reverse=True)
        R[tmp[0][0]] = (-1, -1)
        ans += 1

print(ans)

Solution (Python):
"""
出典:https://atcoder.jp/contests/abc005/tasks/abc005_3
"""
def main():
  N = int(input())
  red_l = [list(map(int,input().split())) for _ in range(N)]
  blue_l = [list(map(int,input().split())) for _ in range(N)]
  red_l=sorted(red_l,key=lambda x:-x[1])
  blue_l=sorted(blue_l,key=lambda x:x[0])

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

if __name__=="__main__":
  main()

Solution (Python):
n = int(input())
lired = [list(map(int,input().split())) for _ in range(n)]
liblue = [list(map(int,input().split())) for _ in range(n)]
lired = sorted(lired,key = lambda x:-x[1])
liblue = sorted(liblue,key = lambda x:x[0])
li = list(range(n))
count = 0

for i in range(n):
  for j in li:
    if lired[i][0] < liblue[j][0] and lired[i][1] < liblue[j][1]:
      count += 1
      li.remove(j)
      break
print(count)

Solution (Python):
n = int(input())
lired = [list(map(int,input().split())) for _ in range(n)]
liblue = [list(map(int,input().split())) for _ in range(n)]
lired = sorted(lired,key = lambda x:-x[1])
liblue = sorted(liblue,key = lambda x:x[0])
li = list(range(n))
cnt = 0



for i in range(n):
  for j in li:
    if lired[i][0] < liblue[j][0] and lired[i][1] < liblue[j][1]:
      cnt += 1
      li.remove(j)
      break
print(cnt)

Solution (Python):
n = int(input())
lired = [list(map(int,input().split())) for _ in range(n)]
liblue = [list(map(int,input().split())) for _ in range(n)]
lired = sorted(lired,key = lambda x:-x[1])
liblue = sorted(liblue,key = lambda x:x[0])
li = list(range(n))
cnt = 0



for i in range(n):
  for j in li:
    if lired[j][0] < liblue[i][0] and lired[j][1] < liblue[i][1]:
      cnt += 1
      li.remove(j)
      break
print(cnt)

Solution (Python):
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
AB_=sorted(AB,key=lambda x:-x[0])
CD=[list(map(int,input().split())) for _ in range(N)]
CD_=sorted(CD,key=lambda x:-x[0])
ans=0
for i in range(N):
    target=[]
    for j in range(len(CD_)):
        if CD_[j][0]>AB_[i][0] and CD_[j][1]>AB_[i][1]:
            target.append(CD_[j])
    target=sorted(target,key=lambda x:x[1])
    if len(target)==0:
        continue
    else:
        ans+=1
        CD_.remove(target[0])
print(ans)

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

    red.sort(reverse=True)
    blue.sort()
    ans1 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans1 += 1
                a[2] = False
                break

    red.sort(key=lambda p: p[1],reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort(key=lambda p: p[1])
    ans2 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans2 += 1
                a[2] = False
                break

    red.sort(key=lambda p: p[1],reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort()
    ans3 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans3 += 1
                a[2] = False
                break

    red.sort(reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort(key=lambda p: p[1])
    ans4 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans4 += 1
                a[2] = False
                break

    print(max(ans1,ans2,ans3,ans4))

if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heappop, heappush
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()

se=set()
for c,d in cd:
    li=[]
    for a,b in ab:
        if a>=c or b>=d:
            continue
        else:
            if (a,b) not in se:
                heappush(li,[-b,a])
    if li:
        b,a=heappop(li)
        se.add((a,-b))
print(len(se))

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_s = sorted(red,key=lambda x:x[1],reverse=True)
blue_s = sorted(blue)

pair = 0
for bx,by in blue_s:
  for i,(rx,ry) in enumerate(red_s):    
    if rx<bx and ry<by:
      pair +=1
      red_s.pop(i)
      break

print(pair)

Solution (Python):
N = int(input())
AB = []
CD = []
for _ in range(N):
    ab = list(map(int, input().split()))
    ab.append(True)
    AB.append(ab)
for _ in range(N):
    cd = list(map(int, input().split()))
    cd.append(True)
    CD.append(cd)
AB.sort(key=lambda x: x[1], reverse=True)
CD.sort(key=lambda x: x[0])
ans = 0

for i in range(N):
    for j in range(N):
        if AB[j][2] and CD[i][2]:
            if AB[j][0] < CD[i][0]:
                if AB[j][1] < CD[i][1]:
                    ans += 1
                    AB[j][2] = False
                    CD[i][2] = False
                    break

print(ans)

Solution (Python):
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(key = lambda x: x[0])
ab_bool = [True]*n
cnt = 0
for i in range(n):
  for j in range(n):
    if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1] and ab_bool[j]:
      cnt += 1
      ab_bool[j] = False
      break
print(cnt)

Solution (Python):
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)]
red.sort(key=lambda x:x[0],reverse = True)
blue.sort(key=lambda x:x[1])
ans = 0
for i in range(n):
    flag = False
    for j in range(len(red)):
        if blue[i][1] > red[j][1] and blue[i][0] > red[j][0] and not flag:
            ans += 1
            red[j][0] = 100000
            flag = True
print(ans)

Solution (Python):
N = int(input())
R_dot, B_dot = [],[]
for _ in range(N):
    R_dot.append(list(map(int,input().split())) + [0])
for _ in range(N):
    B_dot.append(list(map(int,input().split())))

R_dot = sorted(R_dot, key = lambda x: x[1], reverse = True)
B_dot = sorted(B_dot, key = lambda x: x[0])

ans = 0
for i in range(N):
    for j in range(N):
        if R_dot[j][0] < B_dot[i][0] and R_dot[j][1] < B_dot[i][1] and R_dot[j][2] == 0:
            ans += 1
            R_dot[j][2] = 1
            break
            
print(ans)

Solution (Python):
n = int(input())
red = [list(map(int,input().split())) for _ in range(n)]
red.sort(key=lambda x:(x[1]))
blue = sorted(list(map(int,input().split())) for _ in range(n))
blue.sort(key=lambda x:(x[0],x[1]))
seen = [False]*n
for i in range(n):
    check = -1
    for j in range(n):
        if seen[j]:continue
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            check = j
    if check != -1:seen[check] = True
print(seen.count(True))

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()
blue.sort()

for c, d in blue:
    p = []
    dist = []
    for a, b in red:
        if a < c and b < d:
            p.append([a, b])
            dist.append(b)
        elif a >= c:
            break
    if p:
        red.remove(p[dist.index(max(dist))])

print(N - len(red))

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.sort(key=lambda x:(x[0],x[1]))
check = [False]*n
for i in range(n):
    a = -1
    c = -1
    for j in range(n):
        if check[j]:continue
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            if a < red[j][1]:
                a = red[j][1]
                c = j
    if c != -1:
        check[c] = True
print(check.count(True))

Solution (Python):
n = int(input())
a_b = []
for i in range(n):
    a_b.append(list(map(int, input().split())))
a_b.sort(key=lambda x: x[1], reverse=True)
c_d = []
for i in range(n):
    c_d.append(list(map(int, input().split())))
c_d = sorted(c_d)
ans = 0
for c, d in c_d:
    for a, b in a_b:
        if a < c and b < d:
            a_b.remove([a, b])
            ans += 1
            break
print(ans)

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

reds = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])

blues = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])

ans = 0
for bx, by in blues:
    for rx, ry in reds:
        if rx < bx and ry < by:
            ans += 1
            reds.remove((rx, ry))
            break
print(ans)

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

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

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

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):
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()
cd.sort()

pair = []
for i in range(N):
    max_y = -1
    pair_id = -1
    for j in range(N):
        if j not in pair and cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
            if max_y < ab[j][1]:
                max_y = ab[j][1]
                pair_id = j
    if pair_id != -1:
        pair.append(pair_id)

print(len(pair))

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

q = sorted(q)
p = sorted(p, key=lambda x:x[1], reverse=True)
res = 0
l = [0]*n
for i in range(n):
    for j in range(n):
        if q[i][0] > p[j][0] and q[i][1] > p[j][1]:
            if l[j] == 0:
                l[j] = 1
                res += 1
                break
            else:
                continue
        
        
print(res)