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

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

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

count = 0
for b in blues:
    bx, by = b
    for r in reds[::-1]:
        rx, ry = r
        if bx > rx and by > ry:
            count += 1
            reds.remove(r)
            break

print(count)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
x = [inpl() for i in range(n)]
y = [inpl() for i in range(n)]
x.sort(reverse=True)
y.sort(key = lambda x: x[1])
res = 0
used = set()
for i in range(n):
    a,b = x[i][0], x[i][1]
    for j in range(n):
        c,d = y[j][0], y[j][1]
        if a<c and b<d and not j in used:
            res += 1
            used.add(j)
            break
print(res)

Solution (Python):
N, *L = map(int, open(0).read().split())
red = []
blue = []
for a, b in zip(*[iter(L[:2*N])]*2):
  red += [(a,b)]
for c, d in zip(*[iter(L[2*N:])]*2):
  blue += [(c,d)]
red.sort(reverse=True)
blue.sort(reverse=True)
S = set(range(N))

ans = 0
for a,b in red:
  k = -1
  m = 10**3
  for j, n in enumerate(blue):
    c,d = n
    if c<a:
      break
    if d-b>0 and d-b<m and j in S:
      k = j
      m = d-b
  if k!=-1:
    ans += 1
    S.remove(k)
print(ans)

Solution (Python):
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
cd = []
for _ in range(n):
    c, d = (int(x) for x in input().split())
    cd.append([c, d])
ab = sorted(ab, key=lambda x: -x[0])
cd = sorted(cd, key=lambda x: x[1])

count = 0

for a, b in ab:
    index = -1
    for i, cda in enumerate(cd):
        if a < cda[0] and b < cda[1] :
            index = i
            break
    if index != -1:
        cd.pop(index)
        count += 1
print(count)

Solution (Python):


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

blue.sort(key=lambda x: x[0])
used_red = [0]*N
for i in range(N):
    idx = -1
    for j in range(N):
        if used_red[j] != 0:
            continue
        if blue[i][0]-red[j][0]>0 and blue[i][1]-red[j][1]>0:
            if idx == -1 or red[idx][1]<red[j][1]:
                idx = j
    if idx!=-1:
        used_red[idx] += 1

print(sum(used_red))

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())
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.add_edge(n*2, i, 1)
    for j in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            dinic.add_edge(i, j+n, 1)
for i in range(n):
    dinic.add_edge(i+n, n*2+1, 1)
print(dinic.flow(n*2, n*2+1))

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()
remain = set(range(n))

ans = 0
for c,d in cd:
    cand = [-1, -1]
    for i in remain:
        a,b = ab[i]
        if((a<c) & (b<d)):
            if(cand[1] < b):
                cand = [i,b]

    if(cand[0] == -1):
        continue

    remain.remove(cand[0])
    ans += 1


print(ans)

Solution (Python):

"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc091/tasks/arc092_a

xが小さい方から見ていく
→青があったら、今まで見た赤の点の内、現在選んでいる点よりy軸が小さく、最大の点を選んで繋げる
→最適性は簡単にわかる

