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: Wrong Answer

Solution code:
N = int(input())
a = 0
x = []
y = []

for i in range(N):
    s,t = map(int, input().split())
    x.append([s,t])

for j in range(N):
    u,v = map(int, input().split())
    y.append([v,u])

x.sort()
y.sort()

for k in range(N):
    for l in range(len(x)):
        if x[l][0]<y[k][1] and x[l][1]<y[k][0]:
            a += 1
            x.pop(l)
            break



print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0
x = []
y = []

for i in range(N):
    s,t = map(int, input().split())
    x.append([s,t])

for j in range(N):
    u,v = map(int, input().split())
    y.append([v,u])

x.sort()
y.sort()

for k in range(N):
    for l in range(len(x)):
        if x[l][0]<y[k][1] and x[l][1]<y[k][0]:
            a += 1
            x.pop(l)
            break

print(y)

print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0
x = []
y = []

for i in range(N):
    s,t = map(int, input().split())
    x.append([s,t])

for j in range(N):
    u,v = map(int, input().split())
    y.append([v,u])

x.sort()
y.sort()

for k in range(N):
    for l in range(len(y)):
        if x[k][0]<y[l][1] and x[k][1]<y[l][0]:
            a += 1
            y.pop(l)
            break


print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0
x = []
y = []

for i in range(N):
    s,t = map(int, input().split())
    x.append([s,t])

for j in range(N):
    u,v = map(int, input().split())
    y.append([u,v])

x.sort()
y.sort()

for k in range(N):
    for l in range(len(y)):
        if x[k][0]<y[l][0] and x[k][1]<y[l][1]:
            a += 1
            y.pop(l)
            break


print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0
x = []
y = []

for i in range(N):
    s,t = map(int, input().split())
    x.append([s,t])

for j in range(N):
    u,v = map(int, input().split())
    y.append([u,v])

x.reverse()
y.reverse()

for k in range(N):
    for l in range(len(y)):
        if x[k][0]<y[l][0] and x[k][1]<y[l][1]:
            a += 1
            y.pop(l)
            break


print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
for i in range(N):
    R.append(input().split())
    R[i].append(0)
R.sort(key=lambda x:(int(x[0]),-int(x[1])))

B = []
for i in range(N):
    B.append(input().split())
    B[i].append(0)
B.sort(key=lambda x:(int(x[0]),int(x[1])))

a = 0
for i in range(N):
    for j in range(N):
        if int(R[j][0]) < int(B[i][0]) and int(R[j][1]) < int(B[i][1]) and R[j][2] == 0 and B[i][2] == 0:
            a += 1
            R[j][2] = 1
            B[i][2] = 1
            break

print(a)

Submission status: Wrong Answer

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 = sorted(ab, key=lambda x:x[0],reverse=True)
cd = sorted(cd, key=lambda x:x[0])
ab = sorted(ab, key=lambda x:x[1],reverse=True)
cd = sorted(cd, key=lambda x:x[1])

count = 0
i = 0
while i < N:
    for j in range(len(ab)):
        if cd[i][0] > ab[j][0] and cd[i][1] > ab[j][1]:
            count += 1
            del ab[j]
            break
    i += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
red = []
for _ in range(n):
    red.append(na())
blue = []
for _ in range(n):
    blue.append(na())

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

tmp = []
for i in blue:
    for j in red:
        print(j)
        if i[0] > j[0] and i[1] > j[1]:
            tmp.append(j)
    if tmp != []:
        max_red = max(tmp, key=lambda x:x[1])
        ans += 1
        red.remove(max_red)
        tmp = []
    else:
        print("pass")
        pass

print(ans)

Submission status: Wrong Answer

Solution code:
#coding :utf-8
N = int(input())

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


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


memo = [0 for i in range(N)]
memoB = [0 for i in range(N)]

