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())
s=[]
t=[]
for i in range(N):
    a,b=map(int,input().split())
    t+=[(a,b)]
for j in range(N):
    c,d=map(int,input().split())
    s+=[(c,d)]
s=sorted(s)
t=sorted(t)
for k in range(N):
    (x,y)=(-1,-1)
    for ii in range(len(t)):
        if s[k][0]>t[ii][0] and s[k][1]>t[ii][1] and y<t[ii][1]:
            (x,y)=t[ii]
    if (x,y) in t:        
        t.remove((x,y))
print(N-len(t))

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

for i in range(N):
    b.append([int(i) for i in input().split()])




sorted_r = sorted(r, key=lambda r:r[1], reverse=True)
sorted_b = sorted(b)



ans = 0
for e1 in sorted_b:
    for e2 in sorted_r:
        if e2[0] < e1[0] and e2[1] < e1[1]:
            ans += 1
            sorted_r.remove(e2)
            break
print(ans)

Solution (Python):
n = int(input())
red_list = []
blue_list = []

for i in range(n):
    x, y = map(int, input().split())
    red_list.append([x, y])
for i in range(n):
    x, y = map(int, input().split())
    blue_list.append([x, y])



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


blue_list.sort(key=lambda x:(x[0], x[1]), reverse=False)


ans = 0
for red in red_list:
    for blue in blue_list:
        if (red[0]<blue[0]) and (red[1]<blue[1]):
            blue_list.remove(blue)
            ans += 1
            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):

n=int(input())
ab=[]
for _ in range(n):
    ax=list((map(int,input().split())))
    ab.append(ax)
cd=[]
for _ in range(n):
    cx=list(map(int,input().split()))
    cd.append(cx)
ans=0
cd=sorted(cd)
ab=sorted(ab,key=lambda x:x[1],reverse=True)
ans=0
for c in cd:
    for a in ab:
        if a[0]<c[0] and a[1]<c[1]:
            ans+=1
            ab.remove(a)
            break
print(ans)

Solution (Python):
from operator import itemgetter

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=sorted(blue)  

red=sorted(red,key=itemgetter(1),reverse=True)

ans = 0

for i in blue:
    for j in red:
        if i[0]>j[0] and i[1]>j[1]:
            ans += 1
            red.remove(j)
            break

print(ans)

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

cnt = 0
for i in blue:
    for j in red:
        if i[0] > j[0] and i[1] > j[1]:
            cnt += 1
            red.remove(j)
            break

print(cnt)

Solution (Python):


N = int(input())

R = []
for i in range(N):
    x, y = list(map(int, input().split()))
    R.append((x, y))

B = []
for i in range(N):
    x, y = list(map(int, input().split()))
    B.append((x, y))

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

ans = 0
for pos in B:
    x, y = pos
    for pos2 in R:
        x2, y2 = pos2
        if x2<x and y2<y:
            R.remove(pos2)
            ans += 1
            break

print(ans)

Solution (Python):
n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
    for num, j in enumerate(blue):
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            del blue[num]
            break
print(ans)

Solution (Python):
n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
    for num, j in enumerate(blue):
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            del blue[num]
            break
print(ans)

Solution (Python):
n = int(input())
red = {}
blue = {}
for i in range(n):
	x, y = map(int, input().split())
	red[x] = y
for i in range(n):
	x, y = map(int, input().split())
	blue[x] = y

sortBlue = sorted(blue.items(), key=lambda x:x[0])
count = 0
for i in range(n):
	pair = {}
	for k, v in red.items():
		if (k < sortBlue[i][0]) and (v < sortBlue[i][1]):
			pair[k] = v
	if pair:
		sortPair = sorted(pair.items(), key=lambda x:-x[1])
		count += 1
		red.pop(sortPair[0][0])
		
print(count)

Solution (Python):
n = int(input())
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            del red[i]
            break
print(ans)

