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



Sample input:
3
2 0
3 1
1 3
4 2
0 4
5 5


Sample output:
2

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())


    class Edge:
        def __init__(self, here, to, weight, rev_edge):
            self.here = here
            self.to = to
            self.weight = weight
            self.rev_edge = rev_edge    # 逆辺への参照

        def __repr__(self):
            return f"|{self.here}->{self.to}({self.weight})|"


    def bipartite_max_matching(adj_list):
        """
        偶数ノードと奇数ノードで二部グラフが構成されているとする
        偶数ノードから奇数ノードへ向かう辺を集めた隣接リストが渡されるので、超入口と出口を追加し、辺を接続し、逆辺も Edge クラスで張った形の隣接リストを作成。
        最大流を求めて最大マッチングを計算する
        """
        n = len(adj_list)
        adj = [[] for _ in range(n+2)]
        # 順辺、逆辺をはる
        for i, elm in enumerate(adj_list):
            for j in elm:
                # 0-index のノードを 1-index 風に変更
                # どちらのエッジからも逆辺への参照を行えるようにしておく
                forward = Edge(i+1, j+1, 1, None)
                backward = Edge(j+1, i+1, 0, forward)
                forward.rev_edge = backward
                adj[i+1].append(forward)
                adj[j+1].append(backward)
        # 超入口、出口を作成し辺をはる
        start_ind = 0
        for i in range(0, n, 2):
            # 0-index のノードを 1-index 風に変更
            forward = Edge(start_ind, i+1, 1, None)
            backward = Edge(i+1, start_ind, 0, forward)
            forward.rev_edge = backward
            adj[start_ind].append(forward)
            adj[i+1].append(backward)
        goal_ind = n + 1
        for i in range(1, n, 2):
            # 0-index のノードを 1-index 風に変更
            forward = Edge(i+1, goal_ind, 1, None)
            backward = Edge(goal_ind, i+1, 0, forward)
            forward.rev_edge = backward
            adj[i+1].append(forward)
            adj[goal_ind].append(backward)
        # import pprint
        # pprint.pprint(adj)
        def dfs():
            path = [Edge(None, start_ind, None, None)]    # 擬似エッジ
            visited = [False] * (n+2)
            visited[start_ind] = 0
            while path:
                previous_e = path[-1]
                u = previous_e.to
                visited[u] = True
                if u == goal_ind:
                    return path[1:]    # 最初の擬似エッジを取り除く
                for e in adj[u]:
                    if not visited[e.to] and e.weight > 0:
                        path.append(e)
                        break
                else:
                    path.pop()
        def update_flow(path):
            maximum_flow = float('inf')
            for e in path:
                maximum_flow = min(maximum_flow, e.weight)
            for e in path:
                e.weight -= maximum_flow    # エッジクラスは参照で渡されているので adj にも変更が反映される
                e.rev_edge.weight += maximum_flow    # どれくらい押し戻せるかが更新される
            return maximum_flow
        # main loop
        flow = 0
        while True:
            # for e in adj:
            #     print(e)
            p = dfs()
            if not p:
                return flow
            else:
                flow += update_flow(p)
                # print(f"path: {list(map(lambda x: x.to - 1, p))[:-1]}, current flow: {flow}")
        

    n = ii()
    red = [lmi() for _ in range(n)]  # 0, 2, 4, 6, ...
    blue = [lmi() for _ in range(n)]  # 1, 3, 5, 7, ...
    # 二部グラフ
    adj = [[] for _ in range(2*n)]
    for i in range(n):
        for j in range(n):
            if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
                adj[i*2].append(j*2+1)
    # import pprint
    # pprint.pprint(adj)

    
    print(bipartite_max_matching(adj))
    

    



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
ab=[map(int,input().split()) for i in range (N)]
a, b = [list(j) for j in zip(*ab)]
cd=[map(int,input().split()) for i in range (N)]
c, d = [list(j) for j in zip(*cd)]
pair_ab=[]
pair_cd=[]
for i in range(N):
  pair_parts_ab = [a[i], b[i]]
  pair_ab.append(pair_parts_ab)
for i in range(N):
  pair_parts_cd = [c[i], d[i]]
  pair_ab.append(pair_parts_cd)