_aka = sorted(aka, key=lambda x: x[0])
_ao = sorted(ao, key=lambda x: x[0])
ans = 0
for j in range(N):
    _i = -1
    _y = -1
    flag = 0
    for i in range(N): 
        if _ao[j][0] > _aka[N-i-1][0] and _ao[j][1] > _aka[N-i-1][1] and memo[N-i-1] == 0:
            if _y < _aka[N-i-1][1]:
                _y = _aka[N-i-1][1]
                _i = N-i-1
    if not _i == -1:
        ans += 1
        memo[N-i-1] = 1
        

print(memo.count(1))

Submission status: Wrong Answer

Solution code:
#coding :utf-8
N = int(input())

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


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


memoA = [0 for i in range(N)]
memoB = [0 for i in range(N)]

_aka = sorted(aka, key=lambda x: x[0])
_ao = sorted(ao, key=lambda x: x[0])
ans = 0
for j in range(N):
    _i = 0
    _y = 0
    flag = 0
    for i in range(N): 
        if _ao[j][0] > _aka[N-i-1][0] and _ao[j][1] > _aka[N-i-1][1] and memoA[N-i-1] == 0:
            if _y < _aka[N-i-1][1]:
                _y = _aka[N-i-1][1]
                _i = N-i-1
                flag = 1
    
    if flag:
        memoA[_i] = 1
        memoB[j] = 1

print(memoA.count(1))

Submission status: Wrong Answer

Solution code:
red = list()
blue = list()
n = int(raw_input())

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

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

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

Submission status: Wrong Answer

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())))
an=sorted(a)
bn=sorted(b)
count=0
for i in range(len(bn)):
    for j in range(len(an)):
#        print(an[j],bn[i])
        if bn[i][0]>an[j][0] and bn[i][1]>an[j][1]:
            count+=1
            an.pop(j)
            break
 
print(count)

Submission status: Wrong Answer

Solution code:
#coding :utf-8
N = int(input())

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


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


memoA = [0 for i in range(N)]
memoB = [0 for i in range(N)]

_aka = sorted(aka, key=lambda x: x[0])
_ao = sorted(ao, key=lambda x: x[0])
ans = 0
for j in range(N):
    _i = 0
    _y = 0
    flag = 0
    for i in range(N): 
        if _ao[j][0] > _aka[N-i-1][0] and _ao[j][1] > _aka[N-i-1][1] and memoA[N-i-1] == 0:
            flag = 1
            if _y < _aka[N-i-1][1]:
                _y = _aka[N-i-1][1]
                _i = N-i-1
    
    if flag:
        memoA[_i] = 1
        memoB[j] = 1

print(memoA.count(1))

Submission status: Wrong Answer

Solution code:
#http://nobuta05.hatenablog.com/entry/2015/11/12/013938

def get_edge(M, u, U=None):

    if U == None:
        for x in M[:]:
            if x[0] == u:
                return x[1]
            elif x[1] == u:
                return x[0]
    else:
        for x in M[:]:
            if x[0] == u and x[1] in U:
                return x[1]
            elif x[1] == u and x[0] in U:
                return x[0]
    return None

def get_nodes(M):
    U = set()
    V = set()
    for x in M:
        U.add(x[0])
        V.add(x[1])
    return (U, V)


def augpath(Si, Ti, M, E):
    (U, V) = get_nodes(M)
    Ti1 = set(x[1] for x in E if x[0] in Si and not x[1] in Ti)
    
    if Ti1 == set():
        return (M, None)

    elif Ti1.difference(V) == set():
        Si1 = set(x[0] for x in M if x[1] in Ti1)
        (M, ui1) = augpath(Si1, Ti.union(Ti1), M, E)

        if ui1 == None:
            return (M, None)

        else:
            v = get_edge(M, ui1)
            M.remove((ui1,v))

            ui = get_edge(E, v, U=Si)
            M.append((ui,v))
            
            return (M, ui)

    else:
        v = Ti1.difference(V).pop()
        u = get_edge(E, v, U=Si)
        M.append((u,v))

        return (M, u)