Solution (Python):
n = int(input())
ans = 0
red = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])
blue = sorted([list(map(int, input().split())) for _ in range(n)])
for i in red:
	for num, j in enumerate(blue):
		if i[0] < j[0] and i[1] < j[1]:
			ans += 1
			del blue[num]
			break
print(ans)

Solution (Python):
from operator import itemgetter

N = int(input())
red =[]
red_x = []
blue = []
blue_y = []
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 = itemgetter(0))

red.sort(key = itemgetter(1),reverse = True)
count  = 0
for b in blue:
    for r in red:
        
        if b[0]>=r[0] and b[1]>=r[1]:
                count +=1
                red.remove(r)
                break

print(count)

Solution (Python):


def solver1(N, reds, blues):
	""" 解説を実装
	青点のx座標が最も小さいものは、赤点のy座標の最も大きいものとペアになって良い
	"""
	sorted_reds  = sorted(reds, key=lambda x:x[1], reverse=True)  
	sorted_blues = sorted(blues, key=lambda x:x[0])  
	ans = 0
	for i in range(N):
		for j in range(len(sorted_blues)):
			if (sorted_reds[i][0] < sorted_blues[j][0] and
			    sorted_reds[i][1] < sorted_blues[j][1]):
				ans += 1
				del sorted_blues[j]
				break
	print(ans)

if __name__ == "__main__":
	N = int(input())
	reds  = []
	blues = []
	for i in range(N):
		x, y = list(map(int, input().split()))
		reds.append([x, y])
	for i in range(N):
		x, y = list(map(int, input().split()))
		blues.append([x, y])

	solver1(N, reds, blues)

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

es = [[] for i in range(2*N)]
for ri,(rx,ry) in enumerate(ps[:N]):
    for bi,(bx,by) in enumerate(ps[N:]):
        bi += N
        if rx < bx and ry < by:
            es[ri].append(bi)
            es[bi].append(ri)

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

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

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

print(bipartite_matching())

Solution (Python):
n = int(input())
ans = 0
red = sorted([ list(map(int,input().split())) for _ in range(n) ], key = lambda x : -x[1])
blue = sorted([ list(map(int,input().split())) for _ in range(n) ])
for i in red:
    for num,j in enumerate(blue):
        if i[0] < j[0] and i[1] < j[1]:
            ans += 1
            del blue[num]
            break
print(ans)

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

Red = sorted(Red, key=lambda x: -x[1])
Blue.sort()

res = 0
for i in range(N):
	for j in range(len(Blue)):
		if Red[i][0] < Blue[j][0] and Red[i][1] < Blue[j][1]:
			res += 1
			del Blue[j]
			break

print(res)

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

ans = 0
red = sorted(red, key=lambda tup: tup[1], reverse=True)
blue.sort()

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

print(ans)

Solution (Python):
n = int(input())
reds = []
for i in range(n):
    reds.append(tuple(map(int, input().split())))
reds = sorted(reds, key=lambda tup: tup[1], reverse=True)

blues = []
for i in range(n):
    blues.append(tuple(map(int, input().split())))
blues = sorted(blues, key=lambda tup: tup[0])

count = 0
for b in blues:
    paired = None
    for r in reds:
        if b[0] > r[0] and b[1] > r[1]:
            paired = r
            break
            
    if paired is not None:
        reds.remove(paired)
        count += 1

print(count)

Solution (Python):
n = int(input())
reds = []
for i in range(n):
    reds.append(tuple(map(int, input().split())))
reds = sorted(reds, key=lambda tup: tup[1], reverse=True)

blues = []
for i in range(n):
    blues.append(tuple(map(int, input().split())))
blues = sorted(blues, key=lambda tup: tup[0])

count = 0
for b in blues:
    paired = None
    for i in range(len(reds)):
        r = reds[i]
        if b[0] > r[0] and b[1] > r[1]:
            paired = i
            break
            
    if paired is not None:
        del reds[paired]
        count += 1

