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
input = sys.stdin.readline

def main():
    N = int(input())
    ab = sorted([list(map(int, input().split())) for i in range(N)], reverse=True)
    cd = sorted([list(map(int, input().split())) for i in range(N)])

    check = [False] * N
    ans = 0
    for i in range(N):
        a, b = ab[i]
        min_ = int(1e5)
        ind = -1
        for i in range(N):
            if not check[i]:
                c, d = cd[i]
                if c > a and d > b:
                    if min_ > d:
                        min_ = d
                        ind = i
        if ind != -1:
            check[ind] = True
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

red = []
blue = []

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

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

ans = 0
for c, d in sorted(blue, key=lambda x: x[0]):
    candidate = sorted([x for x in red if x[0] < c and x[1] < d and x[2]], key=lambda x: -x[1])
    if candidate:
        candidate[0][2] = False
        ans += 1

print(ans)

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

red_coordinate.sort(reverse = True) 
blue_coordinate.sort() 
ans = 0

for i in range(n): 
    for j in range(n): 
        find = False
        if blue_coordinate[i][0] > red_coordinate[j][1] \
            and blue_coordinate[i][1] > red_coordinate[j][0]:
            ans = ans + 1
            red_coordinate[j][0] = float('inf')
            red_coordinate[j][1] = float('inf')
            find = True
        
        if find:
            break

print(ans)

Solution (Python):
import sys
import math
from fractions import gcd





def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""














N =  int(sys.stdin.readline())
A =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
B =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

A.sort()
B.sort()

cnt = 0
for b in range(N):
    idx = -1
    ty = -1
    for a in range(N):
        
        if A[a][0] < B[b][0] and A[a][1] < B[b][1]:
            if ty < A[a][1]:
                idx = a
                ty = A[a][1]
    
    if ty > -1:
        A[idx][0] = 10 ** 10
        A[idx][1] = 10 ** 10
        cnt += 1

print(cnt)

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)]
used = [False] * n
a.sort(key = lambda x: x[0], reverse = True)
b.sort(key = lambda x: x[0], reverse = True)
result = 0
for i in range(n):
  pj = -1
  miny = float('inf')
  for j in range(n):
    if used[j]:
      continue
    if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
      if b[j][1] < miny:
        pj = j
        miny = b[j][1]
  if pj != -1:
    used[pj] = True
    result += 1
print(result)

Solution (Python):
from operator import itemgetter
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()
b.sort()
ct=0
for i in range(n):
  x=b[i][0];y=b[i][1]
  L=[]
  for j in range(len(r)):
    if r[j][0]<x and r[j][1]<y:
      L.append(r[j])
    L=sorted(L,key=itemgetter(1))
  if len(L)>0:
    r.remove(L[len(L)-1])
    ct+=1
print(ct)

Solution (Python):
N = int(input())
r_stars = [tuple(map(int, input().split())) for _ in range(N)]
b_stars = [tuple(map(int, input().split())) for _ in range(N)]

r_stars.sort()
b_stars.sort()
cnt = 0
r_paired = {}
for bs in b_stars:
  rx = ry = -1
  for rs in r_stars:
    if rs[0] < bs[0] and rs[1] < bs[1] and not rs in r_paired:
      if ry < rs[1]:
        rx, ry = rs[0], rs[1]
  if rx != -1:
    cnt += 1
    r_paired[(rx, ry)] = 1
print(cnt)

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

for blue in blues:
    possible_x = 0
    possible_y = 0
    possible_i = float('inf')
    for i in range(len(reds)):
        if blue[0] >= reds[i][0] and blue[1] >= reds[i][1] and used[i] == 0:
            if possible_y <= reds[i][1]:
                possible_x = reds[i][0]
                possible_y = reds[i][1]
                possible_i = i
    if possible_i != float('inf'):
        used[possible_i] = 1
    
print(sum(used))

Solution (Python):


import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ab = [LI() for _ in range(n)]
cd = [LI() for _ in range(n)]
ab.sort(key = itemgetter(0))
cd.sort(key = itemgetter(0))
ans = 0
for i in range(n):
    lst = []
    x,y = cd[i]
    for j in range(len(ab)):
        a,b = ab[j]
        if a <= x and b <= y:
            lst.append([a,b])
    if len(lst) == 0:
        continue
    lst.sort(key = itemgetter(1),reverse = True)
    ab.remove(lst[0])
    ans += 1
