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):
from copy import copy

N = int(input())

XtoBR = {}
YtoBR = {}
Rnumber = {}
for i in range(N):
    a, b = map(int, input().split())

    Rnumber[i] = (a, b)
    XtoBR[a] = ("R", i)
    YtoBR[b] = ("R", i)

Bnumber = {}
for i in range(N):
    a, b = map(int, input().split())

    Bnumber[i] = (a, b)
    XtoBR[a] = ("B", i)
    YtoBR[b] = ("B", i)

X_list = sorted(list(XtoBR.keys()))

ClearX = {}
clear = set()

ans = 0
for x in reversed(X_list):
    if(XtoBR[x][0] == "B"):
        clear.add(XtoBR[x][1])
    else:
        ClearX[XtoBR[x][1]] = copy(clear)

Y_list = sorted(list(YtoBR.keys()))

clear = set()
for y in reversed(Y_list):
    if(YtoBR[y][0] == "B"):
        clear.add(YtoBR[y][1])
        continue

    n = YtoBR[y][1]
    allclear = clear & ClearX[n]
    
    if(len(allclear) == 0):
        continue

    tmp_x = 2 * N + 1
    tmp = 0
    
    for i in allclear:
        if(Bnumber[i][0] < tmp_x):
            tmp = i
            tmp_x = Bnumber[i][0]

    ans += 1
    clear.remove(tmp)

print(ans)

Solution (Python):
n=int(input())
a={tuple(map(int,input().split())):False for _ in range(n)}
b=sorted([tuple(map(int,input().split())) for _ in range(n)])

ak=sorted(a.keys(),key=lambda x:x[1])[::-1]

for i in b:
  for j in ak:
    if i[0]<j[0] or i[1]<j[1] or a[j]:continue
    else:
      a[j]=True
      break

print(sum(a.values()))

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]


ans = 0
used = [False] * n
A.sort(key=lambda x:x[1], reverse=True)
C.sort()

for c, d in C:
    i = 0
    while i < n and (used[i] or A[i][0] >= c or A[i][1] >= d):
        i += 1
    if i >= n:
        continue
    ans += 1
    used[i] = True

print(ans)

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]


ans = []

for bits in range(1, 2**4):
    cnt = 0
    used = [False] * n
    A.sort(key=lambda x:x[bits & 1], reverse=bits >> 1 & 1)
    C.sort(key=lambda x:x[bits >> 2 & 1], reverse=bits >> 3 & 1)

    for a, b in A:
        i = 0
        while i < n and (used[i] or a >= C[i][0] or b >= C[i][1]):
            i += 1
        if i >= n:
            continue
        cnt += 1
        used[i] = True
        i += 1
        

    ans.append(cnt)

print(max(ans))

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]
C = [[int(i) for i in input().split()] for j in range(n)]


ans = []

for bits in range(1, 2**4):
    cnt = 0
    used = [False] * n
    A.sort(key=lambda x:x[bits & 1], reverse=bits >> 1 & 1)
    C.sort(key=lambda x:x[bits >> 2 & 1], reverse=bits >> 3 & 1)

    for c, d in C:
        i = 0
        while i < n and (used[i] or A[i][0] >= c or A[i][1] >= d):
            i += 1
        if i >= n:
            continue
        cnt += 1
        used[i] = True

    ans.append(cnt)

print(max(ans))

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


class Dinic:
    def __init__(self, v, inf=sys.maxsize):
        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)


@mt
def slv(N, AB, CD):
    cd_ = [(i+1, x, y) for i, (x, y) in enumerate(CD)]
    cd_x = sorted(cd_, key=lambda x: x[1])
    cd_x_keys = [x[1] for x in cd_x]
    cd_y = sorted(cd_, key=lambda x: x[2])
    cd_y_keys = [y[2] for y in cd_y]

    d = Dinic(2*N+2)
    for i in range(1, N+1):
        d.add_edge(0, i, 1)
        d.add_edge(i+N, 2*N+1, 1)
    for i, (x, y) in enumerate(AB):
        ix = bisect.bisect_left(cd_x_keys, x)
        iy = bisect.bisect_left(cd_y_keys, y)
        e = set([j for j, x, y in cd_x[ix:]]) & set(
            [j for j, x, y in cd_y[iy:]])
        for j in e:
            d.add_edge(i+1, j+N, 1)

    return d.max_flow(0, 2*N+1)


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    CD = [read_int_n() for _ in range(N)]

    print(slv(N, AB, CD))


