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):
label = {}
flow = {}
s, t = 'S', 'T'

def printpath(path):
    return
    for u, v in zip(path, path[1:]):
        print("%s -%d-> " % (label[u], flow[(u,v)]), end="")
    print("")

def printflow():
    return
    print("--flow--")
    for r in R:
        for b in edges[r]:
            print("  ", label[r], label[b], "s->r=%d"%flow[(s, r)], ", r->b=%d"%flow[(r, b)], ", b->t=%d"%flow[(b, t)])
            
        if edges[r]:
            print()

def findpath(v, t, edges, flow, visited):
    visited.add(v)
    
    for u in edges[v]:
        if u in visited:
            continue
        if flow[(v, u)] == 1:
            continue
        if u == t:
            return [v, t]
        path = findpath(u, t, edges, flow, visited)
        if path:
            return [v] + path
    return None

def max_match(R, B, edges):

    
    for b in B:
        flow[(b, t)] = 0
        flow[(t, b)] = 1
        edges[b].append(t)

    edges[s] = []
    
    for r in R:
        flow[(s, r)] = 0
        flow[(r, s)] = 1
        edges[s].append(r)

        
        for b in edges[r]:
            flow[(r, b)] = 0
            flow[(b, r)] = 1

    change = True
    while change:
        printflow()
        change = False
        for r in R:
            if flow[(s, r)] == 1:
                continue
            path = findpath(r, t, edges, flow, set([s]))
            if not path:
                continue
            
            path = [s] + path
            for u, v in zip(path, path[1:]):
                flow[(u, v)] = 1
                flow[(v, u)] = 0
            change = True
    printflow()
    return flow

def solve(R, B, edges):
    flow = max_match(R, B, edges)

    match = 0
    for r in R:
        for b in edges[r]:
            match += flow[(r, b)]
    return match
            

N = int(input())

R = [tuple([int(x) for x in input().split()]) for _ in range(N)]
B = [tuple([int(x) for x in input().split()]) for _ in range(N)]
for i, r in enumerate(R):
    label[r] = "R%d" % (i+1)
    
for i, r in enumerate(B):
    label[r] = "B%d" % (i+1)
    
label[s] = 'S'
label[t] = 'T'

edges = {}
for r in R:
    edges[r] = []
for b in B:
    edges[b] = []

for r in R:
    rx, ry = r
    for b in B:
        bx, by = b
        if rx < bx and ry < by:
            edges[r].append(b)
            edges[b].append(r)


print(solve(R, B, edges))

Solution (Python):
from collections import defaultdict

n = int(input())

red = []
blue = []

for _ in range(n):
    a, b = map(int, input().split())
    red.append((a, b))

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

red.sort()
blue.sort()
cnt = 0

for b in blue:
    max_r_y = -1
    paired = (-1, -1)
    for r in red:
        if r[0] > b[0]:
            break
        if max_r_y < r[1] < b[1]:
            max_r_y = r[1]
            paired = r

    if paired != (-1, -1):
        red.remove(paired)
        cnt += 1

print(cnt)

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_ = B[:]

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

for i, b in enumerate(B):
    matchR = [(j, r) for j, r in enumerate(R) if r[0] < b[0] and r[1] < b[1]]
    if matchR:
        matchR.sort(key=lambda x: x[1][1], reverse=True)
        del R[matchR[0][0]]
    else:
        B_[i] = None

print(len([b for b in B_ if b is not None]))

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

ans = 0

ab.sort(key=lambda x:x[1],reverse=True)
cd.sort()


for c,d in cd:
    for i,(a,b) in enumerate(ab):
        if a < c and b < d:
            ans +=1 
            ab.pop(i)
            break
print(ans)

Solution (Python):
dat_r = []
dat_b = []

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

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

dat_r.sort(key=lambda x: ( -x[1], -x[0]-x[1]))
dat_b.sort(key=lambda x: ( +x[0],  x[0]+x[1]))



res = 0
"""
for i in range(n):
    for j in range(len(dat_b)):
        
        if dat_r[i][0] < dat_b[j][0] and dat_r[i][1] < dat_b[j][1]:
            
            res += 1
            dat_b  = dat_b[0:j] + dat_b[j + 1:]
            break
print(res)
"""
for i in range(n):
    for j in range(len(dat_r)):
        
        if dat_r[j][0] < dat_b[i][0] and dat_r[j][1] < dat_b[i][1]:
            
            res += 1
            dat_r  = dat_r[0:j] + dat_r[j + 1:]
            break
print(res)

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

B = sorted(B, key=lambda p: p[0])

