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

Solution (Python):
import collections

class MaxFlow:
    """Dinic Algorithm: find max-flow
       complexity: O(EV^2)
       used in GRL6A(AOJ)
    """
    class Edge:
        def __init__(self, to, rev, cap):
            self.to, self.cap, self.rev = to, cap, rev

    def __init__(self, V):
        """ V: the number of vertexes
            E: adjacency list
            source: start point
            sink: goal point
        """
        self.V = V
        self.E = [[] for _ in range(V)]

    def add_edge(self, fr, to, cap):
        self.E[fr].append(self.Edge(to, len(self.E[to]), cap))
        self.E[to].append(self.Edge(fr, len(self.E[fr])-1, 0))

    def dinic(self, source, sink):
        """find max-flow"""
        INF = float('inf')
        maxflow = 0
        while True:
            self.bfs(source)
            if self.level[sink] < 0:
                return maxflow
            self.itr = [0] * self.V
            while True:
                flow = self.dfs(source, sink, INF)
                if flow > 0:
                    maxflow += flow
                else:
                    break

    def dfs(self, vertex, sink, flow):
        """find augmenting path"""
        if vertex == sink:
            return flow
        for i in range(self.itr[vertex], len(self.E[vertex])):
            self.itr[vertex] = i
            e = self.E[vertex][i]
            if e.cap > 0 and self.level[vertex] < self.level[e.to]:
                d = self.dfs(e.to, sink, min(flow, e.cap))
                if d > 0:
                    e.cap -= d
                    self.E[e.to][e.rev].cap += d
                    return d
        return 0

    def bfs(self, start):
        """find shortest path from start"""
        que = collections.deque()
        self.level = [-1] * self.V
        que.append(start)
        self.level[start] = 0

        while que:
            fr = que.popleft()
            for e in self.E[fr]:
                if e.cap > 0 and self.level[e.to] < 0:
                    self.level[e.to] = self.level[fr] + 1
                    que.append(e.to)

N = int(input())
G = MaxFlow(300)

AB = []
for i in range(1,N+1):
	a,b = input().split()
	a_i = int(a)
	b_i = int(b)
	AB.append((a_i,b_i))

	G.add_edge(0,i,1)

CD = []
for j in range(N+1,2*N+1):
	c,d = input().split()
	c_i = int(c)
	d_i = int(d)
	CD.append((c_i,d_i))

	G.add_edge(j,2*N+1,1)


for n in range(1,N+1):
	for m in range(N+1,2*N+1):
		if((AB[n-1])[0]<(CD[m-(N+1)])[0] and (AB[n-1])[1]<(CD[m-(N+1)])[1]):
			G.add_edge(n,m,1)

flow_value = G.dinic(0,2*N+1)
print(int(flow_value))

Solution (Python):
import random
from operator import itemgetter

N = int(input())
AB = []
for i in range(0,N):
	a,b = input().split()
	a_i = int(a)
	b_i = int(b)
	AB.append((a_i,b_i))

CD = []
for j in range(0,N):
	c,d = input().split()
	c_i = int(c)
	d_i = int(d)
	CD.append((c_i,d_i))

CD.sort()
AB.sort()

count = 0
for n in range(0,N):
	list_AB = []
	for m in range(0,len(AB)):

		if((AB[m])[0]<(CD[n])[0]):
			list_AB.append(AB[m])
	
	if(list_AB != []):
		list_AB = sorted(list_AB, key=itemgetter(1))
		list_AB.reverse()

		for q in range(0,len(list_AB)):
			if((list_AB[q])[1]<(CD[n])[1]):
				count += 1
				AB.remove(list_AB[q])
				break

print(count)

Solution (Python):
n = int(input())
R = []
for v in range(n):
    b = tuple(map(int, input().split(' ')))
    R.append(b)
R.sort()
B = []
for v in range(n):
    r = tuple(map(int, input().split(' ')))
    B.append(r)
B.sort()
count = 0
i = 0
while i < n:
    j = 0
    Bmax = -1
    Bind = -1
    while j < len(R) and B[i][0] > R[j][0]:
        if R[j][1] < B[i][1] and Bmax < R[j][1]:
            Bmax = R[j][1]
            Bind = j
        j += 1
    if Bmax != -1:
        del R[Bind]
        count += 1
    i += 1
print(count)

Solution (Python):

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

lst_red.sort(key=lambda x: x[1], reverse=True) 
lst_blue.sort(key=lambda y: y[0]) 

