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

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

Rok = [True] * N

for i in range(N):
    for j in range(N):
        if Rok[j]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Rok[j] = False
                break
print(ans)

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

Aok = [True] * N

for i in range(N):
    for j in range(N):
        if Aok[j]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Aok[j] = False
                break
print(ans)

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

Aok = [True] * N
Bok = [True] * N

for i in range(N):
    for j in range(N):
        if Aok[j] and Bok[i]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Aok[j] = False
                Bok[i] = False
                break
print(ans)

Solution (Python):

import sys

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[1]) 
    blue.sort(key=lambda x: x[0]) 
    j_list = []
    for i in range(N):
        c,d =blue[i]

        for j in range(N):
            a,b = red[j]
            if j in j_list:
                continue

            if a<c and b<d:
                
                j_list.append(j)
                break
    print(len(j_list))

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

ans = 0
for b in blue:
    bx,by = b
    for i,r in enumerate(red):
        rx,ry = r
        if bx > rx and by > ry:
            ans += 1
            red.pop(i)
            break


print(ans)

Solution (Python):
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) != 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
       R.remove(s)
       pair += 1
           
print(pair)

Solution (Python):
def solve():
    N = int(input())
    ab = [[] for _ in range(N)]
    cd = ab[:]
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    for i in range(N):
        cd[i] = list(map(int, input().split()))
    
    ab.sort(key=lambda x: -x[0])
    cd.sort(key=lambda x: (x[0], -x[1]))
    
    ans = 0
    used = [0 for _ in range(N)]
    for i in range(N):
        use, d_min = -1, 201
        for j in range(N):
            if ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
                if cd[i][1] - ab[j][1] < d_min:
                    if used[j] == 0:
                        use = j
                        d_min = cd[i][1] - ab[j][1]
        if use != -1:
            used[use] = 1
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
from bisect import bisect_left as bi_l

n = int(sys.stdin.readline().rstrip())
I = list(zip(*[map(int, sys.stdin.read().split())] * 2))
red = I[:n]
blue = I[n:]

def main():
    red.sort(key=lambda x: x[0])
    blue.sort(key=lambda x: x[0])
    a = []
    b = []
    for x, y in red:
        a.append(x)
        b.append(y)
    
    paired = [False] * n
    cnt = 0
    for c, d in blue:
        pair = None
        res = -1
        for i in range(bi_l(a, c)):
            if not paired[i] and b[i] < d and b[i] > res:
                pair = i
                res = b[i]
        if not pair is None:
            paired[pair] = True
            cnt += 1
    
    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys

n = int(sys.stdin.readline().rstrip())
abcd = list(zip(*[map(int, sys.stdin.read().split())] * 2))
ab = abcd[:n]
cd = abcd[n:]

def main():
    abcd.sort(key=lambda x: x[0])
    blue = list(map(lambda x: x[1], abcd))
    ab.sort(key=lambda x: x[0], reverse=True)
    reversed_b_sorted_by_a = list(map(lambda x: x[1], ab))
    
    cnt = 0
    for b in reversed_b_sorted_by_a:
        i = blue.index(b)
        if i == len(blue) - 1:
            blue.remove(b)
            continue
        cand = [x for x in blue[i+1:] if x > b]
        if not cand:
            blue.remove(b)
            continue
        blue.remove(b)
        blue.remove(min(cand))
        cnt += 1

    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
n=int(input())
R=[list(map(int,input().split())) for _ in range(n)]
B=[list(map(int,input().split())) for _ in range(n)]
B.sort()
ans=0
for b in B:
    L = [ r for r in R if r[0]<b[0] and r[1]<b[1]]
    if len(L)!=0:
        s = L[0]
        for l in L:
            if s[1]<l[1]: s=l
        R.remove(s)
        ans += 1
print(ans)

Solution (Python):
n=int(input())
R=[list(map(int,input().split())) for _ in range(n)]
B=[list(map(int,input().split())) for _ in range(n)]
B.sort()
ans=0
for b in B:
    L = [ r for r in R if r[0]<b[0] and r[1]<b[1]]
    if len(L)!=0:
        s = L[0]
        for l in L:
            if s[1]<l[1]: s=l
        R.remove(s)
        ans += 1
print(ans)