ans = 0
for bx, by in B:
    ry_max = -1
    idx = -1
    for i, (rx, ry) in enumerate(R):
        if rx < bx and ry < by and ry_max < ry:
            ry_max = ry
            idx = i
    if idx != -1:
        R.pop(idx)
        ans += 1
print(ans)

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 = sorted(red, key = lambda x: x[1])
blue.sort()
ans = 0
for i in range(n):
    a = 0
    for j in range(len(red)):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1]:
            a = j
    if blue[i][0] > red[a][0] and blue[i][1] > red[a][1]:
        ans += 1
        del red[a]
print(ans)

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

R.sort()
B.sort()

count = 0
tmp = []
for bx, by in B:
    for rx, ry in R:
        if bx > rx and by > ry:
            tmp.append([rx, ry])
    if tmp != []:
        max_red = max(tmp, key=lambda r: r[1])
        count += 1
        R.remove(max_red)
        tmp = []
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(key=lambda x: x[1])
blue.sort(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):
import copy
N=int(input())
ab=list(list(map(int,input().split())) for _ in range(N))
cd=list(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])
ans=0
for c,d in cd:
    for a,b in ab:
        if b<d and a<c:
            ab[ab.index([a,b])]=[1000,1000] 
            cd[cd.index([c,d])]=[-1000,-1000]
            ans+=1
            break
print(ans)

Solution (Python):
n,*t=map(int,open(0).read().split())
x=sorted(zip(t[1:n*2:2],t[:n*2:2]))
y=sorted(zip(t[n*2::2],t[n*2+1::2]))[::-1]
c=0
while y:
  i,j=y.pop()
  k=len(x)-1
  while k>=0:
    b,a=x[k]
    if a<i and b<j:
      c+=1
      del x[k]
      break
    k-=1
print(c)

Solution (Python):
n,*t=map(int,open(0).read().split())
x=sorted(zip(t[1:n*2:2],t[:n*2:2]))
y=sorted(zip(t[n*2::2],t[n*2+1::2]))[::-1]
c=0
while y:
  i,j=y.pop()
  k=len(x)-1
  while k>=0:
    b,a=x[k]
    if a<i and b<j:
      c+=1
      del x[k]
      break
    k-=1
print(c)

Solution (Python):
N=int(input())
ab=[]
for i in range(N):
    a,b=map(int,input().split())
    ab.append([b,a])
cd=[]
for i in range(N):
    c,d=map(int,input().split())
    cd.append([c,d])
cd.sort(key=lambda x:(x[0],x[1]))
ab.sort(key=lambda x:(-x[0],-x[1]))
ans=0
for i in cd:
    c,d=i[0],i[1]
    for j in ab:
        b,a=j[0],j[1]
        if a<c and b<d :
            ans+=1
            ab.remove([b,a])
            break
print(ans)

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())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter

points = AB.copy()
for c,d in CD:
    points.append([1,c,max(0,d-0.1)])
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        for i in range(x-1,-1,-1):
            if record[i] > 0:
                ans += 1
                record[i] -= 1
                break
    else:
        record[x] += 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)]

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

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

print(ans)

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

c = 0

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

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

ans = 0
r,b = sorted(r, key=lambda x:x[1],reverse=True), sorted(b)
for i in b:
    for j in r:
        if i[1]>j[1] and i[0] >j[0]:
            ans += 1
            r.remove(j)
            break
 
print(ans)

Solution (Python):
N = int(input())
lia= [ [ int(it) for it in input().split() ] for i in range(N)]
lib= [ [ int(it) for it in input().split() ] for i in range(N)]


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]
    
hop = HopcroftKarp(N,N)

for i in range(N):
  a,b = lia[i]
  for j in range(N):
    c,d = lib[j]
    if ( a<c and b<d ):
      hop.add_edge(i,j)
co = hop.flow()
print ( co )

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

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    ablist = intinl(n)
    cdlist = intinl(n)

    ablist.sort()
    cdlist.sort()
    ans = 0

    while ablist:
        a, b = ablist.pop()
        idx = binl(cdlist, (a, b))

        cand = None
        for i, (c, d) in enumerate(cdlist[idx:]):
            if b < d:
                if cand is None:
                    cand = (i, c, d)
                else:
                    ci, cc, cd = cand
                    if d < cd:
                        cand = (i, c, d)

        if cand is None:
            continue

        ci, cc, cd = cand
        del cdlist[idx + ci]
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
R = [0]*N
B = [0]*N
L = [0]*N
for i in range(N):
    R[i] = list(map(int,input().split(" ")))