ans = 0



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

print(ans)

Solution (Python):
def m():
    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 y: y[0]) 
    ans = 0
    for b in blue:
        for r in red:
            if r[0] < b[0] and r[1] < b[1]:
                red.remove(r)
                ans +=1
                break
    return ans

print(m())

Solution (Python):
class point:
    def __init__(self,x,y):
        self.x = x
        self.y = y

if __name__ == '__main__':
    N = int(raw_input())
    red = []
    blue = []
    for i in range(N):
        x,y = map(int, raw_input().split())
        red.append(point(x,y))

    for i in range(N):
        x,y = map(int, raw_input().split())
        blue.append(point(x,y))


    blue = sorted(blue, key=lambda k: k.x)
    red = sorted(red, key=lambda k: k.y, reverse=True)
    red_check = [0] * N
    ans = 0
    for b in blue:
        red_pair = None
        is_check = True
        for i, r in enumerate(red):
            if b.x > r.x and b.y > r.y and is_check and red_check[i] == 0:
                red_pair = r
                is_check = False
                red_check[i] = 1

        if red_pair is not None:
            ans += 1

    print(ans)

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

ans = 0
for c, d in sorted(blue, key=lambda x: x[0]):
    for a, b in sorted(red, key=lambda x: x[1], reverse=True):
        if a < c and b < d:
            ans += 1
            red.remove([a, b])
            break
print(ans)

Solution (Python):
def main():
    PointNum = int(input())
    
    rPoint = []
    bPoint = []
    for i in range(PointNum):
        rPoint.append([int(i) for i in input().split()] )
    for i in range(PointNum):
        bPoint.append([int(i) for i in input().split()] )
        


    sorted_rPoint = sorted(rPoint)
    sorted_bPoint = sorted(bPoint)


    
    count = 0
    for bp in sorted_bPoint:
        ans_p = [-1, -1]
        IsAnsFind = False
        for rp in sorted_rPoint:
            if(bp[0]>rp[0] and bp[1]>rp[1]):


                IsAnsFind = True
                if(rp[1] > ans_p[1]):
                    ans_p = rp[:]
        if(IsAnsFind):
            count += 1
            sorted_rPoint.remove(ans_p)
    
    print(count)
    
if __name__=="__main__":
    main()

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])
count = 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]:
            count += 1
            R[j][0] = 1000000
            R[j][1] = 1000000
            B[i][0] = -1
            B[i][1] = -1
            break
print(count)

Solution (Python):
n=int(input())
b=[[int(i) for i in input().split()] for j in range(n)]
a=[[int(i) for i in input().split()] for j in range(n)]
a=sorted(a,key=lambda x:x[0])
b=sorted(b,key=lambda x:x[1],reverse=True)
ans=0

for ai in range(n):
  for bi in range(len(b)):
    if b[bi][0]<a[ai][0] and b[bi][1]<a[ai][1]:
      ans+=1
      del b[bi]
      break
print(ans)

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

ans = 0


for i in range(N):
    redx,redy=red_point[i][0],red_point[i][1]
    for j in range(len(blue_point)):
        
        
        bluex,bluey=blue_point[j][0],blue_point[j][1]
        if redx<bluex and redy<bluey:
            
                
                
            ans +=1
            
            blue_point.pop(j)
            break
print(ans)

Solution (Python):
N = int(input())
R = [list(map(int,input().split())) for k in range(N)]
B = [list(map(int,input().split())) for k in range(N)]
 
R = sorted(R, key = lambda x: -1*x[1])
B = sorted(B)
 
ans = 0
for b in B:
    for r in R:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            R.remove(r)
            break
 
print(ans)

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

Solution (Python):
N=int(input())
graphs = [['' for x in range(2*N)] for x in range(2*N)]
for i in range(N):
  x,y=map(int,input().split())
  graphs[x][y] = 'r'
for j in range(N):
  x,y=map(int,input().split())
  graphs[x][y] = 'b'
rqueue = []
count = 0
for k in range(2*N):
  for l in range(2*N):
    if graphs[k][l] == 'r':
      rqueue.append(tuple([k,l]))
      rqueue.sort(key=lambda x:x[1],reverse=True)
    elif graphs[k][l] == 'b':
      for m in range(len(rqueue)):
        if rqueue[m][0] < k and rqueue[m][1] < l:
          rqueue.pop(m)
          count += 1
          break