count=0
for i in range(N):
  for j in pair_ab:
     if (c[i]>j[i][0]) and (d[i]>j[i][1]):
        count+=1
        break
print(count)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
import networkx as nx
from networkx.algorithms import bipartite

def main():
    N = int(readline())
    R = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    B = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]

    g = nx.Graph()  # 空の無向グラフを作成
    g.add_nodes_from([i for i in range(N)], bipartite=0)
    g.add_nodes_from([N + i for i in range(N)], bipartite=1)
    edge = []
    for i, (a, b) in enumerate(R):
        for j, (c, d) in enumerate(B):
            if a < c and b < d:
                g.add_edge(i, N+j, weight=1)

    d = nx.max_weight_matching(g)
    for (i, j) in g.edges():
        if ((i, j) not in d) and ((j, i) not in d):
            g.remove_edge(i, j)

    print(len(g.edges()))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
    #できなかった
n=int(input())
r=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 bx by in b:
    index=-1
    ypoint=-1
    for num,(rx,ry) in enumerate(r):
        if bx>rx and by>ry and ypoint < ry:
            ypoint=ry
            index =num
        if ypoint>=0:
            ans+=1
            r.pop(index)
print(ans)

Submission status: Runtime Error

Solution code:

n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(n)]

ab.sort()
cd.sort()

abf = [0]*n
cdf = [0]*n
que = [[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1] and \
        abf[j] == 0 and cdf[i] == 0:
      que[i].append(j)

qn = []
for i in range(n):
  qn.append([i,len(que[i])])
qn.sort()
print(qn)
while len(qn) > 0:
  for i in range(len(qn)):
    for idx in que[qn[i][0]]:
      print(idx)
      if abf[idx] == 0:
        abf[idx] = 1
        qn.pop(i)
  
print(sum(abf))

Submission status: Runtime Error

Solution code:
N=int(input())

max_answer=0
for k in range(101):
  answer=0
  k1=k
  k2=100-k

  red_list=[]
  for i in range(N):
    a,b=map(int,input().split())
    red_list.append((k1*a+k2*b,a,b))
  red_list.sort()

  blue_list=[]
  for i in range(N):
    c,d=map(int,input().split())
    blue_list.append((k1*c+k2*d,c,d))
  blue_list.sort()

  #print(red_list)
  #print(blue_list)

  answer=0
  selected_set=set()
  for i in range(N):
    rs,rx,ry=red_list[i]
    for j in range(N):
      if j in selected_set:
        continue
      bs,bx,by=blue_list[j]
      if rx<bx and ry<by:
        #print((rx,ry),(bx,by))
        selected_set.add(j)
        answer+=1
        break
      
  max_answer=max(max_answer,answer)
  
print(max_answer)

Submission status: Runtime Error

Solution code:
from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
ab = [ list(myinput()) for _ in range(n) ]
cd = [ list(myinput()) for _ in range(n) ]

count = 0
for i in range(n):
    cd_sorted = mysort(cd,0)
    bx = cd[0][0]
    by = cd[0][1]
    cd.remove([bx,by])
    ab_sorted = ab.sort(key=lambda x:x[1],reverse=True)
    for j in range(len(ab_sorted)):
        rx = ab_sorted[j][0]
        ry = ab_sorted[j][1]
        if rx<bx and ry<by:
            count += 1
            break
        else:
            pass
    ab_sorted.remove([rx,ry])
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
ab = [ list(myinput()) for _ in range(n) ]
cd = [ list(myinput()) for _ in range(n) ]

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

count = 0
for i in range(n):
    cd_sorted = mysort(cd,0)
    bx = cd[0][0]
    by = cd[0][1]
    cd.remove([bx,by])
    for j in range(len(ab)):
        rx = ab_sorted[j][0]
        ry = ab_sorted[j][1]
        if rx<bx and ry<by:
            count += 1
            break
        else:
            pass
    ab_sorted.remove([rx,ry])
print(count)

Submission status: Runtime Error

Solution code:
# XとYの二部グラフの最大マッチング X={0,1,2,...|X|-1} Y={0,1,2,...,|Y|-1}
#   edges[x]: xとつながるYの頂点のset
#   matched[y]: yとマッチングされたXの頂点(暫定)
 
def dfs(v, visited):
    """
    :param v: X側の未マッチングの頂点の1つ
    :param visited: 空のsetを渡す（外部からの呼び出し時）
    :return: 増大路が見つかればTrue
    """
    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
 
 
# 標準入力からのグラフ読み取り
n = int(input())

r = [[0,0] for i in range(n)]
for i in range(n) :
  x,y = map(int,input().split())
  r[i][0],r[i][1] = x,y
  
b = [[0,0] for i in range(n)]
for i in range(n) :
  x,y = map(int,input().split())
  b[i][0],b[i][1] = x,y

edges = [set() for _ in range(n)]
matched = [-1] * n
  
for i in range(n) :
  for j in range(n) :
    if r[i][0] < b[j][0] and r[i][1] < b[j][1] :
      edges[i].add(j)
      
# 増大路発見に成功したらTrue(=1)。合計することでマッチング数となる
print(sum(dfs(s, set()) for s in range(xn)))

Submission status: Runtime Error

Solution code:
N = int(input())
ab = []
cd = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([0,a,b])
for i in range(N):
    c,d = map(int,input().split())
    cd.append([0,c,d])

cover = []
for i in range(N):
    cnt = 0
    cov = []
    for j in range(N):
        if ab[j][1] < cd[i][1] and ab[j][2] < cd[i][2]:
            cnt += 1
            cov.append(j)
    cd[i][0] = cnt
    cover.append(cov)

cover.sort()
cd.sort()
cd_dist = []
for i in range(N):
    dist = []
    if cd[i][0] != 0:
        for j in cover[i]:
            d = (ab[j][1]-cd[i][1])**2+(ab[j][2]-cd[i][2])**2
            dist.append([d,j])
        dist.sort()
        cd_dist.append(dist)
    else:
        cd_dist.append([])

flag = [1]*N
ans = 0
for i in range(N):
    for j in range(cd[i][0]):
        if flag[cd_dist[i][j][1]]:
            ans += 1
            flag[cd_dist[i][j][1]] = 0
            break

print(ans)

Submission status: Runtime Error

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

p.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
q.sort(key= lambda x:[x[0]+x[1],x[0],x[1]])
ans=0
i=0
while len(q)>0:
    #print(p,q)
    x = p.pop()
    for y in q[::-1]:
        if x[0]<y[0] and x[1]<y[1]:
            q.remove(y)
            #print(x,y)
            ans+=1
            break
    else:
        pass
    i+=1
    if i >=2*n:
        break
print(ans)

Submission status: Runtime Error

Solution code:
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)):
            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 len(r_lst):
            if rym < r_lst[i][1]:
                rym = r_lst[i][1]
                rym_i = i
        selected.add(i)
    return len(selected)