Solution (Python):
import sys
import bisect
r = sys.stdin.readline
N = int(r())
red = []
blue = []
for i in range(N):
    a, b = list(map(int, r().split()))
    red.append([a, b])
for i in range(N):
    c, d = list(map(int, r().split()))
    blue.append([c, d])

xblue = sorted(blue, key=lambda x: x[0])

i = 0
j = 0
ii = [True for i in range(2*N+1)]
jj = [True for i in range(2*N+1)]
ans = 0
for i in range(N):
    m = [-100000, -100000]
    for j in range(N):
        if ii[i] and jj[j] and red[j][0] < xblue[i][0] and red[j][1] < xblue[i][1]:
            if m[0] < red[j][1]:
                m[0] = red[j][1]
                m[1] = j
    if m[0] != -100000 and m[1] != -100000:
        ii[i] = False
        jj[m[1]] = False
        ans += 1

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
red_points = [list(map(int,input().split())) for i in range(n)]
blue_points = [list(map(int,input().split())) for i in range(n)]

red_points.sort(key=lambda x:(x[1]*-1))
blue_points.sort()

blue_cursor = 0
pair_cnt = 0

for bx,by in blue_points:
    for i,(ax,ay) in enumerate(red_points):
        if ax < bx and ay < by:
            pair_cnt+=1
            red_points.pop(i)
            break

print(pair_cnt)