print(count)

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 = list(reversed(sorted(red, key=lambda x: x[1])))
blue = sorted(blue)
ans = 0
done = []
for pos in blue:
  i = 0
  while i < n:
    if pos[0] > red[i][0] and pos[1] > red[i][1] and not i in done:
      done.append(i)
      ans += 1
      i += 1
      break
    i += 1

print(ans)

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(key=lambda xy:xy[1], reverse=True)
cd.sort()
ans = 0
for b in cd:
    for r in ab:
        if(r[0] < b[0] and r[1] < b[1]):
            ab.remove(r)
            ans += 1
            break
print(ans)

Solution (Python):
n = int(input())
red = []
blue = []
used_r = [False for _ in range(n)]
used_b = [False for _ in range(n)]
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    red.append((tmp,tmp2))
for i in range(n):
    tmp, tmp2 =  map(int, input().split())
    blue.append((tmp,tmp2))
red = sorted(red, key=lambda x: -1*x[1])
blue = sorted(blue)
cnt = 0
for j in range(n):
    for i in range(n):
        if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            if used_r[i] or used_b[j]:
                continue
            else:
                cnt += 1
                used_r[i] = True
                used_b[j] = True
                break
print(cnt)

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

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

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

print(ans)

Solution (Python):
n = int(input())
red = []
blue = []

for i in range(n):
    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])
    
red_sort = list(reversed(sorted(red, key=lambda y: y[1])))
blue_sort = sorted(blue, key=lambda x: x[0])






pair = []
for blue_point in blue_sort:
    x_blue = blue_point[0]
    y_blue = blue_point[1]
    
    for red_point in red_sort:
        x_red = red_point[0]
        y_red = red_point[1]
        
        if x_red<x_blue and y_red<y_blue:
            if not (red_point in pair) and not (blue_point in pair):
                pair.append(red_point)
                pair.append(blue_point)
    
print(len(pair) // 2)

Solution (Python):
n = input()
x = sorted([map(int,raw_input().split()) for i in range(n)], key=lambda _:-_[1])
y = sorted([map(int,raw_input().split()) for i in range(n)])
used = [False] * n
for i in range(n):
    c, d = y[i]
    for j in range(n):
        a, b = x[j]
        if not used[j] and (a < c) and (b < d):
            used[j] = True
            break
print sum(used)

Solution (Python):
from operator import itemgetter

n = int(input())
red = []
blue = []
ans = 0
for i in range(n):
    red.append(list(map(int, input().split())))
for i in range(n):
    blue.append(list(map(int, input().split())))



blue = sorted(blue, key=itemgetter(0))  
red = sorted(red, key=itemgetter(0))    

for b in blue:
    max_value = -1   
    for r in red:
        if b[0] <= r[0]:  
            break
        else:   
            if max_value < r[1] and b[1] > r[1]:
                max_value = r[1]
                max_obj = r
    if max_value != -1: 
        ans += 1
        red.pop(red.index(max_obj))

print(ans)

Solution (Python):
my_input = input
 
def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]
 
n = int(my_input())
a = []
b = []
for _ in range(n):
    ax, ay = my_input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = my_input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:x[1], reverse=True)
b = sorted(b, key=lambda x:x[0], reverse=False)
ans = 0
ii = set()
for j in range(n):
    for i in range(n):
        if i in ii:
            continue
        if less_than(a[i], b[j]):
            ans += 1
            ii.add(i)
            break
print(ans)

Solution (Python):
N=int(input())
AB=[]
for i in range(N):
    AB.append(list(map(int,input().split())))
CD=[]
for i in range(N):
    CD.append(list(map(int,input().split())))
AB=sorted(AB,key=lambda x:(x[0],x[1]))
CD=sorted(CD,key=lambda x:(x[1],x[0]))
ct=0
for ab in AB[::-1]:
    for i in range(len(CD)):
        cd=CD[i]
        if ab[0]<cd[0] and ab[1]<cd[1]:
            ct+=1
            CD.pop(i)
            break
print(ct)

Solution (Python):
n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])
cd = sorted([[int(i) for i in input().split()] for _ in range(n)])
count = 0
out = []
output = []
for c in cd:
    flag = 0
    for a in ab:
        if a not in output and a[0]<c[0] and a[1]<c[1]:
            out.append(a)
            flag = 1
    if flag == 1:
        output.append(max(out, key=lambda x:x[1]))
        out = []
        count += 1

print(count)

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

ans = 0