if __name__ == '__main__':
    print(solve())

Submission status: Runtime Error

Solution code:
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])
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])
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:
            print(a,b,c,d)
            blue.pop(j)
            ans += 1
            break
print(ans)
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])
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])
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)

Submission status: Runtime Error

Solution code:
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(A, key=itemgetter(1),reverse = True)
Blue1 = sorted(B, 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] #これがなかった
            #print(B1[i],A1[j])
            break #これがなかった
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
red = []
blue = []
chosen = [0]*N
ans = 0
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(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if blue[i][0] >= red[j][0] and blue[i][1] >= red[j][1] and chosen[j] == 0
      chosen[j] = 1
      ans += 1
      break
      
print(ans)

Submission status: Runtime Error

Solution code:
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()

#print(AB)
#print(CD)

li = [[] for i in range(N)]

for i in range(N):
    ab = AB[i]
    for j in range(N):
        cd = CD[j]
        if ab[0] < cd[0] and ab[1] < cd[1]:
            li[i].append(cd)

#print(li)

newli = []
for i in range(N):
    if li[i] != []:
        newli.append(li[i])
    else:
        N -= 1

li = newli

ans = 0
while len(li) != 0:
    l = 1000
    
    for i in range(N):
        l = min(l,len(li[i]))

    for i in range(N):
        if len(li[i]) == l:
            rem = li[i].pop()
            li.remove(remli)
            N -= 1
            ans += 1
            break
    

    for j in range(N):
        if rem in li[j]:
            li[j].remove(rem)

    newli = []
    for i in range(N):
        if li[i] != []:
            newli.append(li[i])
        else:
            N -= 1

    li = newli

print(ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

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

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

Submission status: Runtime Error

Solution code:

import bisect

NIL = -1

N = int(input())
A = [NIL] * 101

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

B = [NIL] * 101

for i in range(N):
    nums=list(map(int, input().split())) 
    B[nums[0]] = nums[1]
numA = len(A) - 1
numB = len(B) - 1
cnt = 0
for i in range(N):
    
    while numA >= 0:
        if A[numA] != NIL:
            
            while numB > numA:
                if B[numB] > A[numA]:
                    cnt += 1
                    A[numA] = NIL
                    B[numB] = NIL
                    
                numB -= 1
        numA -= 1
        numB = len(B) - 1
print(cnt)

Submission status: Runtime Error

Solution code:

import bisect

NIL = -1

N = int(input())
A = [NIL] * 101

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

B = [NIL] * 101

for i in range(N):
    nums=list(map(int, input().split())) 
    B[nums[0]] = nums[1]
numA = len(A) - 1
numB = len(B) - 1
cnt = 0
for i in range(N):
    
    while numA >= 0:
        if A[numA] != NIL:
            
            while numB > numA:
                if numB > numA and B[numB] > A[numA]:
                    cnt += 1
                    A[numA] = NIL
                    B[numB] = NIL
                    break
                numB -= 1
        numA -= 1
        numB = len(B) - 1
print(cnt)

Submission status: Runtime Error

Solution code:

import bisect

NIL = -1

N = int(input())
A = [NIL] * 101

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

B = [NIL] * 101

for i in range(N):
    nums=list(map(int, input().split())) 
    B[nums[0]] = nums[1]
numA = 0
numB = 0
cnt = 0
for i in range(N):
    
    while numA < len(A):
        if A[numA] != NIL:
            
            while numB < len(B):
                if numB > numA and B[numB] > A[numA]:
                    cnt += 1
                    A[numA] = NIL
                    B[numB] = NIL
                    break
                numB += 1
        numA += 1
        numB = numA
print(cnt)

Submission status: Runtime Error

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

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

#print(sorted(B))

#below is incorrect 
#count = 0
#for b in B:
#	delta = []
#	for a in A:
#		delta.append([a,[b[1][0] - a[1][0], b[1][1] - a[1][1]]])
	#print(b,delta)
#	cand = [[d[1][0]+d[1][1],d[0][1]] for d in delta if not d[0][0] and d[1][0] > 0 and d[1][1] > 0]
#	if cand:
#		cand = sorted(cand)
#		print(cand)
#		b[0] = True
#		A[A.index([False,cand[0][1]])][0] = True
#		count += 1

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[1][0] > a[1][0] and b[1][1] > a[1][1] not a[0]:
			cand.append(a)
	cand = sorted(cand, key=lambda x:x[1][1], reverse=True)
	if cand:
		#print(b, cand[0])
		b[0] = True
		cand[0][0] = True
		count += 1

print(count)

Submission status: Runtime Error

Solution code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int x;
    int y;
    int flg;
}data;

//x軸の昇順
int xasc(const void* a, const void* b){
    data p = *(data*)a;
    data q = *(data*)b;
    if(p.x!=q.x) return p.x-q.x;
    else return p.y-q.y;
}

//y軸の降順
int ydesc(const void* a, const void* b){
    data p = *(data*)a;
    data q = *(data*)b;
    if(p.y!=q.y) return q.y-p.y;
    else return q.x-p.x;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    data* red;
    NEW(red,N);
    for(int i=0;i<N;i++){
        scanf("%d%d",&red[i].x,&red[i].y);
        red[i].flg=0;
    }
    qsort(red,N,sizeof(data),ydesc);

    data* blue;
    NEW(blue,N);
    for(int i=0;i<N;i++){
        scanf("%d%d",&blue[i].x,&blue[i].y);
        blue[i].flg=0;
    }
    qsort(blue,N,sizeof(data),xasc);

    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(red[j].flg) continue;
            if(red[j].x<blue[i].x && red[j].y<blue[i].y){
                ans++;
                red[j].flg=1;
                break;
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

import numpy as np


def main():
    N = int(input())
    red = np.zeros([N, 3])
    blue = np.zeros([N, 3])

    for i in range(N):
        red[i, 0:2] = list(map(int, input().split()))

    for i in range(N):
        blue[i, 0:2] = list(map(int, input().split()))

    blue[:, 2] = blue[:, 0] + blue[:, 1]
    blue = blue[np.argsort(blue[:, 2])]

    red[:, 2] = red[:, 0] + red[:, 1]
    red = red[np.argsort(blue[:, 2])]

    d = np.zeros([N, 2])
    cnt = 0

    for i in range(N):
        d[0:N, 0] = blue[i, 0] - red[0:N, 0]
        d[0:N, 1] = blue[i, 1] - red[0:N, 1]

        if np.any(d[:, 0] > 0) and np.any(d[:, 1] > 0):
            dd = d[(d[:, 0] > 0) & (d[:, 1] > 0)]
            ind = np.where(d == dd[-1])
            row = ind[0][0]
            red[row, :] = 10**9
            cnt += 1

    print(cnt)


main()

Submission status: Runtime Error

Solution code:
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)]
sab = [[ab[i][0]*ab[i][1],ab[i][0],ab[i][1]] for i in range(N)]
scd = [[cd[i][0]*cd[i][1],cd[i][0],cd[i][1]] for i in range(N)]

sab.sort(reverse=True)
scd.sort(reverse=True)
ans = 0

for i in range(N):
    for j in range(len(ab)):
        if sab[j][1] < scd[i][1] and sab[j][2] < scd[i][2]:
            ans += 1
            del sab[j]
            break
print(ans)

Submission status: Runtime Error

Solution code:
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())))
c=[[] for i in range(n)]
for bi in range(n):
    for ai in range(n):
        if a[ai][0]<b[bi][0] and a[ai][1]<b[bi][1]:
            c[bi].append(a[ai])