print(count)

Solution (Python):
n = int(input())
reds = []
for i in range(n):
    reds.append(tuple(map(int, input().split())))
reds = sorted(reds, key=lambda tup: tup[1], reverse=True)


blues = []
for i in range(n):
    blues.append(tuple(map(int, input().split())))

blues = sorted(blues, key=lambda tup: tup[0])


count = 0
for b in blues:
    tmp = []

    for i in range(len(reds)):
        r = reds[i]
        if b[0] > r[0] and b[1] > r[1]:
            tmp.append(i)
            break
            
    if len(tmp) > 0:
        del reds[tmp[0]]
        count += 1

print(count)

Solution (Python):
n=int(input())
a=sorted([list(map(int,input().split())) for i in range(n)])
b=sorted([list(map(int,input().split())) for i in range(n)])
ans=0
for i in range(n):
    flag=0
    res=float("inf")
    for j in range(len(a)): 
        if b[i][0]>a[j][0]:
            if 0<b[i][1]-a[j][1]<res:
                res=b[i][1]-a[j][1]
                ind=j
                flag=1
    if flag:
        a.pop(ind)
        ans+=1
print(ans)

Solution (Python):
N = int(input().rstrip())
red = []
for i in range(N):
    a, b = input().rstrip().split()
    red.append((int(a), int(b)))
red.sort(key=lambda y: y[1], reverse=True)
blue = []
for i in range(N):
    a, b = input().rstrip().split()
    blue.append((int(a), int(b)))
blue.sort(key=lambda x: x[0])



i = 0
while len(blue) > i:
    for j in red:
        if j[0] < blue[i][0] and j[1] < blue[i][1]:
            del blue[i]
            red.remove(j)
            break
    else:
        i += 1
    

print(N - len(red))

Solution (Python):
N=int(raw_input())
ab=[]
cd=[]
for i in xrange(N):
 ab.append(map(int,raw_input().split()))
for i in xrange(N):
 cd.append(map(int,raw_input().split()))
ab.sort(key=lambda x:x[1],reverse=True)
cd.sort()
for c,d in cd:
 for a,b in ab:
  if a<c and b<d:
   ab.remove([a,b])
   break
print N-len(ab)

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

blue2 = sorted(blue, key=lambda x: x[0])
count = 0
for k in blue2:
    temp = -1
    pop = -1
    num = -1
    for l in red:
        num += 1
        if l[1] < k[1] and l[0] < k[0]:
            if l[1] > temp:
                temp = l[1]
                pop = num
    if temp >= 0:
        red.pop(pop)
        count += 1
print(count)

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

blue2 = sorted(blue, key=lambda x: x[0])
count = 0
for k in blue2:
    temp = -1
    pop = -1
    num = -1
    for l in red:
        num += 1
        if l[1] < k[1] and l[0] < k[0]:
            if l[1] > temp:
                temp = l[1]
                pop = num
    if temp >= 0:
        red.pop(pop)
        count += 1
print(count)

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

red_points = [[int(i) for i in input().split()] for j in range(N)]

blue_points = [[int(i) for i in input().split()] for j in range(N)]

red_points.sort()
blue_points.sort()
count = 0
distance = 9999
for blue_point in blue_points:
    tmp = [i for i in red_points if blue_point[0] > i[0] and blue_point[1] > i[1]]
    if tmp:
        for j in tmp:
            if (blue_point[1] - j[1]) < distance:
                distance = blue_point[1] - j[1]
                min_red = j
        count = count + 1
        red_points.remove(min_red)
        distance = 9999

print(count)

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

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

Solution (Python):
N = int(input())
red, blue = [], []
for _ in range(N):
    red.append(tuple(int(i) for i in input().split()))
for _ in range(N):
    blue.append(tuple(int(i) for i in input().split()))
ans = 0

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

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

print(ans)