for i in range(N):
    B[i] = list(map(int,input().split(" ")))
    
R = sorted(R,key=lambda x:x[1],reverse=True)
B = sorted(B,key=lambda x:x[0])

for b in B:
    for i in range(N):
        r = R[i]
        if not(L[i]) and r[0] < b[0] and r[1] < b[1]:
            L[i] = 1
            break

print(sum(L))

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
R=[]
B=[]
for i in range(n):
    x,y=IL()
    R.append([x,y,x+y])
for i in range(n):
    x,y=IL()
    B.append([x,y,x+y])
R.sort(key=lambda x:-x[1])
B.sort(key=lambda x:x[0])
Rb=[True]*n
Bb=[True]*n

ans=0
for i in range(n):
    bx,by,bz=B[i]
    for j in range(n):
        rx,ry,rz=R[j]
        if rx<bx and ry<by and Rb[j] and Bb[i]:
            ans+=1
            Rb[j]=False
            Bb[i]=False
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[0])
cd.sort(key = lambda x:x[0])
cnt = 0
for i in range(N):
    x = cd[i][0]
    tmplist = []
    for j in range(len(ab)):
        if ab[j][0] >= x:
            break
        tmplist += [ab[j]]
    tmplist.sort(key = lambda x:x[1],reverse = True)
    for j in range(len(tmplist)):
        if cd[i][1] > tmplist[j][1]:
            cnt += 1
            ab.remove(tmplist[j])
            break
        
print(cnt)

Solution (Python):
def main():
    num = int(input())
    aka_data = [list(map(int, input().split())) for i in range(num)]
    ao_data = [list(map(int, input().split())) for i in range(num)]

    aka_data.sort(key=lambda x:-x[1])
    ao_data.sort(key=lambda x: x[0])

    ans = 0
    for j in range(num):
        for i in range(len(aka_data)):
            if aka_data[i][0] < ao_data[j][0] and aka_data[i][1] < ao_data[j][1]:
                aka_data.pop(i)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
red = sorted(red, reverse=True)
blue = [list(map(int, input().split())) for i in range(n)]
blue = sorted(blue, key=lambda x: x[1])
ans = 0
for re in red:
    a, b = re
    for i, bu in enumerate(blue):
        c, d = bu
        if a < c and b < d:
            ans += 1
            blue.pop(i)
            break
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)]

A_sorted = sorted(A, key=lambda x: x[1], reverse=True)
B_sorted = sorted(B, key=lambda x: x[0])


def func():
    global A_sorted, B_sorted
    count = 0
    for b in B_sorted:
        a = None
        A_sorted_cp = A_sorted[:]
        while True:
            if len(A_sorted_cp) == 0:
                break
            a = A_sorted_cp.pop(0)
            if a[0] < b[0] and a[1]<b[1]:
                count += 1
                A_sorted.pop(A_sorted.index(a))
                break
    return count
            
    

print(func())

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

from operator import itemgetter



cnt = 0
for c, d in CD:
    
    del_idx = None
    tmpmax = -1
    for i, (a, b) in enumerate(AB):
        if a < c and b < d:
            if b > tmpmax:
                
                
                tmpmax = b
                del_idx = i

    if del_idx is not None:
        
        AB[del_idx] = [float('inf'), float('inf')]
        cnt += 1


print(cnt)

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    N = int(input())
    red = [list(map(int, input().split())) for _ in range(N)]
    red.sort(key=lambda x: x[0])

    blue = [list(map(int, input().split())) for _ in range(N)]
    blue.sort(key=lambda x: x[0])

    ans = 0
    for bx, by in blue:
        p_red = None
        for i in range(len(red)):
            rx, ry = red[i][0], red[i][1]
            if rx > bx:
                break
            if ry < by:
                if not p_red:
                    p_red = red[i]
                else:
                    if p_red[1] < ry:
                        p_red = red[i]
        if p_red:
            ans += 1
            red.remove(p_red)

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[1], reverse=True)
    bluedots = sorted(bluedots, key=lambda x: x[0])

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[1], reverse=True)
    bluedots = sorted(bluedots, key=lambda x: x[0])

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[0] = 201
                break

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())


red = []
for i in range(N):
    a = list(map(int, input().split()))
    red += [a]
red.sort(reverse = False)


blue = []
for i in range(N):
    a = list(map(int, input().split()))
    blue += [a]
blue.sort(reverse = False)