"""
import bisect
N = int(input())

p = []

for i in range(N):

    a,b = map(int,input().split())
    p.append([a,b,0])

for i in range(N):

    c,d = map(int,input().split())
    p.append([c,d,1])

p.sort()

R = []
ans = 0

for i in range(2*N):

    x,y,cl = p[i]

    if cl == 0:
        R.append(y)
        R.sort()

    else:
        ind = bisect.bisect_left(R,y)
        if ind == 0:
            continue
        else:
            del R[ind-1]
            ans += 1
    

print (ans)

Solution (Python):
n = int(input())
aka = []
ao = []
aka = aka + [list(map(int,input().split())) for _ in range(n)]
ao = ao + [list(map(int,input().split())) for _ in range(n)]

aka = sorted(aka, key=lambda x:x[1],reverse=True)
ao = sorted(ao, key=lambda x:x[0])

ans = 0

for i in range(n):
	for j in range(n):
		if ao[i][0] > aka[j][0] and ao[i][1] > aka[j][1]:
			ans += 1
			aka[j][1] = 201
			break

print(ans)

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

a=[0]*n
b=[0]*n
c=[0]*n
d=[0]*n
edges=[set() for _ in range(n)]
matched=[-1]*n

for i in range(n):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

for i in range(n):
    tc,td=list(map(int,input().split()))
    c[i]=tc
    d[i]=td

for i in range(n):
    for j in range(n):
        if a[i]<c[j] and b[i]<d[j]:
            edges[i].add(j)

def dfs(v,visited):
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u]==-1 or dfs(matched[u],visited):
            matched[u]=v
            return True
    
    return False

print(sum(dfs(s,set()) for s in range(n)))

Solution (Python):
X_INDEX = 0
Y_INDEX = 1


def solve():
    number_of_balls = int(input())
    red_points = [list(map(int, input().split())) for _ in range(number_of_balls)]
    blue_points = [list(map(int, input().split())) for _ in range(number_of_balls)]

    from operator import itemgetter
    blue_points.sort(key=itemgetter(X_INDEX))  
    red_points.sort(key=itemgetter(Y_INDEX), reverse=True)  

    
    
    number_of_pairs = 0  
    used_red_points = [False for _ in range(number_of_balls)]  
    
    for blue_i, blue_point in enumerate(blue_points):
        for red_i, red_point in enumerate(red_points):
            if red_point[X_INDEX] < blue_point[X_INDEX] and \
                    red_point[Y_INDEX] < blue_point[Y_INDEX] and \
                    not used_red_points[red_i]:
                number_of_pairs += 1
                used_red_points[red_i] = True
                break

    print(number_of_pairs)


solve()

Solution (Python):
INF = float("inf") 
MOD = 10**9+7 
MAX = 510000 

import fractions
import itertools

def main():
    n = int(input())
    ab = [list(map(int,input().split())) for _ in range(n)]
    ab = sorted(ab,key=lambda x:x[1],reverse=True)
    cd = [list(map(int,input().split())) for _ in range(n)]
    cd = sorted(cd,key=lambda x:x[0])

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])
    R = [tuple(map(int, ab)) for ab in map(str.split, args[1:n+1])]
    B = [tuple(map(int, ab)) for ab in map(str.split, args[n+1:2*n+1])]

    R.sort(key=lambda x: (-x[1], x[0]))
    B.sort(key=lambda x: (x[0], x[1]))

    count = 0
    used = [False]*n
    for i in range(n):
        bx, by = B[i]
        for j in range(n):
            if used[j]:
                continue
            rx, ry = R[j]
            if rx < bx and ry < by:
                count += 1
                used[j] = True
                break

    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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(A, key=lambda x: -x[1])  
B = sorted(B, key=lambda x: x[0])   

for i in range(N):
    for j in range(len(A)):
        if A[j][0] < B[i][0] and A[j][1] < B[i][1]:
            A.pop(j)
            break

print(N - len(A))

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

RY = sorted(R, key=lambda x: x[1], reverse=True)
BX = sorted(B, key=lambda x: x[0])

ans = 0

for b in BX:
  for index, r in enumerate(RY):
    if b[0] > r[0] and b[1] > r[1]:
      ans += 1
      RY.pop(index)
      break

print(ans)

Solution (Python):
from collections import deque


class Dinic:
    """
    1-indexed
    din = Dinic(N)
    for _ in range(M):
        s,t,cap = map(int,input().split())
        din.add_edge(s,t,cap)
    ans = din.get_maximumFlow(source, sink)
    """

    def __init__(self, N):
        self.N = N
        self.edge = [[] for _ in range(N + 1)]
        self.level = [-1] * (N + 1)

    def add_edge(self, v_from, v_to, cap):
        self.edge[v_from].append([v_to, cap, len(self.edge[v_to])])
        self.edge[v_to].append([v_from, 0, len(self.edge[v_from]) - 1])

    def _BFS(self, s):
        """
        sからの最短距離をBFSで計算する  
        """
        level = [-1] * (self.N + 1)
        level[s] = 0
        que = deque([s])
        while que:
            s = que.popleft()
            for t, cap, _ in self.edge[s]:
                if cap > 0 and level[t] < 0:
                    level[t] = level[s] + 1
                    que.append(t)
        self.level = level[:]

    def _DFS(self, v, goal, f):
        """
        増加パスをDFSで探す
        """
        if v == goal:
            return f
        for i in range(self.iterate[v], len(self.edge[v])):
            self.iterate[v] = i
            to, cap, rev = self.edge[v][i]
            if cap > 0 and self.level[v] < self.level[to]:
                d = self._DFS(to, goal, min(cap, f))
                if d > 0:
                    self.edge[v][i][1] -= d
                    self.edge[to][rev][1] += d
                    return d
        return 0

    def get_maximumFlow(self, s, t):
        """
        s -> tの最大流を求める
        1-indexed
        """
        self.goal = t
        inf = 10**18
        flow = 0
        while True:
            self._BFS(s)
            if self.level[t] < 0:
                return flow
            self.iterate = [0] * (self.N + 1)
            while True:
                f = self._DFS(s, t, inf)
                if f <= 0:
                    break
                flow += f


if __name__ == "__main__":
    N = int(input())
    din = Dinic(2 * N + 10)
    red = [tuple(map(int, input().split())) for _ in range(N)]
    blue = [tuple(map(int, input().split())) for _ in range(N)]

    source = 2 * N + 1
    sink = source + 1

    for i, (xi, yi) in enumerate(red):
        for j, (xj, yj) in enumerate(blue):
            if xi < xj and yi < yj:
                s = i + 1
                t = j + 1 + N
                din.add_edge(s, t, 1)
    for i in range(1, N + 1):
        din.add_edge(source, i, 1)
        din.add_edge(i + N, sink, 1)

    ans = din.get_maximumFlow(source, sink)
    print(ans)

Solution (Python):
n = int(input())
r = [list(map(int, input().split())) for _ in range(n)]
r.sort(key=lambda x: x[1], reverse=True)  
b = [list(map(int, input().split())) for _ in range(n)]
b.sort()  
cnt = 0  
for i in range(n):  
    for j in range(len(r)):
        if r[j][0] < b[i][0] and r[j][1] < b[i][1]:
            cnt += 1
            r.pop(j)
            break
print(cnt)

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

R.sort(key=lambda r: r[1], reverse=True)
B.sort()

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):
import bisect

N=int(input())
ab=[[0,0,0] for _ in range(N)]
cd=[[0,0,0] for _ in range(N)]

for i in range(N):
    ab[i][0],ab[i][1]=map(int,input().split())

for i in range(N):
    cd[i][0],cd[i][1]=map(int,input().split())
    
    
    
ab.sort()
cd.sort()
ans=0

for i in range(N):
    temp_j=-1
    temp_y=-1
    for j in range(N):
        if ab[j][2]==0:
            if ab[j][0] < cd[i][0]: 
                if cd[i][1] > ab[j][1] and ab[j][1]>=temp_y:
                    temp_y=ab[j][1]
                    temp_j=j
    if temp_j!=-1:
        ab[temp_j][2]=1
        ans+=1
        
print(ans)

Solution (Python):
def solve():
    N = int(input())
    R = [[int(x) for x in input().split()] for i in range(N)]
    B = [[int(x) for x in input().split()] for i in range(N)]
    B.sort()
    selected = set()
    for b in B:
        r_lst = []
        for i in range(len(R)):
            if i in selected: continue
            r = R[i]
            if r[0] < b[0] and r[1] < b[1]:
                r_lst.append(i)
        if len(r_lst) == 0:
            continue
        rym = -1
        rym_i = -1
        for i in r_lst:
            if rym < R[i][1]:
                rym = R[i][1]
                rym_i = i
        selected.add(rym_i)
    return len(selected)
if __name__ == '__main__':
    print(solve())

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

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

CD = sorted(CD, key=lambda x:x[1])
count = 0

for cd in CD:
    c = cd[0]
    d = cd[1]
    max_a = -1
    max_b = -1
    for ab in AB:
        a = ab[0]
        b = ab[1]
        if b < d and a < c:
            if max_a < a:
                max_a = a
                max_b = b
    if max_a == -1:
        pass
    else:
        AB.remove((max_a, max_b))
        count += 1

print(count)

Solution (Python):
def main():
  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 p:p[1], reverse=True)
  B = sorted(B)
  ans = 0
  
  for xB, yB in B:
    for xR, yR in R:
      if xR < xB and yR < yB:
        R.remove([xR, yR])
        ans += 1
        break
  print(ans)

if __name__=="__main__":
  main()

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

ans = 0
for c,d in blue:
    x = []
    for a,b in red:
        if a < c and b < d:
            x.append([a,b])
    if len(x) > 0:
        ans += 1
        x = sorted(x, key=lambda x:x[1])
        red.remove(x[-1])

print(ans)

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

"""考え方
1.青色を第一要素（x）が小さい順にソートする
2.青色の点より左にある赤い点のうち、yが小さく、かつ一番大きい赤い点を選択する
"""



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


CD = []
for n in range(N):
  CD.append(list(map(int, input().split())))
CD = sorted(CD, key=lambda x: x[0], reverse=False)



used_idx = []
ans = 0
for _ in CD:
  c = _[0]
  d = _[1]
  red_max_y = -1
  
  for idx, __ in enumerate(AB):
    a = __[0]
    b = __[1]
    if a < c:
      if b < d:
        if idx not in used_idx:
          used_idx.append(idx)
          ans += 1
          break
  
    
print(ans)

Solution (Python):
n = int(input())
red = []
blue = []
B = [0]*(n+1)
for i in range(n):
  red.append(list(map(int,input().split())))

for i in range(n):
  blue.append(list(map(int,input().split())))
red.sort(key=lambda x: x[1], reverse=True)
blue.sort(key=lambda x: x[0])
cnt = 0

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

print(cnt)

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

Solution (Python):

n = int(input())
coordinates_red = [list(map(int, input().split())) for _ in range(n)]
coordinates_blue = [list(map(int, input().split())) for _ in range(n)]
coordinates_red.sort()
coordinates_blue.sort()



start = 0
ans = 0
for blue in coordinates_blue:
    candidate = []
    for red in coordinates_red:
        
        
        if red[0] < blue[0] and red[1] < blue[1]:
            candidate.append(red)
    if candidate:
        candidate.sort(key=lambda x: x[1])
        coordinates_red.remove(candidate.pop(-1))
        ans += 1

print(ans)

Solution (Python):
N=int(input())
r=[tuple(map(int,input().split())) for i in range(N)]
b=[tuple(map(int,input().split())) for i in range(N)]
r.sort()
b.sort()
a=0
for i in b:
    t=(-1,-1)
    for j in r:
        if j[0]>i[0]:
            break
        if t[1]<j[1]<i[1]:
            t=j
    if t!=(-1,-1):
        r.remove(t)
        a+=1
print(a)

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


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

blue.sort()

pair_count = 0
for i in range(n):
    for j in range(len(red)):
        if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            pair_count += 1
            red.pop(j)
            break

print(pair_count)

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])
ans = 0
for i, bb in enumerate(b):
    c, d = bb
    for j, rr in enumerate(r):
        a, b = rr
        if c > a and d > b:
            ans += 1
            del r[j]
            break
print(ans)

Solution (Python):
from math import ceil
from operator import itemgetter

def main():
    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))
    AB.sort(key = itemgetter(0))
    CD.sort( key = itemgetter(0))
    CD.sort(key = itemgetter(1))

    ans = 0
    used = [False]*N
    for i in range(N):
        c,d = CD[i]
        for j in range(N):
            a,b = AB[N - j - 1]
            if not(used[N - j - 1]) and a <= c and b <= d:
                ans += 1
                used[N - j - 1] = True
                break
    print(ans)
    return

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
r = []
b = []
for _ in range(n):
    x,y = map(int,input().split())
    r.append([x,y,0])
for _ in range(n):
    x,y = map(int,input().split())
    b.append([x,y])
r.sort(key=lambda x: x[1], reverse=True)
b.sort()
cnt = 0
for i in range(n):
    for j in range(n):
        if r[j][0] < b[i][0] and r[j][1] < b[i][1] and r[j][2]==0:
            cnt += 1
            r[j][2] = 1
            break
print(cnt)

Solution (Python):
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)]
alr = [False for i in range(N)]
ab.sort()
cd.sort()
count = 0
for c,d in cd:
    maxi = -1
    maxb = -1
    for i in range(N):
        if alr[i]:
            continue
        a,b = ab[i][0],ab[i][1]
        if a < c:
            if b < d:
                if maxb < b:
                    maxb = b
                    maxi = i
        else:
            break
    if maxi != -1:
        alr[maxi] = True
print(alr.count(True))

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

ans = 0
for rx,ry in R:
    for bx,by in B:
        
        if rx<bx and ry<by:
            
            ans += 1
            B.remove([bx,by])
            break

print(ans)

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

used = [0]*N

ans = 0
for bx, by in blue:
    for ri in range(N):
        if used[ri] == 1:
            continue
        rx, ry = red[ri]
        if rx < bx and ry < by:
            used[ri] = 1
            ans += 1
            break

print(ans)

Solution (Python):
import sys
import math
from operator import itemgetter

input = sys.stdin.readline


def main():
    N = int(input())
    AB = [[int(x) for x in input().split()] for _ in range(N)]
    CD = [[int(x) for x in input().split()] for _ in range(N)]

    AB.sort(key=itemgetter(1), reverse=True)
    CD.sort(key=itemgetter(0))

    ans = 0
    used = set()
    for i, cd in enumerate(CD):
        c, d = cd[0], cd[1]
        for j, ab in enumerate(AB):
            if j in used:
                continue
            a, b = ab[0], ab[1]
            if c > a and d > b:
                used.add(j)
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
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()
cd.sort()

g = defaultdict(list)

for c,d in cd:
    for a,b in ab:
        if a < c and b < d:
            g[c].append(a)
            g[a].append(c)

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

def dfs(v):
    used[v] = True
    for nv in g[v]:
        nnv = match[nv]
        if nnv == -1:
            match[v] = nv
            match[nv] = v
            return True
        elif not used[nnv] and dfs(nnv):
            match[v] = nv
            match[nv] = v
            return True
    return False

ans = 0
for i in range(2*N):
    if match[i] == -1:
        used = [False]*(2*N)
        if dfs(i):
            ans += 1
    

print(ans)

Solution (Python):
from operator import itemgetter

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

Red1 = sorted(Red, key=itemgetter(1),reverse = True)
Blue1 = sorted(Blue, key=itemgetter(0)) 
cnt = 0

for i in range(N): 
    for j in range(N):
        if (Blue1[i][0] > Red1[j][0]) and (Blue1[i][1] > Red1[j][1]):
            cnt+=1
            Red1[j] = [500,500] 
            
            break 
print(cnt)

Solution (Python):
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()
cd.sort()
cnt = 0
for i, j in cd:
	x = []
	for k,l in ab:
		if k < i and l < j:
			x.append([k,l])
	if len(x) > 0:
		cnt += 1
		xx = sorted(x, key=lambda x:x[1])
		ab.remove(xx[-1])
print (cnt)

Solution (Python):
N = int(input())
Red = [0] * N
Blue = [0] * N
for j in range(N):
    Red[j] = [0] * 2
    Red[j][0], Red[j][1] = map(int, input().split())
for k in range(N):
    Blue[k] = [0] * 2
    Blue[k][0], Blue[k][1] = map(int, input().split())
Blue = sorted(Blue)
Red = sorted(Red)
ans = 0
for i in range(N):
    kouho = -1
    blue_x = Blue[i][0]
    blue_y = Blue[i][1]
    kouho_y = -1
    for p in range(len(Red)):
        if blue_x > Red[p][0]:
            if kouho_y < Red[p][1] <blue_y:
                kouho_y = Red[p][1]
                kouho = p
        else:
            continue
    if kouho >= 0:
        ans += 1
        del Red[kouho]

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)]
b.sort()
d,ans=dict(),0
for i in range(n):
  cnt=-1
  ok=False
  for j in range(n):
    if j not in d:
      if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
        if r[j][1]>cnt:
          cnt=r[j][1]
          k=j
          ok=True
  if ok:
    ans+=1
    d[k]=0
print(ans)

Solution (Python):
def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=lambda x: x[0], reverse=True)
    
    cd.sort(key=lambda x: x[1])
    ans = 0
    for bx, by in cd:
        for rx, ry in ab:
            if rx < bx and ry < by:
                ab.remove((rx, ry))
                ans += 1
                break
    print(ans)
    return


main()

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=itemgetter(1), reverse=True)
    
    cd.sort()
    ans = 0
    for bx, by in cd:
        for rx, ry in ab:
            if rx < bx and ry < by:
                ab.remove((rx, ry))
                ans += 1
                break
    print(ans)
    return


main()

Solution (Python):
def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=lambda x:x[1], reverse=True)
    
    cd.sort()
    ans = 0
    for bx, by in cd:
        for rx, ry in ab:
            if rx < bx and ry < by:
                ab.remove((rx, ry))
                ans += 1
                break
    print(ans)
    return


main()

Solution (Python):
def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=lambda x:x[1], reverse=True)
    
    cd.sort()
    
    done = [False] * N
    for bx, by in cd:
        for k, ((rx, ry), d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=itemgetter(1), reverse=True)
    
    cd.sort()
    
    done = [False] * N
    for bx, by in cd:
        for k, ((rx, ry), d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=itemgetter(1), reverse=True)
    
    cd.sort(key=itemgetter(0))
    ans = 0
    for bx, by in cd:
        for rx, ry in ab:
            if rx < bx and ry < by:
                ab.remove((rx, ry))
                ans += 1
                break
    print(ans)
    return


main()

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    
    ab.sort(key=itemgetter(1), reverse=True)
    
    cd.sort(key=itemgetter(0))
    
    done = [False] * N
    for bx, by in cd:
        for k, ((rx, ry), d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    ab = [[int(j) for j in input().split()] for i in range(N)]
    cd = [[int(j) for j in input().split()] for i in range(N)]
    
    ab.sort(key=itemgetter(1), reverse=True)
    
    cd.sort(key=itemgetter(0))
    
    done = [False] * N
    for bx, by in cd:
        for k, ((rx, ry), d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    ab = [[int(j) for j in input().split()] for i in range(N)]
    cd = [[int(j) for j in input().split()] for i in range(N)]
    
    ab.sort(key=itemgetter(1), reverse=True)
    
    cd.sort(key=itemgetter(0))
    
    done = [False] * N
    for bx, by in cd:
        for k, ([rx, ry], d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()