def Hungary(U0, V0, E):
    U_bef = set()
    M = []
    cnt = 0
    length = len(U0)
    
    # CALC
    while True:

        # INIT
        (U, V) = get_nodes(M)
        u = U0[cnt%length]
        cnt = cnt + 1
        S0 = set()
        S0.add(u)
        T0 = set()

        # 終了条件(すべての頂点から始まる増大道を調べて、マッチング数が変わっていなければ、それ以上増えることはない)
        if cnt % length == 0:
            if U.difference(U_bef) == set():
                break
            U_bef = U.copy()

        # 枝刈り(すでにマッチングしている頂点から始まる道は増大道ではない)
        if u in U:
            continue
        try:
        #CALC
            (M, u) = augpath(S0, T0, M, E)
        except:pass

    return M

#今回の問題分---------------------------------------------------------------------

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

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)
pair.sort(key=lambda x:len(x))

#---------------------------------------------------------------------

E = []
U0 = [x for x in range(len(pair))]
V0 = [x for x in range(n)]


for i in range(len(pair)):
    for j in range(len(pair[i])):
        node1, node2 = i,pair[i][j]
        E.append((node1, node2))

# CALC

edges = Hungary(U0, V0, E)

# OUTPUT
print(len(edges))

Submission status: Wrong Answer

Solution code:
red = list()
blue = list()
n = int(raw_input())

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

blue = sorted(blue, key=lambda x:x[0])

c = int()
for b in blue:
    temp = -1
    ri = -1

    for i,r in enumerate(red):
        if r[0]<b[0] and r[1]<b[1]:
            if r[1] > temp:
                tmp = r[1]
                ri = i
    if ri >= 0:
        red.pop(ri)
        c+=1
print c

Submission status: Wrong Answer

Solution code:
#http://nobuta05.hatenablog.com/entry/2015/11/12/013938
"""
==================================================
二部グラフの最大マッチングを求めるプログラム

# 条件
G = (U,V,E) |U| = |E|

# 入力
U --> 1 2 3 4 .... 10
V --> a b c d .... j
E -->
1 a
1 d
2 b
2 f
etc...

# 出力(最大マッチングの一例)
edges = [(1,a), (2,b), (3 h), ...]

# 定義
def get_edge(M, u, U)    枝集合Mに含まれる枝のうち、頂点uと接している枝の他方の頂点_(1)を返す関数。そのような枝
                         が複数ある場合、一番最初に見つかった頂点を返す。また、引数にUが指定されている場合、(1)
                         を満たし、かつUに含まれる頂点を返す。

def get_nodes(M)         枝集合Mに含まれる枝に関して、左接続の頂点と右接続の頂点に分け、左接続の頂点集合と右接続
                         の頂点集合の二つを返す関数。

def augpath(Si, Ti, M, E)
                         二部グラフにおいて、増大道があるかどうかを判定・処理するプログラム。

==================================================
"""

def get_edge(M, u, U=None):

    if U == None:
        for x in M[:]:
            if x[0] == u:
                return x[1]
            elif x[1] == u:
                return x[0]

    else:
        for x in M[:]:
            if x[0] == u and x[1] in U:
                return x[1]
            elif x[1] == u and x[0] in U:
                return x[0]
    return None

def get_nodes(M):
    U = set()
    V = set()
    for x in M:
        U.add(x[0])
        V.add(x[1])
    return (U, V)


def augpath(Si, Ti, M, E):
    (U, V) = get_nodes(M)
    Ti1 = set(x[1] for x in E if x[0] in Si and not x[1] in Ti)
    
    if Ti1 == set():
        return (M, None)

    elif Ti1.difference(V) == set():
        Si1 = set(x[0] for x in M if x[1] in Ti1)
        (M, ui1) = augpath(Si1, Ti.union(Ti1), M, E)

        if ui1 == None:
            return (M, None)

        else:
            v = get_edge(M, ui1)
            M.remove((ui1,v))

            ui = get_edge(E, v, U=Si)
            M.append((ui,v))
            
            return (M, ui)

    else:
        v = Ti1.difference(V).pop()
        u = get_edge(E, v, U=Si)
        M.append((u,v))

        return (M, u)