if __name__ == '__main__':
    main()

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


class Dinic:
    def __init__(self, v, inf=sys.maxsize):
        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)


@mt
def slv(N, AB, CD):
    cd_ = [(i+1, x, y) for i, (x, y) in enumerate(CD)]
    cd_x = sorted(cd_, key=lambda x: x[1])
    cd_x_keys = [x[1] for x in cd_x]
    cd_y = sorted(cd_, key=lambda x: x[2])
    cd_y_keys = [y[2] for y in cd_y]

    d = Dinic(2*N+2)
    for i in range(1, N+1):
        d.add_edge(0, i, 1)
        d.add_edge(i+N, 2*N+1, 1)
    for i, (x, y) in enumerate(AB):
        ix = bisect.bisect_left(cd_x_keys, x)
        iy = bisect.bisect_left(cd_y_keys, y)
        e = set([j for j, x, y in cd_x[ix:]]) & set(
            [j for j, x, y in cd_y[iy:]])
        for j in e:
            d.add_edge(i+1, j+N, 1)

    return d.max_flow(0, 2*N+1)


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    CD = [read_int_n() for _ in range(N)]

    print(slv(N, AB, CD))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = []
c = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    a.append([x1,y1])
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    c.append([x1,y1])
a = sorted(a,key=lambda x:-x[1])
c = sorted(c,key=lambda x:x[0])
ans = 0
for i in range(n):
  e = c[i]
  for j in range(len(a)):
    if (e[0] > a[j][0] and e[1] > a[j][1]):
      a.pop(j)
      ans += 1
      break
print(ans)

Solution (Python):
N = int(input())
rn = [[True]+list(map(int,input().split())) for _ in range(N)]
bn = sorted([list(map(int,input().split())) for _ in range(N)])
rn.sort(key=lambda x: -x[2])
for bp in bn:
  bx,by = bp
  for rp in rn:
    f,rx,ry = rp
    if f and rx<bx and ry<by:
      rp[0] = False
      break
print(sum([0 if rp[0] else 1 for rp in rn]))

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

red = []

for i in range(n):
	red.append(map(int,raw_input().split()))

blue = []

for i in range(n):
	blue.append(map(int,raw_input().split()))


redflug = []
for i in range(n):
	redflug.append(0)

blue.sort()

ans = 0
for i in range(n):
	t = -1
	maxy = -1
	for j in range(n):
		if redflug[j] == 0 and blue[i][0] > red[j][0] and blue[i][1] > red[j][1] and red[j][1] > maxy :
			t = j
			maxy = red[j][1]

	if t != -1 :
		redflug[t] = 1
		ans += 1

print ans

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)]
R.sort(key = lambda x:x[1], reverse=True)
B.sort(key = lambda x:x[0], reverse=False)
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 = [tuple(int(x) for x in input().split()) for _ in range(n)]
blue = [tuple(int(x) for x in input().split()) for _ in range(n)]

red = sorted(red)
blue = sorted(blue)

ans = 0
for x, y in blue:
    if x == 0:
        continue
    else:
        temp = [-1, -1]
        for a, b in red:
            if a > x:
                break
            elif y > b > temp[1]:
                temp = [a, b]
        if temp[1] >= 0:
            ans += 1
            red.remove((temp[0], temp[1]))

print(ans)

Solution (Python):
from sys import setrecursionlimit
setrecursionlimit(10**7)
N=int(input())