for bluex, bluey in blue:
    for redx, redy in red:
        if bluex>redx and bluey>redy:

            red.remove([redx,redy])
            ans+=1
            break

print(ans)

Solution (Python):
my_input = input

def less_than(a, b):
    return a[0] < b[0] and a[1] < b[1]

n = int(my_input())
a = []
b = []
for _ in range(n):
    ax, ay = my_input().split()
    a.append((int(ax), int(ay)))
for _ in range(n):
    bx, by = my_input().split()
    b.append((int(bx), int(by)))
a = sorted(a, key=lambda x:x[1], reverse=True)
b = sorted(b, key=lambda x:x[0], reverse=False)
ans = 0
ii = set()
for j in range(n):
    for i in range(n):
        if i in ii:
            continue
        if less_than(a[i], b[j]):
            ans += 1
            ii.add(i)
            break
print(ans)

Solution (Python):
import numpy as np
n = int(input())

red_x = []
red_y = []
blue_x = []
blue_y = []
for ls in [[red_x,red_y], [blue_x,blue_y]]:
    for i in range(n):
        x, y = map(int, input().split())
        ls[0].append(x)
        ls[1].append(y)
        
red_x = np.array(red_x)
red_y = np.array(red_y)
blue_x = np.array(blue_x)
blue_y = np.array(blue_y)


def abc091c(red_x, red_y, blue_x, blue_y, count):
    if len(blue_x) > 0:
        blue_min_index = np.where(blue_x == min(blue_x))[0][0] 
        x_threshold = blue_x[blue_min_index] 
        y_threshold = blue_y[blue_min_index] 

        enable_pair_indexes = []
        for i, (r_x, r_y) in enumerate(zip(red_x, red_y)):
            if r_x < x_threshold and r_y < y_threshold:
                enable_pair_indexes.append(i)

        if len(enable_pair_indexes) > 0:
            enable_pair_index = np.where(red_y == max(red_y[enable_pair_indexes]))[0][0]
            
            red_x = np.delete(red_x, enable_pair_index)
            red_y = np.delete(red_y, enable_pair_index)
            
            count += 1
            
        
        blue_x = np.delete(blue_x, blue_min_index)
        blue_y = np.delete(blue_y, blue_min_index)
        

        abc091c(red_x, red_y, blue_x, blue_y, count)
    else:
        print(count)

count = 0
abc091c(red_x, red_y, blue_x, blue_y, count)

Solution (Python):
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
red.sort(key=lambda x:x[1], reverse=True)
blue = [list(map(int, input().split())) for i in range(n)]
blue = sorted(blue)
ans = 0
for x_b, y_b in blue:
  for x_r, y_r in red:
    if x_r < x_b and y_r < y_b:
      red.remove([x_r, y_r])
      ans += 1
      break
print(ans)

Solution (Python):
n = int(input())
red = [list(map(int, input().split())) for i in range(n)]
red.sort(key=lambda x:x[1], reverse=True)
blue = [list(map(int, input().split())) for i in range(n)]
blue = sorted(blue)
ans = 0
for x_b, y_b in blue:
  for x_r, y_r in red:
    if x_r < x_b and y_r < y_b:
      red.remove([x_r, y_r])
      ans += 1
      break
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)]

b1 = sorted(b)
r1 = sorted(r, key=lambda x: x[1])[::-1]

cnt = 0
for ib in b1:
    for ir in r1:
        if ir[0] < ib[0] and ir[1] < ib[1]:
            cnt += 1
            r1.remove(ir)
            break
print(cnt)

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(reverse=True)
blue.sort(key=lambda x:x[1])
ans=0
for i in range(n):
    redx,redy=red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey=blue[j][0],blue[j][1]
        if redx<bluex and redy<bluey:
            ans+=1
            blue.pop(j)
            break
print(ans)

Solution (Python):
n = int(input())
red = []
blue = []
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(reverse = True)
blue.sort(key=lambda x:x[1])
ans = 0
for i in range(n):
    redx,redy = red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey = blue[j][0],blue[j][1]
        if redx < bluex and redy < bluey:
            ans += 1
            blue.pop(j)
            break
print(ans)

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

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

answer = 0
for i in B:
    for j in R:
        if i[0]>j[0] and i[1]>j[1]:
            answer += 1
            R.remove(j)
            break
print(answer)

Solution (Python):
N = int(input())
r = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
for p in r:
    p[0],p[1] = p[1], p[0]