def Hungary(U0, V0, E):
    U_bef = set()
    M = []
    cnt = 0
    length = len(U0)
    
    # CALC
    while True:

        # INIT
        (U, V) = get_nodes(M)
        u = U0[cnt%length]
        cnt = cnt + 1
        S0 = set()
        S0.add(u)
        T0 = set()

        # 終了条件(すべての頂点から始まる増大道を調べて、マッチング数が変わっていなければ、それ以上増えることはない)
        if cnt % length == 0:
            if U.difference(U_bef) == set():
                break
            U_bef = U.copy()

        # 枝刈り(すでにマッチングしている頂点から始まる道は増大道ではない)
        if u in U:
            continue
        
        #CALC
        (M, u) = augpath(S0, T0, M, E)
    
    return M

#今回の問題分---------------------------------------------------------------------

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

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)
pair.sort(key=lambda x:len(x))

#---------------------------------------------------------------------

E = []
U0 = [x for x in range(len(pair))]
V0 = [x for x in range(n)]


for i in range(len(pair)):
    try:
        for j in range(len(pair[i])):
            node1, node2 = i,pair[i][j]
            E.append((node1, node2))
    except:
        pass

# CALC
try:
    edges = Hungary(U0, V0, E)
except:
    pass

# OUTPUT
try:
    print(len(edges))
except:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
red=[0]*n
for i in range(n):
    a,b=map(int,input().split())
    red[i]=(a,b)
blue=[0]*n
for i in range(n):
    a,b=map(int,input().split())
    blue[i]=(a,b)
blue.sort()
c=0
for bx,by in blue:
    maxby=-1
    maxi=-1
    for i in range(len(red)):
        rx,ry=red[i]
        if rx < bx and ry < by:
            if maxby < by:
                maxby=by
                maxi=i
    if not maxi == -1:
        c+=1
        red.pop(maxi)
print(c)

Submission status: Wrong Answer

Solution code:
red = list()
blue = list()
n = int(raw_input())
for i in range(0,n):
    red.append(map(int,raw_input().split()))
for i in range(0,n):
    blue.append(map(int, raw_input().split()))

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

c = int()
for b in blue:
    temp = -1
    ri = -1

    for i,r in enumerate(red):
        if r[0]<b[0] and r[1]<b[1]:
            if r[1] > temp:
                tmp = r[1]
                ri = i
    if ri > -1:
        red.pop(ri)
        c+=1
print c

Submission status: Wrong Answer

Solution code:
red = list()
blue = list()
n = int(raw_input())
for i in range(0,n):
    red.append(map(int,raw_input().split()))
for i in range(0,n):
    blue.append(map(int, raw_input().split()))

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

c = int()
for b in blue:
    temp = -1
    ri = -1

    for i,r in enumerate(red):
        if r[0]<b[0] and r[1]<b[1]:
            if r[1] > temp:
                tmp = r[1]
                ri = i
    if ri > -1:
        print red[ri]
        red.pop(ri)
        c+=1
print c

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

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

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

res1 = 0
for blue in blue_array:
    for red in red_array:
        if blue[0] > red[0] and blue[1] > red[1]:
            red_array.remove(red)
            break

print(n - len(red_array))

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

reds = sorted([list(map(int, input().split(' '))) for i in range(N)], key = lambda x: sqrt(x[0] * x[0] + x[1] * x[1]))
blues = sorted([list(map(int, input().split(' '))) for i in range(N)], key = lambda x: sqrt(x[0] * x[0] + x[1] * x[1]))

result = 0

for i in range(N):
    min_dis = 10000000000000
    tmp_index = -1
    length = len(reds)
    for j in range(length):
        if blues[i][0] > reds[j][0] and blues[i][1] > reds[j][1]:
            dis = sqrt(pow(blues[i][0] - reds[j][0], 2) + pow(blues[i][1] - reds[j][1], 2))
            if min_dis > dis:
                min_dis = dis
                tmp_index = j
    if tmp_index != -1:
        result += 1
        reds.pop(tmp_index)