table=[[0]*(2*N+2) for i in range(2*N+2)]
for i in range(1,N+1):
    table[0][i]=1
    table[i+N][2*N+1]=1    
red=[]
blue=[]
for i in range(1,N+1):
    a,b=map(int,input().split())
    red.append((i,a,b))
for i in range(1,N+1):
    a,b=map(int,input().split())
    blue.append((i,a,b))
for i,a,b in red:
    for j,x,y in blue:
        if a<x and b<y:
            table[i][N+j]=1
def fk(x):
    visit[x]=True
    if x==2*N+1:
        return True
    for i in range(2*N+2):
        if (not visit[i]) and table[x][i]>0:
            if fk(i):
                table[x][i]-=1
                table[i][x]+=1
                return True
    return False

ans=0
while True:
    visit=[False]*(2*N+2)
    if fk(0):
        ans+=1
    else:
        break

print(ans)

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

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])
blue.sort(key=lambda x:x[0])
ct=0
for i in blue:
    for j in reversed(red):
        if i[0]>j[0] and i[1]>j[1]:
            red.remove(j)

            ct+=1
            break
print(ct)

Solution (Python):
from collections import deque


class Dinic:
  def __init__(self, n):
    self.n = n
    self.links = [[] for _ in range(n)]
    self.depth = None
    self.progress = None
 
  def add_link(self, _from, to, cap):
    self.links[_from].append([cap, to, len(self.links[to])])
    self.links[to].append([0, _from, len(self.links[_from]) - 1])
 
  def bfs(self, s):
    depth = [-1] * self.n
    depth[s] = 0
    q = deque([s])
    while q:
      v = q.popleft()
      for cap, to, rev in self.links[v]:
        if cap > 0 and depth[to] < 0:
          depth[to] = depth[v] + 1
          q.append(to)
    self.depth = depth
 
  def dfs(self, v, t, flow):
    if v == t:
      return flow
    links_v = self.links[v]
    for i in range(self.progress[v], len(links_v)):
      self.progress[v] = i
      cap, to, rev = link = links_v[i]
      if cap == 0 or self.depth[v] >= self.depth[to]:
        continue
      d = self.dfs(to, t, min(flow, cap))
      if d == 0:
        continue
      link[0] -= d
      self.links[to][rev][0] += d
      return d
    return 0
 
  def max_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, float('inf'))
      while current_flow > 0:
        flow += current_flow
        current_flow = self.dfs(s, t, float('inf'))


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):
  a,b=map(int,input().split())
  blue.append([a,b])



mf=Dinic(2*N+2)
for i in range(1,N+1):
  mf.add_link(0, i, 1)
for i in range(N+1,2*N+1):
  mf.add_link(i, 2*N+1, 1)


for i in range(N):
  for j in range(N):
    a,b=red[i]
    c,d=blue[j]
    if a<c and b<d:
      mf.add_link(i+1, N+1+j, 1)
      
print(mf.max_flow(0, 2*N+1))

Solution (Python):
N=input()
A=[ map(int, raw_input().split())  for i in range(N) ]
C=[ map(int, raw_input().split())  for i in range(N) ]

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

V=[0 for i in range(N+1)]

ans=0

for bx,by in C:
	for i,u  in enumerate(A):
		rx=u[0]
		ry=u[1]
		if bx>rx and by>ry and V[i]==0:
			ans+=1
			V[i]=1
			break

print ans

Solution (Python):
n = int(input())
a = []
c = []

for i in range(n):
    a.append([int(i) for i in input().split()])
for i in range(n):
    c.append([int(i) for i in input().split()])

a.sort(key=lambda x:x[1], reverse=True)
c = sorted(c)

count = 0
for i, (tc, td) in enumerate(c):
    for j, (ta, tb) in enumerate(a):
        if ta < tc and tb < td:
            count += 1
            a.pop(j)
            break

print(count)

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


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

print(ans)