Solution (Python):
N = int(input())
red = [tuple([int(i) for i in input().split()]) for _ in range(N)]
blue = [tuple([int(i) for i in 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 i, r in enumerate(red):
        if b[0] > r[0] and b[1] > r[1]:
            ans += 1
            red.pop(i)
            break
print(ans)

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

Solution (Python):
n = int(input())
ba = []
cd = []
for i in range(n):
  a, b = map(int, input().split())
  ba.append([b, a])
for j in range(n):
  c, d = map(int, input().split())
  cd.append([c, d])
ba.sort(reverse = True)
cd.sort()
ans = 0
for c, d in cd:
  for i in range(n):
    b, a = ba[i]
    if a < c and b < d:
      ans += 1
      ba[i] = [201, 201]
      break
print(ans)

Solution (Python):
from scipy.sparse.csgraph import dijkstra

N = int(input())
NN = N * 2
XY = [[int(x) for x in input().split()] for _ in range(NN)]

graph = [[0] * (NN+2) for _ in range(NN+2)]
start = NN
goal = NN + 1

for i,(a,b) in enumerate(XY[:N]):
  for j,(c,d) in enumerate(XY[N:],N):
    if a < c and b < d:
      graph[i][j] = 1

for i in range(N):
  graph[start][i] = 1
for i in range(N,NN):
  graph[i][goal] = 1

INF = 10 ** 9

def max_flow(graph):
  dist,pred = dijkstra(graph,indices = start,return_predecessors = True)
  if dist[goal] > INF:
    return 0
  y = goal
  while y != start:
    x = pred[y]
    graph[x][y] -= 1
    graph[y][x] += 1
    y = x
  return 1 + max_flow(graph)

answer = max_flow(graph)
print(answer)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
cd=[list(map(int,input().split())) for i in range(n)]
usedab=[0]*n
usedcd=[0]*n
cd.sort();ab.sort(key=lambda tup:-tup[1])
for i,(c,d) in enumerate(cd):
    for j,(a,b) in enumerate(ab):
        if a<c and b<d and (not usedab[j]) and (not usedcd[i]):
            usedab[j]=1
            usedcd[i]=1
            count+=1
            
print(count)

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()
cnt = 0
for i in range(N):
    for j in range(N):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            red[i][0] = 0
            red[i][1] = 0
            blue[j][0] = 0
            blue[j][1] = 0
            cnt += 1
            break
print(cnt)

Solution (Python):
import numpy as np
N=int(input())
rp=np.array([list(map(int, input().split())) for i in range(N)])
bp=np.array([list(map(int, input().split())) for i in range(N)])
rp=rp[np.argsort(rp[:, 0])]
bp=bp[np.argsort(bp[:, 0])]
rp=np.c_[rp, np.arange(N).reshape(-1, 1)]
bp=np.c_[bp, np.arange(N).reshape(-1, 1)]

counter=0
for i in range(N):
  temp=rp[rp[:, 0]<bp[i, 0], :]
  if temp.shape[0]>0:
    temp=temp.reshape(-1, 3)
  if temp.shape[0]>0:
    temp=temp[temp[:, 2]!=-1, :]
    temp=temp.reshape(-1, 3)
  if temp.shape[0]>0:
    temp=temp[temp[:, 1]<bp[i, 1], :]
    temp=temp.reshape(-1, 3)
  if temp.shape[0]>1:
    temp=temp[np.argmax(temp[:, 1]), :]
    temp=temp.reshape(1, 3)
  if temp.shape[0]==1:
    counter+=1
    rp[temp[0, 2], 2]=-1
    
print(counter)

Solution (Python):
from collections import deque

N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
CD=[list(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x:x[1], reverse=True)
CD.sort()
CD=deque(CD)
cc=0

while len(CD)>0:
    p=CD.popleft()
    c,d=p[0],p[1]
    for i in range(len(AB)):
        if AB[i][0]<c and AB[i][1]<d:
            AB=AB[:i]+AB[i+1:]
            cc+=1
            break

print(cc)

Solution (Python):
from collections import deque

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

graph = [[] for _ in range(2*N+2)]

for i in range(N):
    forward = [2+i,1,None]
    forward[2] = backward = [0,0,forward]
    graph[0].append(forward)
    graph[2+i].append(backward)

for i in range(N):
    forward = [1,1,None]
    forward[2] = backward = [2+N+i,0,forward]
    graph[2+N+i].append(forward)
    graph[1].append(backward)

for i in range(N):
    for j in range(N):
        if R[i][0]<B[j][0] and R[i][1]<B[j][1]:
            forward = [2+N+j,1,None]
            forward[2] = backward = [2+i,0,forward]
            graph[2+i].append(forward)
            graph[2+N+j].append(backward)

flow = 0

while True:

    queue = deque([0])
    level = [None for _ in range(2*N+2)]
    level[0] = 0

    while queue:
        node = queue.popleft()
        for adj,adjcap,_ in graph[node]:
            if adjcap>0 and level[adj] is None:
                level[adj] = level[node]+1
                queue.append(adj)

    if level[1] is None:
        break

    stack = [0]
    visited = [0 for _ in range(2*N+2)]
    visited[0] = 1
    parent = [None for _ in range(2*N+2)]
    parent[0] = 0

    while stack:
        node = stack.pop()
        for adj,adjcap,adjrev in graph[node]:
            if not visited[adj] and adjcap>0 and level[node]<level[adj]:
                visited[adj] = 1
                parent[adj] = node
                stack.append(adj)

    if visited[1]:
        flow += 1
        present = 1
        prev = parent[present]
        while present != 0:
            for g in graph[prev]:
                adj,adjcap,adjrev = g
                if adj == present:
                    g[1] = 0
                    adjrev[1] = 1
            present = prev
            prev = parent[present]

print(flow)

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

answer = 0
for a,b in l1:
    for c,d in l2:
        if a < c and b < d:
            answer += 1
            l2.remove([c,d])
            break

print(answer)

Solution (Python):
n = int(input())
red = sorted([tuple(map(int, input().split())) for _ in range(n)])
blue = sorted([tuple(map(int, input().split())) for _ in range(n)])

res = 0
for bx, by in blue:
    tmp_max = -1
    tmp_cnt = None
    for i, (rx, ry) in enumerate(red):
        if bx <= rx:
            break
        if tmp_max <= ry < by:
            tmp_max = ry
            tmp_cnt = i
    if tmp_cnt is not None:
        res += 1
        red.pop(tmp_cnt)

print(res)

Solution (Python):
from operator import itemgetter
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=itemgetter(1), reverse=True)
blue.sort()
red_flag = [False] * n
for i in range(n):
    pair_red_index = float('inf')
    for j in range(n):
        if not (red_flag[j]) and red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            pair_red_index = j
            break
    if pair_red_index != float('inf'):
        red_flag[pair_red_index] = True
print(red_flag.count(True))

Solution (Python):
n = int(input())
reds = sorted((tuple(map(int, input().split())) for _ in range(n)), key=lambda tuple_: tuple_[1], reverse=True)
blues = sorted((tuple(map(int, input().split())) for _ in range(n)), key=lambda tuple_: tuple_[0])

pairs = 0
for blue in blues:
    for idx, red in enumerate(reds):
        if red[0] < blue[0] and red[1] < blue[1]:
            break
    else:
        continue
    del reds[idx]
    pairs += 1

print(pairs)

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

pairs = 0
for blue in blues:
    red_max_y = -float("inf")
    arg_max = -1
    for idx, red in enumerate(reds):
        if red[0] < blue[0] and red[1] < blue[1]:
            if red[1] > red_max_y:
                red_max_y = red[1]
                arg_max = idx
    if arg_max != -1:
        del reds[arg_max]
        pairs += 1

print(pairs)

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


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

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

reds.sort(key=lambda x: x[0], reverse=True)
blues.sort(key=lambda x: x[0])

res = 0
for r in reds:
    b_list = [b for b in blues if r[0] < b[0] and r[1] < b[1]]

    if len(b_list):
        b = min(b_list, key=lambda x: x[1])
        blues.remove(b)
        res += 1

print(res)

Solution (Python):
import sys
from itertools import combinations, product
n = int(input())
red_ls = []
blue_ls = []
for j in range(n):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    red_ls.append([1+j, a, b])
for j in range(n):
    c, d = [int(i) for i in sys.stdin.readline().split()]
    blue_ls.append([n+1+j, c, d])

graph = {i : [] for i in range(2*n+2)}
edge_ls = []
cnt = 0
for i in range(1, n+1):
    edge_ls.append([i, 1, None])
    graph[0].append(cnt)
    cnt += 1
for i in range(n+1, 2*n+1):
    edge_ls.append([2*n+1, 1, None])
    graph[i].append(cnt)
    cnt += 1

for (r_ind, r_x, r_y), (b_ind, b_x, b_y) in product(red_ls, blue_ls):
    if r_x < b_x and r_y < b_y:
        edge = [b_ind, 1, cnt+1]
        edge_rev = [r_ind, 0, cnt]
        graph[r_ind].append(cnt)
        graph[b_ind].append(cnt + 1)
        edge_ls += [edge, edge_rev]
        cnt += 2

def dfs(s, g, flow):
    if s==g:
        return flow
    used[s] = True
    for _next in graph[s]:
        t, c, rev = e = edge_ls[_next]
        if not used[t] and c > 0:
            flow = min(flow, c)
            d = dfs(t, g, flow)
            if d:
                edge_ls[_next][1] -= d
                if rev is not None:
                    edge_ls[rev][1] += d
                return d
    return 0


flow = 0
INF = 10**18
f = INF
while f:
    used = [0 for i in range(2*n+2)]
    f = dfs(0, 2*n+1, INF)
    flow += f
print(flow)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    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(lambda x:x[1],reverse=1)
    CD.sort()

    ans=0
    for i in range(n):
        c,d=CD[i]
        for j in range(n):
            a,b=AB[j]
            if(a<c and b<d):
                AB[j]=[INF,INF]
                CD[i]=[-INF,-INF]
                ans+=1
                break
    print(ans)
resolve()

Solution (Python):



N = int(input())

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

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

r.sort()
b.sort()

ans = 0
for my,x in r:
    for j in range(len(b)):
        if  -my < b[j][1] and x < b[j][0]:
            ans += 1
            b.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()
ans = 0

for i in range(N):
    blue_x , blue_y = cd[i][0], cd[i][1]
    red_list_x = []
    red_list_y = []
    red_list_index = []
    for k in range(len(ab)):
        red_x, red_y = ab[k][0], ab[k][1]
        if blue_x > red_x and blue_y > red_y:
            red_list_x.append(red_x)
            red_list_y.append(red_y)
            red_list_index.append(k)
    if red_list_index:
        loc = red_list_index[red_list_y.index(max(red_list_y))]
        ans += 1
        del ab[loc]
        

print(ans)

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

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

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


count = 0
for b in B:
	cand = []
	for a in A:
		if b[0] or a[0] : continue
		
		if b[1][0] > a[1][0] and b[1][1] > a[1][1]:
			
			b[0] = True
			a[0] = True
			count += 1

print(count)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
b=[]
for i in range(n):
    b.append(list(map(int,input().split())))
b.sort()
a=sorted(a,key=lambda x: -x[1])
ans=0
vb=[]
for i in range(n):
    for j in range(n):
        if not j in vb:
            if a[i][0]<b[j][0] and a[i][1]<b[j][1]:
                vb.append(j)
                ans+=1
                break
print(ans)

Solution (Python):
N = int(input())
lst1 = []
lst2 = []
for i in range(N):
    lst1.append(list(map(int, input().split())))
for i in range(N):
    lst2.append(list(map(int, input().split())))
lst1.sort()
lst2.sort()
cnt = 0
for i in lst2:
    ans = []
    for j in lst1:
        if i[0] <= j[0]:
            break
        else:
            if i[1] > j[1]:
                ans.append(j[::-1])
    if not ans:
        continue
    else:
        lst1.remove(max(ans)[::-1])
        cnt += 1
print(cnt)

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

b_f = [-1] * n
r_f = [-1] * n

pair = []
count = 0
for i in range(n):
    if b_f[i] == -1:
        tmp = []
        for j in range(n):
            if b[i][0] > r[j][0] and b[i][1] > r[j][1] and r_f[j] == -1:
                tmp.append(j)
            
        if len(tmp) != 0:     
            pair_j = max(tmp, key=lambda j: r[j][1])
            count += 1
            b_f[i] = 1
            r_f[pair_j] = 1
print(count)

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

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

CD = []    
for i in range(N):
    tmp = list(map(int, input().split()))
    CD.append(tmp)
    
AB = sorted(AB, key=lambda x: x[1], reverse=True)
CD = sorted(CD)

ans = 0
for cd in CD:
    for ab in AB:
        if cd[0] > ab[0] and cd[1] > ab[1]:
            ans += 1
            AB.remove(ab)
            break
        
print(ans)

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

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

abl = sorted(abl)


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]

karp = HopcroftKarp(n,n)

for i in range(n):
    for j in range(n):
        if abl[i][0] < cdl[j][0] and abl[i][1] < cdl[j][1]:
            karp.add_edge(i,j)
            
print(karp.flow())

Solution (Python):

def dfs(v, edges, n, visited, matched):
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], edges, n, visited, matched):
            matched[u] = v
            return True
    return False