print(ans)

Solution (Python):
inf = float('inf')
N = int(input())
A = []
B = []
for _ in range(N):
    A.append(tuple(map(int, input().split())))
for _ in range(N):
    B.append(tuple(map(int, input().split())))
B.sort(key=lambda t: t[0])

count = 0
for i in range(N):
    x, y = B[i]
    max_y = -1
    idx = -1
    for j in range(len(A)):
        tx, ty = A[j]
        if x > tx and y > ty:
            if max_y < ty:
                max_y = ty
                idx = j
    if idx >= 0:
        A.pop(idx)
        count += 1
print(count)

Solution (Python):
from collections import deque

class Dinic:
    def __init__(self, v, inf=10**9+7):
        self.V = v
        self.inf = inf
        self.G = [list() for _ in range(v)]
        self.level = [-1 for _ in range(v)]
        self.iter = [0]*v

    def addedge(self,fr,to,cap):
        """
        G[fr] = [to, cap, rev]
        """
        go = [to, cap, None]
        go[2] = back = [fr, 0, go]
        self.G[fr].append(go)
        self.G[to].append(back)

    def bfs(self,st,en):
        q = deque([st])
        self.level = [-1 for _ in range(self.V)]
        self.level[st] = 0
        while q:
            cur = q.popleft()
            for x,cap,_ in self.G[cur]:
                if cap and self.level[x]<0:
                    self.level[x] = self.level[cur] + 1
                    q.append(x)
        return self.level[en] > 0

    def dfs(self,v,t,f):
        if v == t:
            return f
        for e in self.iter[v]:
            w,cap,rev = e
            if cap and self.level[v]<self.level[w]:
                d = self.dfs(w,t,min(f,cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self,s,t):
        flow = 0
        while self.bfs(s,t):
            self.iter = list(map(iter, self.G))
            f = self.dfs(s,t,self.inf)
            while f:
                flow += f
                f = self.dfs(s,t,self.inf)
        return flow
n = int(input())
dinic = Dinic(n*2+2)
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(n):
  dinic.addedge(0,1+i,1)
  dinic.addedge(n+1+i,2*n+1,1)
for i in range(n):
  for j in range(n):
    if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
      dinic.addedge(1+i,n+1+j,1)
print(dinic.flow(0,2*n+1))

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)]
blue = sorted(blue)

INF = 1000000000
min_dif = INF
min_index = -1
pair = 0

while len(blue):
    min_dif = INF
    min_index = -1
    for i in range(len(red)):
        if blue[0][0] > red[i][0] and blue[0][1] > red[i][1]:
            dif = blue[0][1] - red[i][1]
            if dif < min_dif:
                min_dif = dif
                min_index = i
    blue.pop(0)
    if min_index != -1:
        red.pop(min_index)
        pair += 1


print(pair)

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

cnt = 0
for i in range(N):
	temp_y = -1
	temp_ind = -1
	for j in range(len(R)):
		if R[j][0] < B[i][0] and R[j][1] < B[i][1] and R[j][1] > temp_y:
			temp_y = R[j][1]
			temp_ind = j
	if temp_ind != -1:
		cnt += 1
		R.pop(temp_ind)
print(cnt)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
a,b = Line(N)
c,d = Line(N)

x = []
for i in range(N):
    x.append([a[i],b[i],0])
    x.append([c[i],d[i],1])

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

use = {}
for i in range(2*N):
    use[i] = False

ans = 0
for i in range(2*N)[::-1]:
    if x[i][2] != 0:
        continue
    else:
        index = 2*N
        val = float('inf')
        for j in range(i+1,2*N):
            if x[j][1]>x[i][1] and x[j][1]<val and use[j]!=True and x[j][2]==1:
                index = j
                val = x[j][1]
        if index != 2*N:
            ans += 1
            use[index] = True

print(ans)

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

Solution (Python):
from operator import itemgetter

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=itemgetter(1), reverse=True)
ab.sort(key=itemgetter(0), reverse=True)
cd.sort(key=itemgetter(0), reverse=False)
cd.sort(key=itemgetter(1), reverse=False)