Solution (Python):
N = int(input())
src = [tuple(map(int,input().split())) for i in range(2*N)]
es = [[] for i in range(2*N)]
for i,(x1,y1) in enumerate(src[:N]):
    for j,(x2,y2) in enumerate(src[N:]):
        if x1 < x2 and y1 < y2:
            es[i].append(j+N)
            es[j+N].append(i)

used = [False] * (2*N)
match = [-1] * (2*N)

def _dfs(v):
    global used, match
    used[v] = True
    for u in es[v]:
        w = match[u]
        if w < 0 or not used[w] and _dfs(w):
            match[v] = u
            match[u] = v
            return True
    return False

def bipartite_matching():
    global used, match
    ret = 0
    for v in range(2*N):
        if match[v] < 0:
            used = [False] * (2*N)
            if _dfs(v):
                ret += 1
    return ret

print(bipartite_matching())

Solution (Python):
n = int(input())
list_red = [list(map(int, input().split())) for i in range(n)]
list_blue = [list(map(int, input().split())) for i in range(n)]
list_red.sort(key = lambda x:x[1], reverse = True)
list_blue = sorted(list_blue)
ans = 0

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

Solution (Python):
N = int(input())
red_points  = sorted([list(map(int, input().split())) for i in range(N)], key = lambda x: (-x[1], -x[0]))
blue_points = sorted([list(map(int, input().split())) for i in range(N)], key = lambda x: (x[0], x[1]))
for blue_point in blue_points:
    blue_point.append(False)

ans = 0
for red_point in red_points:
    for blue_point in blue_points:
        if red_point[0] < blue_point[0] and red_point[1] < blue_point[1] and not blue_point[2]:
            ans += 1
            blue_point[2] = True
            break
print(ans)

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

red_coodinates.sort(key=lambda x:-x[1])
blue_coodinates.sort()
number_of_pairs=0

for i in range(N):
    for j in range(0,len(red_coodinates)):
        if red_coodinates[j][0]<blue_coodinates[i][0] and red_coodinates[j][1]<blue_coodinates[i][1]:
            number_of_pairs+=1
            red_coodinates.remove(red_coodinates[j])
            break
        else:
            pass

print(number_of_pairs)

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)]
a = [0] * N
for x,y in sorted(blue,key=lambda x: x[0]):
    k = []
    for i,[x2,y2] in enumerate(red):
        if x2 < x and y2 < y and not a[i]:
            k.append((x2,y2,i))
    if len(k):
        x,y,i=sorted(k,key=lambda x:-1*x[1])[0]
        a[i] = 1
print(sum(a))

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

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

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

ans = 0

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

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

ans = 0

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

print(ans)

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)]
ans = 0
red = sorted(red, key = lambda x:  x[1]*(-1))
blue = sorted(blue)

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

Solution (Python):
n = int(input())
s, t = [], []
for i in range(n):
  a, b = list(map(int, input().split()))
  s.append((a, b))
for i in range(n):
  c, d = list(map(int, input().split()))
  t.append((c, d))
s.sort(key=lambda x:x[1])
t.sort()

ans = 0
for i in range(n):
  for j in range(n-1, -1, -1):
    if s[j]==None:
      continue
    if s[j][0]<t[i][0] and s[j][1]<t[i][1]:
      ans+=1
      s[j] = None
      break
print(ans)

Solution (Python):
N=int(input())
import bisect
w=0
r=[]
b=[]
for i in range(N):
    x,y=map(int,input().split())
    r.append((x,y))
for i in range(N):
    x,y=map(int,input().split())
    b.append((x,y))
b.sort()
r.sort()   
for i,j in b:
    u=[]
    for k in range(len(r)):
        if i>r[k][0] and j>r[k][1]:
            u.append((r[k][1],r[k][0]))
    if u:        
        u.sort()   
        (p,q)=u[-1]
        r.remove((q,p))
        w+=1
print(w)

Solution (Python):



def search_bluedot(end_x, end_y):
	
	global ans
	global field
	
	for y in range(end_y-1, -1, -1):
		for x in range(end_x):
			
			if field[y][x] == 1:
				ans += 1
				field[y][x] = 0
				return