r,b = sorted(r, reverse=True), sorted(b)
for i in b:
    for j in r:
        if i[0]>j[1] and i[1] >j[0]:
            ans += 1
            r.remove(j)
            break

print(ans)

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

for i in R:
    i[0],i[1] = i[1],i[0]
R,B = sorted(R)[::-1],sorted(B)

answer = 0
for i in B:
    for j in R:
        if i[0]>j[1] and i[1]>j[0]:
            answer += 1
            R.remove(j)
            break
print(answer)

Solution (Python):






from sys import stdin

def graph(red, blue):
    """
    Return the adjacent list of the bipartite graph that consists of
    the red vertices and the blue vertices.
    The red vertices are numbered as 0, 1, ..., N - 1 and
    the blue vertices are numbered as N, N + 1, ..., 2N - 1.
    The returned list contains 2N elements, each of which is
    the adjacent list of a vertex.
    """
    N = len(red)
    adj = [[] for i in range(2 * N)]
    for i in range(N):
        a, b = red[i]
        for j in range(N):
            c, d = blue[j]
            if a < c and b < d:
                adj[i]    .append(j + N)
                adj[j + N].append(i)
    return adj

def dfs(v, g, M, visited, path):
    if visited[v]: return None
    visited[v] = True
    for u in g[v]:
        w = M[u]
        if w == None: return path + [v, u]
        apath = dfs(w, g, M, visited, path + [v, u])
        if apath != None: return apath
    return None

def augPath(g, M):
    """
    For a graph g and a current matching M,
    return an augmenting path.
    If g does not have an augmenting path, then return None.
    """
    nvertices = len(g)
    for v in range(nvertices):
        if M[v] == None:
            visited = [False for v in range(nvertices)]
            apath = dfs(v, g, M, visited, [])
            if apath != None: return apath
    return None

def solve(red, blue):
    g = graph(red, blue)
    nvertices = len(g)
    
    M = [None for v in range(nvertices)]
    
    while True:
        apath = augPath(g, M)
        if apath == None: break
        
        for i in range(0, len(apath), 2):
            v, u = apath[i : i + 2]
            M[v], M[u] = u, v
    nmatching = sum(1 for m in M if m != None) // 2
    return nmatching

def readIntPairList(N):
    """Read a list of N pairs of ints from stdin."""
    ls = []
    for i in range(N):
        a, b = [int(w) for w in stdin.readline().split()]
        ls.append((a, b))
    return ls

N = int(stdin.readline())
red  = readIntPairList(N)
blue = readIntPairList(N)
print(solve(red, blue))

Solution (Python):
n = int(input())
rc, bc = [], []

for i in range(n):
    rc.append(tuple(map(int, input().split())))

for i in range(n):
    bc.append(tuple(map(int, input().split())))

rc.sort(key=lambda tup: tup[0])
bc.sort(key=lambda tup: tup[0])

pairs = 0
for i in bc:
    pair = (200, -1)
    for j in rc:
        if i[0] < j[0]:
            break
        elif i[1] > j[1] > pair[1]:
            pair = j

    if i[0] > pair[0] and i[1] > pair[1]:
        pairs += 1
        rc.remove(pair)

print(pairs)

Solution (Python):
import bisect

def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in [0] * N]
    CD = [list(map(int, input().split())) for _ in [0] * N]

    AB.sort()
    CD.sort()
    ab = list(map(list, zip(*AB)))
    ans = 0
    for c, d in CD:
        x = bisect.bisect_left(ab[0], c)
        if x:
            y = [(j, i) for i, j in enumerate(ab[1][:x]) if j < d]
            if y:
                maxy = max(y)
                ab[1][maxy[1]] = float('inf')
                ans += 1
    print(ans)

main()

Solution (Python):
n = int(input())
r = [[int(i) for i in input().split()] for i in range(n)]
b = [[int(i) for i in input().split()] for i in range(n)]

for i in r:
	i[0],i[1] = i[1],i[0]
r,b = sorted(r)[::-1],sorted(b)

answer = 0
for i in b:
	for j in r:
		if i[0]>j[1] and i[1]>j[0]:
			answer += 1
			r.remove(j)
			break
print(answer)

Solution (Python):
n = int(input())
reds = [list(int(_) for _ in input().split()) for i in range(n)]
blues = [list(int(_) for _ in input().split()) for i in range(n)]

reds.sort()
blues.sort()

cnt_pair = 0