reserved = [0 for _ in range(N)]
for a, b in ab:
    for i, (c, d) in enumerate(cd):
        if reserved[i] :
            continue
        if a<c and b<d :
            reserved[i] = 1
            break
print(sum(reserved))

Solution (Python):
n = int(input())
rd = []
bl = []
for _ in range(n):
    a, b = map(int,input().split())
    rd.append([a,b])
for _ in range(n):
    c, d = map(int,input().split())
    bl.append([c,d])
bl.sort()
used_r = [0] * n
ans = 0

for i in range(n):
    y = -1
    pair = -1
    for j in range(n):
        if rd[j][0] < bl[i][0] and rd[j][1] < bl[i][1] and rd[j][1] > y and used_r[j] == 0:
            y = rd[j][1]
            pair = j
    if pair != -1:
        used_r[pair] = 1
        ans += 1
print(ans)

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)]
a1 = sorted(a, key = lambda x:x[0])
b1 = sorted(b, key = lambda x:x[0])

inum = []
for j in range(n):
    bench = []
    for i in range(n):
        if a1[i] not in inum:
            if a1[i][0]< b1[j][0] and a1[i][1]< b1[j][1]:
                bench.append(a1[i])
    if bench:
        inum.append(max(bench, key=lambda x:x[1]))
print(len(inum))

Solution (Python):
N = int(input())
red_ps  = []
blue_ps = []
for i in range(N):
    red_ps.append(list((map(int,input().split()))))
for i in range(N):
    blue_ps.append(list((map(int,input().split()))))
    
red_ps.sort(key = lambda p: p[0], reverse = True)
blue_ps.sort(key = lambda p: p[1], reverse = False)

count = 0

for blue_p in blue_ps:
    for i,red_p in enumerate(red_ps):
        if red_p[0] < blue_p[0] and red_p[1] < blue_p[1]:
            count += 1
            red_ps.pop(i)
            break

print(count)

Solution (Python):
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        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)
        return level[t] is not None

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

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

n = int(input())
ab = []
cd = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([i+1, a, b])

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

s = 0
g = 2 * n + 1
edge = []
for i in range(1, n + 1):
    edge.append([0, i])
for i in range(n + 1, g):
    edge.append([i, g])


for i in range(len(ab)):
    i_idx, a, b = ab[i]
    for j in range(len(cd)):
        j_idx, c, d = cd[j]
        if a < c and b < d:
            edge.append([i_idx, j_idx])

try:
    dinic = Dinic(len(edge))

    for i in range(len(edge)):
        dinic.add_edge(edge[i][0], edge[i][1], 1)
    ans = dinic.flow(s, g)

    print(ans)
except:
    print(0)

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

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

ab.sort()
cd.sort()
num = 0
for i in range(N):
	blue = cd[i]
	red_y_max = -1
	index = -1
	for j in range(N):
		if ab[j][0] > blue[0]:
			break
		if ab[j][1] > red_y_max and ab[j][1] < blue[1]:
			red_y_max = ab[j][1]
			index = j
	if index != -1:
		ab[index][1] = 100000000000
		num += 1
print(num)

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

Solution (Python):
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    AB = sorted([LIST() for _ in range(N)], key=(lambda x: -x[1]))
    CD = sorted([LIST() for _ in range(N)])

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

    print(cnt)


if __name__ == '__main__':
    main()

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

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

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

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

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

    for i in range(N):
        c, d, f = CD[i]
        if f: continue
        if c <= a and d <= b: break
        if c <= a or d <= b: continue
        if min_val > d:
            min_val = d
            min_idx = i
    if min_idx >= 0:
        ans += 1
        CD[min_idx][2] = 1
        
print(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],x[0]),reverse=True)
cd.sort()

ans=0
for i in range(len(cd)):
  for j in range(len(ab)):
    c,d=cd[i]
    a,b=ab[j]
    if int(a)<int(c) and int(b)<int(d):
      ans+=1
      ab.pop(j)
      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)]

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

count = 0
for c, d in CD:
    for j, (a, b) in enumerate(AB):
        if a < c and b < d:
            count += 1
            AB.pop(j)
            break