print(result)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

reds = sorted([list(map(int, input().split(' '))) for i in range(N)], key = lambda x: sqrt(x[0] * x[0] + x[1] * x[1]))
blues = sorted([list(map(int, input().split(' '))) for i in range(N)], key = lambda x: sqrt(x[0] * x[0] + x[1] * x[1]))

result = 0

for i in range(N):
    min_dis = 1000000000
    tmp_index = -1
    length = len(reds)
    for j in range(length):
        if blues[i][0] > reds[j][0] and blues[i][1] > reds[j][1]:
            dis = sqrt(pow(blues[i][0] - reds[j][0], 2) + pow(blues[i][1] - reds[j][1], 2))
            if min_dis > dis:
                min_dis = dis
                tmp_index = j
    if tmp_index != -1:
        result += 1
        reds.pop(tmp_index)

print(result)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

reds = sorted([list(map(int, input().split(' '))) for i in range(N)], key = lambda x: sqrt(x[0] * x[0] + x[1] * x[1]))
blues = sorted([list(map(int, input().split(' '))) for i in range(N)], key = lambda x: sqrt(x[0] * x[0] + x[1] * x[1]))

result = 0

for i in range(N):
    min_dis = 100
    tmp_index = -1
    length = len(reds)
    for j in range(length):
        if blues[i][0] > reds[j][0] and blues[i][1] > reds[j][1]:
            dis = sqrt(pow(blues[i][0] - reds[j][0], 2) + pow(blues[i][1] - reds[j][1], 2))
            if min_dis > dis:
                min_dis = dis
                tmp_index = j
    if tmp_index != -1:
        result += 1
        reds.pop(tmp_index)

print(result)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

reds = sorted([list(map(int, input().split(' '))) for i in range(N)])
blues = sorted([list(map(int, input().split(' '))) for i in range(N)])

result = 0

for i in range(N):
    min_dis = 100
    tmp_index = -1
    length = len(reds)
    for j in range(length):
        if blues[i][0] > reds[j][0] and blues[i][1] > reds[j][1]:
            dis = sqrt(pow(blues[i][0] - reds[j][0], 2) + pow(blues[i][1] - reds[j][1], 2))
            if min_dis > dis:
                min_dis = dis
                tmp_index = j
    if tmp_index != -1:
        result += 1
        reds.pop(tmp_index)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

red = []
for i in range(n):
    red.append([int(j) for j in input().split()])
red.sort(key=lambda x : x[1], reverse=True)
print(red)

blue = []
for i in range(n):
    blue.append([int(j) for j in input().split()])
blue.sort()
print(blue)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())

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


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


#print(aka)
#print(ao)


memoA = [0 for i in range(N)]
memoB = [0 for i in range(N)]
ans = 0
'''
for j in range(N):
    for i in range(N):
        if aka[j][0] < ao[i][0] and aka[j][1] < ao[i][1] and memoA[j] == 0 and memoB[i] == 0:
            ans += 1
            memoA[j] = 1
            memoB[i] = 1
'''

'''
ans = 0
buff = 100000000
for j in range(N):
    buff = 10000000
    _i = 0
    _j = 0
    flag = 0
    for i in range(N):
        ans_buff = ao[i][0] - aka[j][0] + ao[i][1] - aka[j][1]
        if buff > ans_buff and ans_buff > 0 and memoA[i] == 0 and memoB[j] == 0 and ao[i][0] - aka[j][0] > 0 and ao[i][1] - aka[j][1] > 0:
            buff = ans_buff
            _i = i
            _j = j
            flag = 1
    if flag == 1:
        ans += 1
        memoA[_i] = 1
        memoB[_j] = 1

'''


'''
_aka = sorted(aka, key=lambda x: x[0]+x[1])
_ao = sorted(ao, key=lambda x: x[0]+x[1])
'''