for i in range(n):
  blue = blues[i]
  
  max_y = -1
  red_idx = -1
  
  for j in range(len(reds)):
    red = reds[j]
    
    if red[0] >= blue[0]:
      break
    
    if red[1] < blue[1] and red[1] > max_y:
      max_y = red[1]
      red_idx = j
    
  if red_idx >= 0:
    reds.pop(red_idx)
    cnt_pair += 1

print(cnt_pair)

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

red = []
blue = []

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

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

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

res = 0

for b in range(n):
    for r in range(len(red)):
        if blue[b][0] > red[r][0] and blue[b][1] > red[r][1]:
            res += 1
            del red[r]
            break

print(res)

Solution (Python):
N = int(input())
a = [list(map(int, input().split())) for i in range(N)]
b = [list(map(int, input().split())) for i in range(N)]
a = sorted(a, key=lambda x: x[1])[::-1]
b = sorted(b)
ans = 0
for n in range(N):
    for i in range(len(b)):
        for j in range(len(a)):
            if b[i][0] > a[j][0]:
                if b[i][1] > a[j][1]:
                    ans+=1
                    del a[j]
                    del b[i]
                    break
        else:
            continue
        break
print(ans)

Solution (Python):
def sort_x(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][0]) < min:
                min = int(a[i][0])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

def sort_y(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][1]) < min:
                min = int(a[i][1])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

if __name__ == '__main__':
    n = int(input())
    a_ = [input().split() for i in range(n)]
    c_ = [input().split() for i in range(n)]
    a = [[0,0] for i in range(n)]
    c = [[0,0] for i in range(n)]
    c = sort_x(c_)
    a = sort_y(a_)
    
    frend_num = 0
    
    
    
    
    filter_a = [1 for i in range(n)]
    for j in range(n):
        for i in reversed(range(n)):
            if filter_a[i]==1 and int(a[i][0])<int(c[j][0]) and int(a[i][1])<int(c[j][1]):
                        filter_a[i]=0
                        frend_num += 1
                        
                        
                        
                        break
    print(frend_num)

Solution (Python):
def sort_x(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][0]) < min:
                min = int(a[i][0])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

def sort_y(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][1]) < min:
                min = int(a[i][1])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

if __name__ == '__main__':
    n = int(input())
    a_ = [input().split() for i in range(n)]
    c_ = [input().split() for i in range(n)]
    a = [[0,0] for i in range(n)]
    c = [[0,0] for i in range(n)]
    c = sort_x(c_)
    a = sort_y(a_)
    
    frend_num = 0
    
    
    
    
    filter_a = [1 for i in range(n)]
    for j in range(n):
        for i in reversed(range(n)):
            if filter_a[i]==1:
                if int(a[i][0])<int(c[j][0]) and int(a[i][1])<int(c[j][1]):
                        filter_a[i]=0
                        frend_num += 1
                        
                        
                        
                        break
    print(frend_num)

Solution (Python):
def sort_x(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][0]) < min:
                min = int(a[i][0])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

def sort_y(a):
    min = 100000
    min_num = 0
    n = len(a)
    A=[[0, 0] for i in range(n)]
    left_list = [1 for i in range(n)]

    for j in range(n):
        for i in range(n):
            if left_list[i]==1 and int(a[i][1]) < min:
                min = int(a[i][1])
                min_num = i
        left_list[min_num] = 0
        A[j] = a[min_num]
        min=100000
    return A

if __name__ == '__main__':
    n = int(input())
    a_ = [input().split() for i in range(n)]
    c_ = [input().split() for i in range(n)]
    a = [[0,0] for i in range(n)]
    c = [[0,0] for i in range(n)]
    c = sort_x(c_)
    a = sort_y(a_)
    
    frend_num = 0
    
    
    
    
    filter_a = [1 for i in range(n)]
    for j in range(n):
        for i in reversed(range(n)):
            
            
            
            if filter_a[i]==1:
                if int(a[i][0])<int(c[j][0]):
                    if int(a[i][1])<int(c[j][1]):
                        filter_a[i]=0
                        frend_num += 1
                        
                        
                        
                        break
    print(frend_num)

Solution (Python):
n = int(input())
ab = sorted([[int(a) for a in input().split()] for _ in range(n)], reverse=True)
cd = sorted([[int(a) for a in input().split()] for _ in range(n)],key=lambda  x:x[1])
count = 0
for c in cd:
    for a in ab:
        if (a[0]<c[0]) and (a[1]<c[1]):
            count += 1
            ab.remove(a)
            break
print(count)