print(count)

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



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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
B = [0] * N

for i in range(N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    A[i] = (a, b)

for j in range(N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    B[j] = (a, b)

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

ans = 0
for k in B:
    flag = False
    val = 0
    max_v = 0
    for l in A:
        if l[0] < k[0] and l[1] < k[1]:
            if max_v <= l[1]:
                flag = True
                max_v = l[1]
                val = l
    if flag:
        ans += 1
        A.remove(val)
print(ans)

Solution (Python):
N = int(input())
A = [0] * N
d = [0] * N 
B = [0] * N
for i in range(N):
    A[i] = list(map(int, input().split()))
    d[i] = A[i][1]
for i in range(N):
    B[i] = list(map(int, input().split()))

B.sort()

tmp = []

for i in range(N):
    t = -10
    for j in range(N):
        if A[j][0] < B[i][0] and A[j][1] < B[i][1] and j not in tmp:
            t = max(t, A[j][1]) 
    if t > -1 :
        tmp.append(d.index(t))
    

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

Solution (Python):
from operator import itemgetter
N = int(input())
A = [tuple(map(int,input().split())) for i in range(N)]
B = [tuple(map(int,input().split())) for i in range(N)]
A.sort()
B.sort()
num = 0
for i in range(N):
    K = [A[k] for k in range(len(A)) if (A[k][0] <B[i][0]) and (A[k][1] < B[i][1])]
    if K:
        num += 1
        t = sorted(K, key=itemgetter(1))[-1]
        A.remove(t)
print(num)

Solution (Python):
from operator import itemgetter

def main():
    N = int(input())
    
    red = [[int(i) for i in input().split()] for i in range(N)]
    blue = [[int(i) for i in input().split()] for i in range(N)]

    
    
    sort_red = sorted(red, key=itemgetter(1), reverse=True)
    sort_blue = sorted(blue, key=itemgetter(0))

    cnt = 0
    for b in sort_blue:
        for r in sort_red:
            if r[0] < b[0] and r[1] < b[1]:
                cnt += 1
                sort_red.remove(r)
                break
    print(cnt)


main()

Solution (Python):
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

class MaxFlow:
    def __init__(self, node_count):
        self.node_count = node_count
        self.graph = [[] for _ in range(node_count)]

    def add_edge(self, u, v, cap):
        idx1 = len(self.graph[v])
        idx2 = len(self.graph[u])
        self.graph[u].append([v, cap, idx1])
        self.graph[v].append([u,   0, idx2])

    def dfs(self, u, t, f):
        if u == t:
            return f
        self.used[u] = True
        for i in range(len(self.graph[u])):
            v, cap, rev = self.graph[u][i]
            if self.used[v] == False and cap > 0:
                d = self.dfs(v, t, min(f, cap))
                if d:
                    self.graph[u][i][1] -= d
                    self.graph[v][rev][1] += d
                    return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.used = [False] * self.node_count
            f = self.dfs(s, t, 1 << 29)
            if not f:
                return flow
            flow += f



n = getint()
a = [getints() for _ in range(n)]
b = [getints() for _ in range(n)]

src = n + n
dst = src + 1
nv = dst + 1
mf = MaxFlow(nv)

for i in range(n):
    mf.add_edge(src, i, 1)
    mf.add_edge(i + n, dst, 1)

for i in range(n):
    for j in range(n):
        if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
            mf.add_edge(i, j + n, 1)

print (mf.max_flow(src, dst))

Solution (Python):
n = int(input())
r = [ list(map(int,input().split())) for i in range(n)]
b = [ list(map(int,input().split())) for i in range(n)]
b.sort()
ans = 0
for i in range(n):
    Bx = b[i][0]
    By = b[i][1]
    tmp = []
    for j in range(len(r)):
        if r[j][0] <= Bx and r[j][1] <= By:
            dis = (Bx - r[j][0])**2 + (By - r[j][1])**2
            tmp.append([r[j][1],[r[j][0],r[j][1]]])
    if len(tmp) == 0:
        continue
    else:
        tmp.sort(reverse=True)
        ans += 1
        r.remove(tmp[0][1])
print(ans)

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

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

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())
red = []
blue = []
for i in range(n):
    x,y =map(int,input().split())
    red.append([x,y])
for i in range(n):
    x,y =map(int,input().split())
    blue.append([x,y])

ans=0
for i in range(2*n):
    now = 2*n -1 -i
    for redpoint in red:
        if redpoint[0] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[1]:
                        value =bluepoint[1]
                        add =bluepoint
            if add:
                blue.remove(add)
                red.remove(redpoint)
                ans +=1
            if redpoint[0]==redpoint[1] and add:
                break
        if redpoint[1] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[0]:
                        value =bluepoint[0]
                        add =bluepoint
            if add:
                blue.remove(add)
                red.remove(redpoint)
                ans +=1
                        
print(ans)

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

a.sort()
b.sort()
res = 0
used = [False for i in range(n)]
for i in range(n):
  ind = -1
  cur = b[i]
  best = -1
  for j in range(n):
    if not used[j] and a[j][0] < cur[0] and a[j][1] < cur[1] and best < a[j][1]:
      ind = j
      best = max(best, a[j][1])
  if ind != -1:
    res+=1
    used[ind] = True

print(res)

Solution (Python):

n = int(input())
a = []
b = []
for i in range(n):
  a.append(list(map(int,input().split())) + [i])
for i in range(n):
  b.append(list(map(int,input().split())) + [i])
b.sort()
ans = 0
for bi in range(n):
  bnow = b[bi]
  acan = []
  for ai in range(n):
    anow = a[ai]
    if anow[0] < bnow[0] and anow[1] < bnow[1]:
      acan.append(anow)
  try:
    ause = max(acan, key = lambda x: x[1])
    a[ause[2]] = [1000,1000,'used']
    ans += 1
  except:
    pass
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=1,
    )
    B = sorted([tuple(map(int, input().split())) for _ in range(N)])
    ans, memo = 0, set()
    for bx, by in B:
        for i, (ax, ay) in enumerate(A):
            if i not in memo and ax < bx and ay < by:
                ans += 1
                memo |= {i}
                break
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
R = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x: x[1],reverse = True)
B = sorted([list(map(int,input().split())) for i in range(N)])
count = 0
l = []
for i in range(N):
    Bx = B[i][0]
    By = B[i][1]
    for j in range(N):
        if Bx > R[j][0] and By > R[j][1] and R[j][0] not in l:
            count += 1
            l.append(R[j][0])
            break