Solution (Python):
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
  N = GI()

  l = []

  for color in 'r', 'b':
    for _ in range(N):
      x, y = GIS()
      l.append((x, y, color))

  l.sort()
  rys = [0] * 200
  count = 0
  for x, y, c in l:
    if c == 'r':
      rys[y] = 1
    else:
      found = None
      for i in range(y):
        if rys[i]:
          found = i
      if found is not None:
        rys[found] = 0
        count += 1

  print(count)

main()

Solution (Python):

"""
C - 2D Plane 2N Points
https://beta.atcoder.jp/contests/abc091/tasks/arc092_a

"""
import sys
from sys import stdin
from collections import namedtuple, deque
input = stdin.readline


edge = namedtuple('edge', ['to', 'cap', 'rev'])

def add_edge(G, f, t, c):
    G[f].append(edge(t, c, len(G[t])))
    G[t].append(edge(f, 0, len(G[f]) - 1))


def bfs(G, level, s):
    for i in range(len(level)):
        level[i] = -1
    que = deque()
    level[s] = 0
    que.append(s)
    while que:
        v = que.popleft()
        for e in G[v]:
            if e.cap > 0 and level[e.to] < 0:
                level[e.to] = level[v] + 1
                que.append(e.to)


def dfs(G, iter, level, v, t, f):
    if v == t:
        return f
    for i in range(iter[v], len(G[v])):
        e = G[v][i]
        if e.cap > 0 and level[v] < level[e.to]:
            d = dfs(G, iter, level, e.to, t, min(f, e.cap))
            if d > 0:
                G[v][i] = edge(e.to, e.cap - d, e.rev)
                G[e.to][e.rev] = edge(G[e.to][e.rev].to, G[e.to][e.rev].cap + d, G[e.to][e.rev].rev)
                return d
    return 0


def max_flow(G, V, s, t):
    level = [0] * V
    flow = 0
    while True:
        bfs(G, level, s)
        if level[t] < 0:
            return flow
        iter = [0] * V
        while True:
            f = dfs(G, iter, level, s, t, float('inf'))
            if f > 0:
                flow += f
            else:
                break


def main(args):
    """
    - 追加したソースノードID: 0
    - 赤い点ID: 1〜N
    - 青い点ID: N+1 〜2N
    - 追加したシンクノードID: 2N + 1(2N + 2 - 1)
    として、ノード0 → 2N+1 への最大流を求める
    """
    N = int(input())
    G = [[] for _ in range(N*2 + 2)]
    red_points = []
    for ri in range(1, N+1):
        rx, ry = map(int, input().split())
        red_points.append([rx, ry])
        add_edge(G, 0, ri, 1)   

    for bi in range(1, N+1):
        bx, by = map(int, input().split())
        add_edge(G, bi+N, N*2+1, 1) 
        for i, r in enumerate(red_points, start=1):
            rx = r[0]
            ry = r[1]
            if rx < bx and ry < by:
                add_edge(G, i, bi+N, 1) 

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


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
N = int(input())
a = []
b = []
for i in range(N):
    a.append(list(map(int, input().split())))
for i in range(N):
    b.append(list(map(int, input().split())))
a_sorted = sorted(a, key = lambda x:-x[1])
b_sorted = sorted(b)

ans = 0
for i in range(len(b_sorted)):
    for j in range(len(a_sorted)):
        if(b_sorted[i][0] > a_sorted[j][0] and b_sorted[i][1] > a_sorted[j][1]):
            ans += 1
            a_sorted.pop(j)
            break
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(reverse=True)
CD.sort()

AB_used = set()
CD_used = set()
for index_ab, ab in enumerate(AB):
    mx = float('inf')
    my = float('inf')
    i = -1
    j = -1
    if index_ab in AB_used:
        continue
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_used:
            continue
        if (ab[0] < cd[0]) & (ab[1] < cd[1]) & (cd[1] < my) & (cd[0] < mx):
            i, j = index_ab, index_cd
            my = cd[1]
    if (i != -1) & (j != -1):
        AB_used.add(i)
        CD_used.add(j)