'''
print()
print(_aka)
print(_ao)
'''

_memo = [0 for n in range(N)]
memo = []
for i in range(N):
    memo.append(_memo.copy())

d = []
dmemo = []

for j in range(N):
    d = []
    for i in range(N):
        if aka[j][0] < ao[i][0] and aka[j][1] < ao[i][1]:
            memo[j][i] = 1
            d.append(i)
    dmemo.append(d)


count_memo = {}

for j in range(N):
    count_memo[j] = memo[j].count(1)

_memo = [0 for n in range(N)]
for k, v in sorted(count_memo.items(), key=lambda x: x[1]):
    if v > 0:
        flag = 0
        for j in dmemo[k]:
            if _memo[j] == 0 and flag == 0:
                _memo[j] = 1
                ans += 1
                flag  = 1
        
    

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
block = [['' for x in range(2*N)] for y in range(2*N)]
for i in range(N):
    tmp = input().split()
    block[int(tmp[0])][int(tmp[1])] = 'R'
for j in range(N):
    tmp = input().split()
    block[int(tmp[0])][int(tmp[1])] = 'B'

queue =[]
count = 0
for j in range(2*N):
    for i in range(2*N):
        if block[i][j] =='R':
            queue.append([i,j])
        elif block[i][j] == 'B' and len(queue) > 0:
            L = len(queue)
            for k in range(L-1,-1,-1):
                if queue[k][0] < i and queue[k][1] < j:
                    block[i][j] = ''
                    queue.pop(k)
                    count += 1
                    break
print(count)

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from collections import deque
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 = deque(sorted(red))
blue = deque(sorted(blue))
count = 0
flag = [0] * N
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1] and flag[i] == 0:
            count += 1
            flag[i] = 1
            break

print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input().strip())
    lines = [input().split() for _ in range(N)]
    a_b = [(int(line[0]), int(line[1])) for line in lines]
    lines = [input().split() for _ in range(N)]
    c_d = [(int(line[0]), int(line[1])) for line in lines]

    # N = 5
    # a_b = [(0, 0), (1, 1), (5, 5), (6, 6), (7, 7)]
    # c_d = [(2, 2), (3, 3), (4, 4), (8, 8), (9, 9)]

    a_b = sorted(a_b)
    c_d = sorted(c_d)

    for c, d in c_d:
        candidates = [(a, b) for a, b in a_b if a < c and b < d]
        if candidates:
            candidates = sorted(candidates, key=lambda ab: ab[1])
            # candidates[0] is best point as the partner of (a, b)
            a_b.remove(candidates[0])

    print(N - len(a_b))

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from collections import deque
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 = deque(sorted(red, key=lambda x:(x[1], x[0]), reverse=True))
blue = deque(sorted(blue))
count = 0
flag = [0] * N
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1] and flag[i] == 0:
            count += 1
            flag[i] = 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

red = []
blue = []
data = []

for a in range(n):
  q = map(int,raw_input().split(" "))
  red.append(q)
  data.append(q)

for a in range(n):
  q = map(int,raw_input().split(" "))
  blue.append(q)
  data.append(q)

red.sort()
blue.sort()
data.sort()

s = []
ans = 0

for a in data:
  if a in red:
    s.append(a)
  else:
    q = None
    y = -1
    for b in s:
      if y < b[1] and b[1] < a[1]:
        q = b
    if q != None:
      s.remove(q)
      ans += 1
print ans

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
B = sorted(B, key = lambda x:x[0])
ans = 0
for b in B:
    tmp = 1000000000
    rp = -1
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            if tmp > r[1]:
                tmp = r[1]
                rp = i
    if rp >= 0:
        R.pop(rp)
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from collections import deque
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 = deque(sorted(red))
blue = deque(sorted(blue))
count = 0
flag = [0] * N
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1] and flag[i] == 0:
            count += 1
            flag[i] = 1