print(count)

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

red = [0] * N
blue = [0] * N

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

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

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

ans = 0



for bp in blue:
    
    rem = None
    
    if len(red) > 0:
        cand = None
        for rp in red:
            if bp[0] > rp[0] and bp[1] > rp[1]:
                if cand is None:
                    cand = rp
                else:
                    if cand[1] < rp[1]:
                        cand = rp

        
        ans += 1 if cand is not None else 0
        rem = cand
        

    if rem is not None:
        red.remove(rem)

print(ans)

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

red = []
blue = []


for i in range(n):
    l = list(map(int,input().split()))
    red.append(l)
for i in range(n):
    l = list(map(int,input().split()))
    blue.append(l)

done = []

blue.sort()
for i in range(n):
    bag = []
    cnt = 0
    x = blue[i][0]
    y = blue[i][1]
    for j in range(n):
        if (x > red[j][0]) and (y > red[j][1]):
            if red[j] not in done:
                bag.append(red[j])
                cnt += 1
    bag.sort(key = lambda x:x[1])
    if cnt != 0:
        done.append(bag[cnt-1])

print(len(done))

Solution (Python):

import sys, math, fractions, itertools


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    R = list(reversed(sorted(zip(a, b), key=lambda x: x[1])))
    B = sorted(zip(c, d), key=lambda x: x[0])
    P = [0] * N
    counter = 0
    for b in B:
        for i, (a, p) in enumerate(zip(R, P)):
            if p == 0 and a[0] < b[0] and a[1] < b[1]:
                P[i] = 1
                counter += 1
                break
    print(counter)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int()] * (N)  
    b = [int()] * (N)  
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (N)  
    d = [int()] * (N)  
    for i in range(N):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, a, b, c, d)

if __name__ == '__main__':
    main()