print(len(AB_used))

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(reverse=True)
CD.sort()

AB_used = set()
CD_used = set()
for index_ab, ab in enumerate(AB):
    my = float('inf')
    i = -1
    j = -1
    if index_ab in AB_used:
        continue
    for index_cd, cd in enumerate(CD):
        if index_cd in CD_used:
            continue
        if (ab[0] < cd[0]) & (ab[1] < cd[1]) & (cd[1] < my):
            i, j = index_ab, index_cd
            my = cd[1]
    if (i != -1) & (j != -1):
        AB_used.add(i)
        CD_used.add(j)

print(len(AB_used))

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

    
    

    
    


def prepare_points(N, color_str):
    points = []
    for i in range(N):
        tmp = input().split()
        x, y = int(tmp[0]), int(tmp[1])
        point = Point(x, y)
        points.append((point, color_str))
    return points


def main():
    N = int(input())
    red_points = prepare_points(N, 'r')
    blue_points = prepare_points(N, 'b')
    sorted_ = sorted((red_points + blue_points), key=lambda x: x[0].x)
    uses = set()
    count = 0
    for item in sorted_:
        if item[1] == 'r':
            uses.add(item)
        else:
            reds = {
                foo
                for foo in uses if foo[1] == 'r' and foo[0].y < item[0].y
            }
            
            if not reds:
                continue
            max_p = max(reds, key=lambda x: x[0].y)
            if max_p[0].y < item[0].y:
                uses.remove(max_p)
                count += 1
    
    
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):






def get_candidate_points(sorted_a_b: list, c: int, d: int) -> list:
    candidate_a_b = [x for x in sorted_a_b if (x[0] < c) and (x[1] < d)]
    return sorted(candidate_a_b, key=lambda x: (x[1], x[0]), reverse=True)


if __name__ == '__main__':
    number = int(input())

    a_b = [list(map(int, input().split())) for _ in range(number)]
    c_d = [list(map(int, input().split())) for _ in range(number)]
    sorted_a_b = sorted(a_b, key=lambda x: (x[0], x[1]))
    sorted_c_d = sorted(c_d, key=lambda y: (y[0], y[1]))
    count = 0

    for c, d in sorted_c_d:
        points = get_candidate_points(sorted_a_b, c, d)

        if len(points) >= 1:
            sorted_a_b.remove(points[0])
            count += 1

    print(count)

Solution (Python):




import collections
class Dinic:

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

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

    def add_multi_edge(self, v1, v2, cap1, cap2):
        self.g[v1].append([v2, cap1, len(self.g[v2])])
        self.g[v2].append([v1, cap2, len(self.g[v1])-1])

    def bfs(self, s):
        level = [-1]*self.n
        deq = collections.deque()
        level[s] = 0
        deq.append(s)
        while deq:
            v = deq.popleft()
            for e in self.g[v]:
                if e[1]>0 and level[e[0]]<0:
                    level[e[0]] = level[v] + 1
                    deq.append(e[0])
        self.level = level

    def dfs(self, v, t, f):
        if v==t: return f
        es = self.g[v]
        level = self.level
        for i in range(self.it[v], len(self.g[v])):
            e = es[i]
            if e[1]>0 and level[v]<level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d>0:
                    e[1] -= d
                    self.g[e[0]][e[2]][1] += d
                    self.it[v] = i
                    return d
        self.it[v] = len(self.g[v])
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0: break
            self.it = [0]*self.n
            while True:
                f = self.dfs(s, t, 10**9+7)
                if f>0:
                    flow += f
                else:
                    break
        return flow






n=int(input())
s=[]
ss=[]
for i in range(n):
    s.append([int(i) for i in input().split()])
    
for i in range(n):
    ss.append([int(i) for i in input().split()])