def judge(m): 
    INF = 10 ** 9
    count = 0
    memo = -1
    for i in range(N): 
        if blue[m][0] > red[i][0]: 
            
            if memo < red[i][1] and blue[m][1] > red[i][1]: 
            
                count = 1 
                memo = max(memo, red[i][1]) 
                memo_i = i 
    if count == 0: 
        return False
    else: 
        red[memo_i][0] = INF 
        red[memo_i][1] = INF 
        return True

count = 0
for s in range(N): 
    if judge(s):
        count += 1
print (count)

Solution (Python):

N = int(input())

red_x = []
red_y = []
for i in range(N):
    a = list(map(int, input().split()))
    red_x += [a]
    red_y += [a[::-1]]
red_x.sort(reverse = False)
red_y.sort(reverse = False)



blue_x = []
blue_y = []

for i in range(N):
    a = list(map(int, input().split()))
    blue_x += [a]
    blue_y += [a[::-1]]
blue_x.sort(reverse = False)
blue_y.sort(reverse = False)


def judge_x(m): 
    INF = 10 ** 9
    count = 0
    memo = -1
    for i in range(N):
        if blue_x[m][0] > red_x[i][0]: 
            
            

            
            
            if memo < red_x[i][1] and blue_x[m][1] > red_x[i][1]: 
                count = 1
                memo = max(memo, red_x[i][1]) 
                memo_i = i
    if count == 0: 
        return False
    else: 
        red_x[memo_i][0] = INF 
        red_x[memo_i][1] = INF 

        return True
    return False

def judge_y(m): 
    INF = 10 ** 9
    for i in range(N):
        if blue_y[m][1] > red_y[i][1]:
            if blue_y[m][0] > red_y[i][0]:
                red_y[i][1] = INF
                return True
        else:
            pass
    return False

count_x = 0
for s in range(N): 
    if judge_x(s):
        count_x += 1
print (count_x)

Solution (Python):
n=int(input())
reds=list()
blues=list()
cnt=0
for i in range(n):
	reds.append(list(map(int,input().split())))
for i in range(n):
	blues.append(list(map(int,input().split())))
blues=sorted(blues,key=lambda x:x[0])
reds=sorted(reds,key=lambda x:x[1],reverse=True)

for blue in blues:
	for red in reds:
		if red[0]<blue[0] and red[1]<blue[1]:
			cnt+=1
			red[0]=201
			break
print(cnt)

Solution (Python):
n = int(input())
reds = list()
blues = list()
counter = 0

for i in range(n):
    reds.append(list(map(int,input().split())))
    
for i in range(n):
    blues.append(list(map(int,input().split())))
    
blues = sorted(blues,key=lambda x:x[0])
reds = sorted(reds,key=lambda x:x[1],reverse=True)

for blue in blues:
    for red in reds:
        if red[0] < blue[0] and red[1] < blue[1]:
            red[1] = 201
            counter += 1
            break
print(counter)

Solution (Python):

import sys
INF = float("inf")
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_edge(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'))


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    red = [[a[i], b[i]] for i in range(N)]
    blue = [[c[i], d[i]] for i in range(N)]

    
    dn = Dinic(2*N+2)
    for i, (rx, ry) in enumerate(red):
        dn.add_edge(0, i+1, 1)
    for j, (bx, by) in enumerate(blue):
        dn.add_edge(N+j+1, 2*N+1, 1)

    for i, (rx, ry) in enumerate(red):
        for j, (bx, by) in enumerate(blue):
            if rx < bx and ry < by:
                dn.add_edge(i+1, N+j+1, 1)

    ans = dn.max_flow(0, 2*N+1)
    print(ans)

    


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

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

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

	ans = 0
	for b in blue:
		removes = []
		for i, r in enumerate(red):
			if r[0] < b[0] and r[1] < b[1]:
				removes.append([r[1], i])
		if len(removes) > 0:
			removes.sort(key=lambda x: -x[0])
			ans += 1
			red.pop(removes[0][1])

	print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
INF = float("inf")



def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    red = [[a[i], b[i], False] for i in range(N)]
    blue = [[c[i], d[i], False] for i in range(N)]

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

    
    
    ans = 0

    for b in blue:
        cand = [i for i, r in enumerate(red) if r[0] < b[0] and r[1] < b[1]]
        
        if len(cand) > 0:
            ans += 1
            i = max(cand, key=lambda i: red[i][1])
            red.pop(i)
    print(ans)

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


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

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

print(ans)

Solution (Python):
N = int(input())
ab = [[int(i) for i in input().split(" ")] for _ in range(N)]
cd = [[int(i) for i in input().split(" ")] for _ in range(N)]
ab_sort = sorted(ab, key=lambda x:-x[1])
cd_sort = sorted(cd, key=lambda x:x[0])

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

print(cnt)