z=[]
cin=0
for i in range(n):
    if len(c[i])>0:
        cin+=1
        z+=c[i]
print(min(cin,len(set(z))))

Submission status: Runtime Error

Solution code:
"""
出典:https://atcoder.jp/contests/abc005/tasks/abc005_3
"""
def main():
  N = int(input())
  red_l = [list(map(int,input().split())) for _ in range(N)]
  blue_l = [list(map(int,input().split())) for _ in range(N)]
  red_l=sorted(red_l,key=lambda x:-x[1]s)
  blue_l=sorted(blue_l,key=lambda x:x[0])

  count=0
  for r in red_l:
    for b in blue_l:
      if r[0]<b[0] and r[1]<b[1]:
        count +=1
        blue_l.remove(b)
        break
  print(count)

if __name__=="__main__":
  main()

Submission status: Runtime Error

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

for i in range(n):
  index_list = []
  for j in range(n):
    if blue[j][0]>red[i][0] and blue[j][1]>red[i][1]:
      index_list.append(j)
  red_count.append(index_list)
red_count.sort(key=lambda x: len(x))

def redcounter(count,i,removed_index):
  if i == len(red_count)-1 and set(red_count[i])-set(removed_index):
    return count+1
  elif  i == len(red_count)-1: 
    return count
  
  if red_count[i]:
    for index in range(len(red_count[i])): ## removeするindex
      if red_count[i][index] not in removed_index:
        removed_index_copy = copy.copy(removed_index)
        c = count
        removed_index_copy.append(red_count[i][index])
        c = max(c,redcounter(count,i+1,removed_index_copy))
    return c+1
  else:
    return redcounter(count,i+1,removed_index)
   
print(redcounter(0,0,[]))

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    int_inputs = list(map(string_to_int, inputs))
    N = len(inputs) // 2
    reds = int_inputs[:N]
    blues = int_inputs[N:]

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

    count = 0
    for i in range(N):
        candidates = []
        for j in range(len(blues)):
            if blues[j][0] > reds[i][0] and blues[j][1] > reds[i][1]:
                candidates.append([j, *blues[j]])
        if len(candidates) > 0:
            candidates.sort(key=lambda x: x[2])
            blues.pop(candidates[0][0])
            count += 1

    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N*2))
    print(ret)