def examC():
    N = I()
    ab = [LI() for _ in range(N)]
    cd = [LI() for _ in range(N)]
    xn = N; yn = N
    matched = [-1] * yn
    E = [set() for _ in range(xn)]
    for i in range(xn):
        for j in range(yn):
            if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
                E[i].add(j)
    ans = 0
    for s in range(xn):
        ans += dfs(s, E, yn, set(), matched)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):

def dfs(v, edges, n, visited, matched):
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], edges, n, visited, matched):
            matched[u] = v
            return True
    return False
def examC():
    N = I()
    ab = [LI() for _ in range(N)]
    cd = [LI() for _ in range(N)]
    xn = N; yn = N
    matched = [-1] * yn
    E = [set() for _ in range(xn)]
    for i in range(xn):
        for j in range(yn):
            if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
                E[i].add(j)
    ans = 0
    for s in range(xn):
        ans += dfs(s, E, yn, set(), matched)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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

red.sort(reverse=True)
blue.sort(key=lambda x: x[1])
pairedBlue = [False] * N

ans = 0
for r in red:
    for id, b in enumerate(blue):
        if pairedBlue[id]:
            continue
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            pairedBlue[id] = True
            break

print(ans)

Solution (Python):
import heapq

N = int(input())

red = []
for i in range(N):
    x,y = map(int, input().split())
    heapq.heappush(red, (-y, x))

blue = []
for i in range(N):
    x,y = map(int, input().split())
    heapq.heappush(blue, (x,y))

ans = 0
for i in range(N):
    tmp = []
    bx,by = heapq.heappop(blue)
    flag = True
    while flag:
        mry, rx = heapq.heappop(red)
        if bx > rx and by > -mry:
            ans += 1
            flag = False
            if len(tmp) > 0:
                for mry,rx in tmp:
                    heapq.heappush(red, (mry, rx))
        else:
            tmp.append((mry, rx))

        if len(red) == 0:
            if len(tmp) > 0:
                for mry,rx in tmp:
                    heapq.heappush(red, (mry, rx))
            break
            
print(ans)