dot_count = int(input())

field = [[0 for i in range(dot_count*2)] for j in range(dot_count*2)]

for i in range(dot_count):
	x, y = map(int, input().split())
	field[y][x] = 1

for i in range(dot_count):
	x, y = map(int, input().split())
	field[y][x] = 2

ans = 0
for x in range(dot_count*2):
	
	for y in range(dot_count*2):
		
		if field[y][x] == 2:
			search_bluedot(x, y)

print(ans)

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

ab=[]
cd=[]

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

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

ab.sort()
cd.sort()




ans=0

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


print(ans)

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)]
ans = 0
red = sorted(red, key = lambda x:x[1] * -1)
blue = sorted(blue)
for b in blue:
	for r in red:
		if b[0] > r[0] and b[1] > r[1]:
			ans += 1
			red.remove(r)
			break
print(ans)

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)]
ans = 0
red = sorted(red, key = lambda x: -1 * x[1])
blue = sorted(blue)
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			red.remove(r)
			break
print(ans)

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)]
ans = 0
red = sorted(red, key = lambda x: -1 * x[1])
blue = sorted(blue)
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			red.remove(r)
			break
print(ans)

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(0),reverse=True)
ab.sort(key=itemgetter(1),reverse=True)
cd.sort(key=itemgetter(1))
cd.sort(key=itemgetter(0))
count = 0
for c,d in cd[:]:
    for a,b in ab:
        if a < c and b < d:
            count += 1
            ab.remove([a,b])
            cd.remove([c,d])
            break
print(count)

Solution (Python):
N=int(input())
r=[(0,0) for i in range(N)]
b=[(0,0) for i in range(N)]

for i in range(N):
    x,y=map(int,input().split())
    r[i]=(x,y)
for i in range(N):
    x,y=map(int,input().split())
    b[i]=(x,y)
b.sort()
ru=[0 for i in range(N)]
ans=0
for i in range(N):
    k=-1
    for j in range(N):
        if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
            if k==-1 and ru[j]==0:
                k=j
            elif r[k][1]<r[j][1] and ru[j]==0:
                k=j
    if k!=-1:
        ru[k]=1
        ans+=1
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.sort(key=lambda x: (x[1], x[0]), reverse=True)
blue.sort(key=lambda x: (x[0], x[1]))

cnt = 0
for i in range(len(blue)):
    for j in range(len(red)):
        if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            cnt += 1
            del red[j]
            break
print(cnt)

Solution (Python):
N=int(input())
reds = set()
blues = []
for i in range(N):
    x,y=map(int,input().split())
    reds.add((x,y))
for i in range(N):
    x,y=map(int,input().split())
    blues.append((x,y))
blues.sort(key=lambda x: x[0])
ans = 0
for (bx,by) in blues:
    candidates = []
    for (rx,ry) in reds:
        if rx < bx and ry < by:
            candidates.append((rx,ry))
    if candidates:
        candidates.sort(key = lambda x: -x[1])
        ans += 1
        reds.remove(candidates[0])
    
print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())
reds = [tuple(int(x) for x in input().split())for _ in range(n)]
blues = [tuple(int(x) for x in input().split())for _ in range(n)]

blue_dict = defaultdict(list)
for c, d in blues:
    for a, b in reds:
        if a < c and b < d:
            blue_dict[c, d].append((a, b))
for val in blue_dict.values():
    val.sort(key=lambda x:-x[1])

red_dict = {}
for blue, red_list in sorted(blue_dict.items(), key=lambda x:x[0][0]):
    for red in red_list:
        if red in red_dict:
            continue
        red_dict[red] = blue
        break

print(len(red_dict))

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

RED=[None]*N

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

BLUE=[None]*N

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


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

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

score=0
for i in range(N-1,-1,-1):
    for j in range(len(BLUE)):
        if RED[i][0]<BLUE[j][0] and RED[i][1]<BLUE[j][1]:
            score+=1
            del(BLUE[j])
            break

print(score)