print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input().strip())
    lines = [input().split() for _ in range(N)]
    a_b = [(int(line[0]), int(line[1])) for line in lines]
    lines = [input().split() for _ in range(N)]
    c_d = [(int(line[0]), int(line[1])) for line in lines]

    # N = 5
    # a_b = [(0, 0), (1, 1), (5, 5), (6, 6), (7, 7)]
    # c_d = [(2, 2), (3, 3), (4, 4), (8, 8), (9, 9)]

    a_b = sorted(a_b)
    c_d = sorted(c_d)

    for a, b in a_b:
        candidates = [(c, d) for c, d in c_d if a < c and b < d]
        if candidates:
            candidates = sorted(candidates, key=lambda cd: cd[1])
            # candidates[0] is best point as the partner of (a, b)
            c_d.remove(candidates[0])

    print(N - len(c_d))

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

red = []
blue = []
data = []

for a in range(n):
  q = map(int,raw_input().split(" "))
  red.append(q)
  data.append(q)

for a in range(n):
  q = map(int,raw_input().split(" "))
  blue.append(q)
  data.append(q)

red.sort()
blue.sort()
data.sort()

s = []
ans = 0

for a in data:
  if a in red:
    s.append(a)
  else:
    q = None
    y = -1
    for b in s:
      if y < b[1]:
        q = b
    if q != None:
      s.remove(q)
      ans += 1
print ans

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from collections import deque
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 = deque(red)
blue = deque(blue)
count = 0
flag = [0] * N
for b in blue:
    for i, r in enumerate(red):
        if r[0] < b[0] and r[1] < b[1] and flag[i] == 0:
            count += 1
            flag[i] = 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
block = [['' for x in range(2*N)] for y in range(2*N)]
for i in range(N):
    tmp = input().split()
    block[int(tmp[0])][int(tmp[1])] = 'R'
for j in range(N):
    tmp = input().split()
    block[int(tmp[0])][int(tmp[1])] = 'B'

queue =[]
count = 0
for j in range(2*N):
    for i in range(2*N):
        if block[i][j] =='R':
            queue.append([i,j])
        elif block[i][j] == 'B' and len(queue) > 0:
            L = len(queue)
            for k in range(L):
                if queue[k][0] < i and queue[k][1] < j:
                    block[i][j] = ''
                    queue.pop(k)
                    count += 1
                    break
print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
count_max = 0

def func(ok_list,num_list,loop):
    if loop == N:
        count_tmp = len(num_list)
        global count_max
        if count_tmp > count_max:
            count_max = count_tmp
    else:
        if loop == 0:
            num_list = []
        for l in ok_list[loop]:
            if l not in num_list:
                num_list.append(l)
            func(ok_list,num_list,loop+1)

N = int(input())
RED_list = []
BLUE_list = []
for i in range(N):
    tmp = input().split(" ")
    RED_list.append([int(tmp[0]), int(tmp[1])])

for i in range(N):
    tmp = input().split(" ")
    BLUE_list.append([int(tmp[0]), int(tmp[1])])

RED_list.sort(key=itemgetter(0))
BLUE_list.sort(key=itemgetter(0))

ok_list = []

for l_list in RED_list:
    tmp_list = []
    for m_list in BLUE_list:
        if (l_list[0] < m_list[0])and(l_list[1] < m_list[1]):
            tmp_list.append(BLUE_list.index(m_list))
    ok_list.append(tmp_list)

loop = 0
num_list = []
func(ok_list,num_list,loop)
print(count_max)

Submission status: Wrong Answer

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

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

sr = list(reversed(sorted(red)))
sb = list(reversed(sorted(blue)))
sry = list(reversed(sorted(red, key=lambda tup: tup[1])))
sb = list(reversed(sorted(blue, key=lambda tup: tup[1])))
ans = 0
for i in range(n):

    for j in range(n):
        if(sr[i][0] < sb[j][0] and sr[i][1] < sb[j][1]):
            sb[j] = (-1, -1)
            sr[i] = (2 * n + 1, 2 * n + 1)
            ans += 1
            break
print(ans)