pair=[]
for i in range(len(s)):
    right=[]
    for j in range(n):    
        if s[j][0]<ss[i][0] and s[j][1]<ss[i][1]:
            right.append(j)
    pair.append(right)








V=len(pair)+n+2 

dinic = Dinic(V)

for i in range(len(pair)): 
    u, v, c = 0, i+1, 1
    dinic.add_edge(u, v, c)
            
for i in range(n): 
    u, v, c = i+len(pair)+1, V-1, 1
    dinic.add_edge(u, v, c)    
    
for i in range(len(pair)): 
    for j in range(len(pair[i])):
        node1, node2 = i+1,pair[i][j]+len(pair)+1
        
        u, v, c = node1, node2, 1
        dinic.add_edge(u, v, c)
        
print (dinic.max_flow(0, V-1))     




"""
元々のinput
V, E =  [int(i) for i in input().split()]

dinic = Dinic(V)

for i in range(E):
    u, v, c = [int(i) for i in input().split()]
    dinic.add_edge(u, v, c)

print (dinic.max_flow(0, V-1))
"""

Solution (Python):


def solve(abs, cds):
    abs = sorted(abs, key = lambda x: -1 * x[1]) 
    cds = sorted(cds, key = lambda x: x[0]) 

    count = 0
    for r in cds:
        _abs = list(filter(lambda x: r[0] > x[0] and r[1] > x[1], abs))
        if len(_abs) == 0:
            continue
        del abs[abs.index(_abs[0])]
        count += 1
    return count

if __name__ == '__main__':
    N = int(input())
    abs = []
    cds = []
    for _ in range(N):
        abs = abs + [list(map(lambda x: int(x), input().split()))] 
    for _ in range(N):
        cds = cds + [list(map(lambda x: int(x), input().split()))] 

    print(solve(abs, cds))

Solution (Python):

"""
C - 2D Plane 2N Points
https://beta.atcoder.jp/contests/abc091/tasks/arc092_a

"""
import sys
from sys import stdin
from collections import namedtuple
input = stdin.readline
edge = namedtuple('edge', ['to', 'cap', 'rev'])


def add_edge(G, f, t, c):
    G[f].append(edge(t, c, len(G[t])))
    G[t].append(edge(f, 0, len(G[f]) - 1))


def dfs(G, used, v, t, f):
    if v == t:
        return f
    used[v] = True
    for i in range(len(G[v])):
        e = G[v][i]
        if (not used[e.to]) and (e.cap > 0):
            d = dfs(G, used, e.to, t, min(f, e.cap))
            if d > 0:
                G[v][i] = edge(e.to, e.cap - d, e.rev)
                G[e.to][e.rev] = edge(G[e.to][e.rev].to, G[e.to][e.rev].cap + d, G[e.to][e.rev].rev)
                return d
    return 0


def max_flow(G, V, s, t):
    used = [False] * V
    flow = 0
    while True:
        for i in range(len(used)):
            used[i] = False
        f = dfs(G, used, s, t, float('inf'))
        if f == 0:
            return flow
        flow += f


def main(args):
    N = int(input())
    G = [[] for _ in range(N*2 + 2)]
    red_points = []
    for ri in range(1, N+1):
        rx, ry = map(int, input().split())
        red_points.append([rx, ry])
        add_edge(G, 0, ri, 1)

    for bi in range(1, N+1):
        bx, by = map(int, input().split())
        add_edge(G, bi+N, N*2+1, 1)
        for i, r in enumerate(red_points, start=1):
            rx = r[0]
            ry = r[1]
            if rx < bx and ry < by:
                add_edge(G, i, bi+N, 1)

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


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):


N=int(raw_input())
ab=[]
cd=[]
for i in xrange(N):
 ab.append(map(int,raw_input().split()))
for i in xrange(N):
 cd.append(map(int,raw_input().split()))
ab.sort(key=lambda x:x[1],reverse=True)
cd.sort()
for c,d in cd:
 for a,b in ab:
  if a<c and b<d:
   ab.remove([a,b])
   break
print N-len(ab)

Solution (Python):
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    b.append(list(map(int,input().split())))
an=sorted(a, key=lambda x:-x[1])
bn=sorted(b)

count=0
for i in range(len(bn)):
    for j in range(len(an)):
        
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            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.sort(key=lambda x:x[1], reverse=True)
blue.sort()

c = 0
for bx, by in blue:
    for i, (rx, ry) in enumerate(red):
        if rx<bx and ry<by:
            c += 1
            red.pop(i)
            break

print(c)

Solution (Python):
red_p = []
blue_p = []
count = 0
n = int(input())
for i in range(n):
    a_ad, b_ad = map(int, input().split())
    red_p.append((a_ad, b_ad))
for i in range(n):
    c_ad, d_ad = map(int, input().split())
    blue_p.append((c_ad, d_ad))
red_p.sort(key = lambda x: x[1], reverse = True)
blue_p.sort()
for i in range(n):
    l = len(red_p)
    for k in range(l):
        if red_p[k][1] < blue_p[i][1] and red_p[k][0] < blue_p[i][0]:
            count += 1
            red_p = red_p[:k] + red_p[k+1:]
            break
print(count)

Solution (Python):





num=201 

def dfs(cur):
	global vis
	global EE
	vis[cur] = 1

	if cur==num:
		return 1

	for i in range(num+1):
		if vis[i]==0 and EE[cur][i]>0 and dfs(i) > 0:
			EE[cur][i] -= 1
			EE[i][cur] += 1
			return 1
	return 0




n=int(input())
s=[]
ss=[]
for i in range(n):
    s.append([int(i) for i in input().split()])
for i in range(n):
    ss.append([int(i) for i in input().split()])



pair=[]
for i in range(len(s)):
    right=[]
    for j in range(n):    
        if s[j][0]<ss[i][0] and s[j][1]<ss[i][1]:
            right.append(j)
    pair.append(right)








EE = [[0 for x in range(num+1)] for y in range(num+11)]
vis = [0] * (num+1)

for i in range(len(pair)): 
	EE[0][i+1] = 1


for i in range(n): 
	EE[i+101][num] = 1

for i in range(len(pair)): 
    for j in range(len(pair[i])):
        node1, node2 = i+1,pair[i][j]+101

        EE[node1][node2] = 1



flow=0
while 1:
    for i in range(0, num+1):
        vis[i] = 0
    if dfs(0) == 0:
        break
    flow += 1

print (flow)

Solution (Python):





num=201 

def dfs(cur):
	global vis
	global EE
	vis[cur] = 1

	if cur==num:
		return 1

	for i in range(num+1):
		if vis[i]==0 and EE[cur][i]>0 and dfs(i) > 0:
			EE[cur][i] -= 1
			EE[i][cur] += 1
			return 1
	return 0




n=int(input())
s=[]
ss=[]
for i in range(n):
    s.append([int(i) for i in input().split()])
for i in range(n):
    ss.append([int(i) for i in input().split()])



pair=[]
for i in range(len(s)):
    right=[]
    for j in range(n):    
        if s[j][0]<ss[i][0] and s[j][1]<ss[i][1]:
            right.append(j)
    pair.append(right)








EE = [[0 for x in range(num+1)] for y in range(num+11)]
vis = [0] * (num+1)

for i in range(len(pair)): 
	EE[0][i+1] = 1
	EE[i+1][0] = 1

for i in range(n): 
	EE[i+101][num] = 1

for i in range(len(pair)): 
    for j in range(len(pair[i])):
        node1, node2 = i+1,pair[i][j]+101

        EE[node1][node2] = 1



flow=0
while 1:
    for i in range(0, num+1):
        vis[i] = 0
    if dfs(0) == 0:
        break
    flow += 1

print (flow)