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:
#coding:utf-8
import numpy as np
n = int(input())
a = []
b = []
c = []
d = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)
a = np.array(a)
b = np.array(b)
for i in range(n):
    ci, di = list(map(int, input().split()))
    c.append(ci)
    d.append(di)

pair = 0
ab = [False]*n
cd = [False]*n
for i in range(n):
    k = 0
    if max(a) > max(b):
        k = np.argmax(a)
    else:
        k = np.argmax(b)
    if ab[k] == False:
        for j in range(n):
            if a[k] < c[j] and b[k] < d[j] and cd[j] == False:
                pair+=1
                ab[k] = True
                cd[j] = True

print(pair)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [0 for i in range(N)]
b = [0 for i in range(N)]
c = [0 for i in range(N)]
d = [0 for i in range(N)]
for i in range(N):
    a[i],b[i] = map(int,input().split())
for i in range(N):
    c[i],d[i] = map(int,input().split())
cnt = 0
fin = []
for i in range(N):
    f = 0
    s1 = 100000000000
    s2 = 100000000000
    tmp1 = 100000000000
    tmp2 = 100000000000
    for j in range(N):            
        tmp1 = a[i] - c[j]
        tmp2 = b[i] - d[j]
        if tmp1 < 0 and tmp2 < 0:
            s1 = abs(tmp1) + abs(tmp2)
            #print(i,j)
            if s1 < s2 :
                ti = i
                tj = j
                s2 = s1
                f = 1
    if f == 1 and not (j in fin) :
        fin.append(tj)
        cnt += 1
        print(ti,tj)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [0, 0, True] * n
ans = 0
for i in range(0, n):
    line = list(map(int, input().split(" ")))
    data[line[0]] = [line[1], 0, True]
for i in range(0, n):
    line = list(map(int, input().split(" ")))
    data[line[0]] = [line[1], 1, True]
for i in range(0, n):
    kappuru = 0
    if data[i][2]:
        for j in range(i + 1, n*2):
            if data[j][2] and data[i][1] != data[j][1] and data[i][0] < data[j][0]:
                if kappuru == 0:
                    kappuru = j
                elif data[j][0] < data[kappuru][0]:
                    kappuru = j
        if kappuru != 0:
            data[i][2] = False
            data[kappuru][2] = False
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (-a-b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (_, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a < c and b < d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    # abList.reverse()
    # cdList2.reverse()
    for (_, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a < c and b < d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ired = []
iblue = []

for i in range(n):
    a,b = map(int,input().split())
    ired.append([a,b])
    
for i in range(n):
    c,d = map(int,input().split())
    iblue.append([c,d])

red = sorted(ired)
blue = sorted(iblue)


    
x_ans = 0

for i in range(len(red)):
    for j in range(n):
        if (blue[i][0] > red[j][0]) and (blue[i][1] > red[j][1]):
            red[i] = [300,300]
            x_ans += 1
            break
        
red = sorted(ired,key = lambda x:x[1])
blue = sorted(iblue,key = lambda x:x[1])


    
y_ans = 0        
for i in range(len(red)):
    for j in range(n):
        if (blue[i][0] > red[j][0]) and (blue[i][1] > red[j][1]):
            red[i] = [300,300]
            y_ans += 1
            break        

 

   

print(max(x_ans,y_ans))

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, key=lambda x:(x[0],-x[1]),reverse=True)
bn=sorted(b, key=lambda x:(x[0],-x[1]),reverse=True)
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:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (a+b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (_, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a < c and b < d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    # abList.reverse()
    # cdList2.reverse()
    for (_, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a < c and b < d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

Submission status: Wrong Answer

Solution code:
def re_count(x):
    c={}
    for values in x:
        c.setdefault(values,0)
        c[values]+=1
    v=0
    for keys in c:
        v+=min(keys,c[keys])
    return v

N=int(input())
a=[]
b=[]
for i in range(N):
    x,y=input().split()
    a.append(int(x))
    b.append(int(y))
c=[]
d=[]
for i in range(N):
    x,y=input().split()
    c.append(int(x))
    d.append(int(y))
    
num_a={}
num_c={}
for j in range(N):
    for i in range(N):
        if a[j]<c[i] and b[j]<d[i]:
            num_a.setdefault(a[j],0)
            num_a[a[j]]+=1
            num_c.setdefault(c[i],0)
            num_c[c[i]]+=1
            
a=re_count(num_a)
c=re_count(num_c)
        
print(min(a,c))

Submission status: Wrong Answer

Solution code:
N = int(input())

R = []
B = []
for _ in range(N):
    x, y = input().split(' ')
    R.append((int(x),int(y)))

for _ in range(N):
    x, y = input().split(' ')
    B.append((int(x),int(y)))

def greedy(R, B, direction):

    pairs = 0
    rpoints = R.copy()
    bpoints = B.copy()

    rpoints.sort(key=lambda x: x[direction])
    bpoints.sort(key=lambda x: x[direction])

    
    for ri, rp in enumerate(rpoints):
        for bi, bp in enumerate(bpoints):
            if rp[0] >= 0 and rp[0] < bp[0] and rp[1] >= 0 and rp[1] < bp[1]:
                rpoints[ri]=(-1, -1)
                bpoints[bi]=(-1, -1)
                pairs += 1
                break
    return pairs

print(max(greedy(R, B, 0), greedy(R, B, 1)))

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_1 = sorted(red)
blue_1 = sorted(blue)
ans_1 = 0

for i in red_1:
    for j in blue_1:
        if i[0] < j[0] and i[1] < j[1]:
            ans_1 += 1
            blue_1.remove(j)
            break

red.sort()
blue.sort()
red_2 = sorted(red, key=lambda x:sum(x))
blue_2 = sorted(blue, key=lambda x:sum(x))
ans_2 = 0

for i in red_2:
    for j in blue_2:
        if i[0] < j[0] and i[1] < j[1]:
            ans_2 += 1
            blue_2.remove(j)
            break

from operator import itemgetter
red.sort(key=itemgetter(1))
blue.sort(key=itemgetter(1))
ans_3 = 0

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

ans = []
ans.append(ans_1)
ans.append(ans_2)
ans.append(ans_3)
print(max(ans))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())
a = []
b = []
c = []
d = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)

for i in range(n):
    ci, di = list(map(int, input().split()))
    c.append(ci)
    d.append(di)

pair = 0
a.sort()
b.sort()
c.sort()
d.sort()
ab = [False]*n
cd = [False]*n
for i in range(n):
    k = n-i-1
    if ab[k] == False:
        for j in range(n):
            if a[k] < c[j] and b[k] < d[j] and cd[j] == False:
                pair+=1
                ab[k] = True
                cd[j] = True

print(pair)

Submission status: Wrong Answer

Solution code:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (a+b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (_, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a < c and b < d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    abList.reverse()
    cdList2.reverse()
    for (_, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a < c and b < d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = []
    B = []
    C = []
    D = []
    for i in range(N):
        buf1, buf2 = list(map(int, (input().split(' '))))
        A.append(buf1)
        B.append(buf2)
    for i in range(N):
        buf1, buf2 = list(map(int, (input().split(' '))))
        C.append(buf1)
        D.append(buf2)

    def calc_dist(a, b, c, d):
        return pow((pow((c - a), 2) + pow((d - b), 2)), 0.5)

    A_dist_buf = {}
    B_dist_buf = {}
    for i in range(N):
        a_key = str(A[i]) + '_' + str(B[i])
        b_key = str(C[i]) + '_' + str(D[i])
        A_dist_buf[a_key] = calc_dist(0, 0, A[i], B[i])
        B_dist_buf[b_key] = calc_dist(0, 0, C[i], D[i])
    A_dist = sorted(A_dist_buf.items(), key=lambda x: x[1], reverse=True)
    B_dist = sorted(B_dist_buf.items(), key=lambda x: x[1], reverse=True)
#    print(A_dist)
#    print(B_dist)
    A = []
    B = []
    C = []
    D = []
    for key,ele in A_dist:
        A.append(key.split('_')[0])
        B.append(key.split('_')[1])
    for key,ele in B_dist:
        C.append(key.split('_')[0])
        D.append(key.split('_')[1])
    ans1 = 0
    for i in range(N):
        for j in range(N):
            if len(A) <= i or len(C) <= j:
                break
            if ((A[i] < C[j]) and (B[i] < D[j])):
#                print(A[i], B[i], C[j], D[j])
                ans1 += 1
                del C[j], D[j]
                break
    print(ans1)

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

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

Submission status: Wrong Answer

Solution code:
import copy

def main():
    N = int(input())
    abList = []
    cdList = []
    for i in range(N):
        [a, b] = list(map(int, input().split(' ')))
        abList.append( (a+b, a, b) )
    for i in range(N):
        [c, d] = list(map(int, input().split(' ')))
        cdList.append( (c+d, c, d) )
    abList.sort()
    cdList.sort()
    cdList.reverse()
    cdList2 = copy.copy( cdList )
    ans = 0
    for (_, a, b) in abList:
        for i in range( len(cdList) ):
            (_, c, d) = cdList[i]
            if a < c and b < d:
                cdList.pop(i)
                ans += 1
                break
    ans2 = 0
    abList.reverse()
    cdList.reverse()
    for (_, a, b) in abList:
        for i in range( len(cdList2) ):
            (_, c, d) = cdList2[i]
            if a < c and b < d:
                cdList2.pop(i)
                ans2 += 1
                break
    print( max(ans, ans2) )
main()

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = []
    B = []
    C = []
    D = []
    for i in range(N):
        buf1, buf2 = list(map(int, (input().split(' '))))
        A.append(buf1)
        B.append(buf2)
    for i in range(N):
        buf1, buf2 = list(map(int, (input().split(' '))))
        C.append(buf1)
        D.append(buf2)

    def calc_dist(a, b, c, d):
        return pow((pow((c - a), 2) + pow((d - b), 2)), 0.5)

    A_dist_buf = {}
    B_dist_buf = {}
    for i in range(N):
        a_key = str(A[i]) + '_' + str(B[i])
        b_key = str(C[i]) + '_' + str(D[i])
        A_dist_buf[a_key] = calc_dist(0, 0, A[i], B[i])
        B_dist_buf[b_key] = calc_dist(0, 0, C[i], D[i])
    A_dist = sorted(A_dist_buf.items(), key=lambda x: x[1], reverse=True)
    B_dist = sorted(B_dist_buf.items(), key=lambda x: x[1], reverse=True)
#    print(A_dist)
#    print(B_dist)
    A = []
    B = []
    C = []
    D = []
    for key,ele in A_dist:
        A.append(key.split('_')[0])
        B.append(key.split('_')[1])
    for key,ele in B_dist:
        C.append(key.split('_')[0])
        D.append(key.split('_')[1])
    ans1 = 0
    for i in range(N):
        for j in range(N):
            if len(A) <= i or len(C) <= j:
                break
            if ((A[i] <= C[j]) and (B[i] < D[j])) and ((A[i] < C[j]) and (B[i] <= D[j])):
#                print(A[i], B[i], C[j], D[j])
                ans1 += 1
                del C[j], D[j]
                break
    print(ans1)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

a = [''] * N
b = [''] * N
for i in range(N):
    line = input()
    line = line.split(' ')
    a[i] = int(line[0])
    b[i] = int(line[1])

c = [''] * N
d = [''] * N
for i in range(N):
    line = input()
    line = line.split(' ')
    c[i] = int(line[0])
    d[i] = int(line[1])

count = 0
cUsed = [False] * N
dUsed = [False] * N
for i in range(N):
    distance = [10*N] * N
    for j in range(N):
        if cUsed[j] == False and dUsed[j] == False:
            if a[i] < c[j] and b[i] < d[j]:
                distance[j] = int(sqrt(c[j] - a[i]) + sqrt(d[j] - b[i]))
    if min(distance)<10*N:
        # print(i, j, min(distance))
        cUsed[distance.index(min(distance))] = True
        dUsed[distance.index(min(distance))] = True
        count += 1

print (count)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[tuple(map(int,input().split()))for i in range(n)]#red point
y=[tuple(map(int,input().split()))for i in range(n)]#blue point
red=[]
blue=[]
for i in range(n):
    for j in range(n):
        if x[i][0]<y[j][0] and x[i][1]<y[j][1]:
            red.append(x[i])
            blue.append(y[j])
red=list(set(red))
blue=list(set(blue))
red.sort()
blue.sort()
count=0
for i,j in zip(red,blue):
    if i<j:
        count+=1
print(min(count,len(red),len(blue)))

Submission status: Wrong Answer

Solution code:
import random
print(random.randint(0,100000000))

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
red = []
blue = []
for i in range(n):
	x,y = map(int,raw_input().split())
	red.append((x,y));
for i in range(n):
	x,y = map(int,raw_input().split())
	blue.append((x,y));

d = {}

for pr in blue:
	d[pr] = []
	for rr in red:
		if rr[0] < pr[0] and rr[1] < pr[1]:
			d[pr].append(rr);
lst = d.values()
lst.sort(key=len)
dele = {}
for i in red:
	dele[i] = 0;

ans = 0;
for i in lst:
	i.sort(reverse=True)
	for j in i:
		if dele[j] == 0:
			dele[j] = 1;
			ans += 1;
			break;


print ans

Submission status: Wrong Answer

Solution code:
from math import sqrt

N = int(input())

a = [''] * N
b = [''] * N
for i in range(N):
    line = input()
    line = line.split(' ')
    a[i] = int(line[0])
    b[i] = int(line[1])

c = [''] * N
d = [''] * N
for i in range(N):
    line = input()
    line = line.split(' ')
    c[i] = int(line[0])
    d[i] = int(line[1])

count = 0
cUsed = [False] * N
dUsed = [False] * N
for i in range(N):
    distance = [10*N] * N
    for j in range(N):
        if cUsed[j] == False and dUsed[j] == False:
            if a[i] < c[j] and b[i] < d[j]:
                distance[j] = min(sqrt(c[j] - a[i]), sqrt(d[j] - b[i]))
    if min(distance)<10*N:
        # print(i, j, min(distance))
        cUsed[distance.index(min(distance))] = True
        dUsed[distance.index(min(distance))] = True
        count += 1

print (count)

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*s+t*t,s,t])

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

x.reverse()
y.reverse()

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


print(a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = []
b = []
c = []
d = []
lis = []
li = []
nu = 0
for i in range(n):
    an,bn = map(int,input().split())
    a.append(an)
    b.append(bn)
for i in range(n):
    cn,dn = map(int,input().split())
    c.append(cn)
    d.append(dn)
for i in range(n):
    cou = []
    co = []
    for m in range(n):
        print(a[i],c[m],b[i],d[m])
        if a[i] < c[m] and b[i] < d[m]:
            cou.append(str(m))
            co.append(m)
    lis.append(cou)
    li.append(co)
lislis = li
for i in range(n):
    if lis[i] == "":
        lis[i] = "500"
print(lis)
print(li)

for i in range(n):
    aa = 0
    for k in range(n):
        if i in lislis[k]:
            lislis[k].remove(i)
            aa = 1
    print(lislis,"!")

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*s+t*t,s,t])

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

x.reverse()
y.reverse()

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


print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

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

    count = 0

    for i, (a, b) in enumerate(sorted_a_b):
        for j, (c, d) in enumerate(sorted_c_d):
            if (a < c) and (b < d):
                sorted_a_b.pop()
                sorted_c_d.pop()
                count += 1

    print(count)

Submission status: Wrong Answer

Solution code:
import math
import sys
from pprint import pprint

def distance(a,b):
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

def solve(reds, blues):
    ans = []
    while len(blues) != 0:
        blue = blues.pop()
        # print("-----")
        # pprint(reds)
        # pprint(blues)
        red_ans = reds[0]
        min_d = sys.maxsize
        skip_f = False
        for red in reds:
            if blue[0] > red[0] and blue[1] > red[1] and (red, blue) not in ans:
                d = distance(red, blue)
                if min_d == d:
                    skip_f = True
                    break
                if min_d > d:
                    red_ans = red
                    min_d = d
        if skip_f:
            continue
        if min_d != sys.maxsize:
            # print("{} <-> {}".format(red_ans, blue))
            ans.append((red_ans, blue))
            reds.remove(red_ans)
    # pprint(reds)
    # pprint(blues)
    # while len(reds) != 0:
    #     red = reds.pop()
    #     # print("-----")
    #     # pprint(reds)
    #     # pprint(blues)
    #     blue_ans = blues[0]
    #     min_d = sys.maxsize
    #     for blue in blues:
    #         if blue[0] > red[0] and blue[1] > red[1] and (red, blue) not in ans:
    #             d = distance(red, blue)
    #             if min_d > d:
    #                 blue_ans = blue
    #                 min_d = d
    #     if min_d != sys.maxsize:
    #         # print("{} <-> {}".format(red, blue_ans))
    #         ans.append((red, blue_ans))
    #         blues.remove(blue_ans)
    # pprint(ans)
    return len(ans)

if __name__ == '__main__':
    N = int(input())
    reds = []
    for i in range(N):
        a,b = list(map(lambda x: int(x), input().split(" ")))
        reds.append((a,b))
    blues = []
    for i in range(N):
        c,d = list(map(lambda x: int(x), input().split(" ")))
        blues.append((c,d))
    ans = []
    reds.sort()
    blues.sort()
    ans = solve(reds, blues)
    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = []
    B = []
    C = []
    D = []
    for i in range(N):
        buf1, buf2 = list(map(int, (input().split(' '))))
        A.append(buf1)
        B.append(buf2)
    for i in range(N):
        buf1, buf2 = list(map(int, (input().split(' '))))
        C.append(buf1)
        D.append(buf2)

    def calc_dist(a, b, c, d):
        return pow((pow((c - a), 2) + pow((d - b), 2)), 0.5)

    A_dist_buf = {}
    B_dist_buf = {}
    for i in range(N):
        a_key = str(A[i]) + '_' + str(B[i])
        b_key = str(C[i]) + '_' + str(D[i])
        A_dist_buf[a_key] = calc_dist(0, 0, A[i], B[i])
        B_dist_buf[b_key] = calc_dist(0, 0, C[i], D[i])
    A_dist = sorted(A_dist_buf.items(), key=lambda x: x[1], reverse=True)
    B_dist = sorted(B_dist_buf.items(), key=lambda x: x[1], reverse=True)
#    print(A_dist)
#    print(B_dist)
    A = []
    B = []
    C = []
    D = []
    for key,ele in A_dist:
        A.append(key.split('_')[0])
        B.append(key.split('_')[1])
    for key,ele in B_dist:
        C.append(key.split('_')[0])
        D.append(key.split('_')[1])
    ans1 = 0
    for i in range(N):
        for j in range(N):
            if len(A) <= i or len(C) <= j:
                break
            if (A[i] < C[j]) and (B[i] < D[j]):
#                print(A[i], B[i], C[j], D[j])
                ans1 += 1
                del C[j], D[j]
                break
    print(ans1)

Submission status: Wrong Answer

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

cand = []
for b in B:
    temp = []
    for i, r in enumerate(R):
        if r[0] < b[0] and r[1] < b[1]:
            temp.append(i)
    cand.append(temp)

cand = sorted(cand, key=lambda x: len(x))

result = 0
d = [False for _ in range(N)]
while True:
    flag = False
    for c in cand:
        if len(c) == 1:
            flag = True
    cnt = d.count(True)

    if flag:
        for j, c in enumerate(cand):
            if 0 < len(c):
                num = c[0]
                if len(c) == 1 and not d[num]:
                    result += 1
                    d[num] = True
                    for i in cand:
                        if num in i:
                            i.remove(num)
                cand[j] = []
                break
    else:
        cnt = d.count(True)
        for j, c in enumerate(cand):
            if 0 < len(c):
                num = c[0]

                result += 1
                d[num] = True
                for i in cand:
                    if num in i:
                        i.remove(num)
                cand[j] = []
                break

    if cnt == d.count(True):
        break

print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

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

    count = 0

    print(sorted_a_b)
    print(sorted_c_d)

    for i, (a, b) in enumerate(sorted_a_b):
        for j, (c, d) in enumerate(sorted_c_d):
            if (a < c) and (b < d):
                sorted_a_b.pop()
                sorted_c_d.pop()
                count += 1

    print(count)

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*s+t*t,s,t])

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

x.reverse()
y.reverse()

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


print(a)

Submission status: Wrong Answer

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

def main():
  N = GI()
  rs = [LGIS() for _ in range(N)]

  bys = [-1] * 200
  bxs = [-1] * 200

  for _ in range(N):
    c, d = GIS()
    bys[c] = d
    bxs[d] = c

  xpairs = ypairs = 0

  for a, b in rs:
    for x in range(a + 1, 200):
      if bys[x] > b:
        ypairs += 1
        bys[x] = -1
        break

  for a, b in rs:
    for y in range(b + 1, 200):
      if bxs[y] > a:
        #print(a, b, x, bs[x])
        xpairs += 1
        bxs[y] = -1
        break

  print(max(xpairs, ypairs))

main()

Submission status: Wrong Answer

Solution code:
import sys


def spam(ab, cd, count=0):
    ab = ab[:]
    cd = cd[:]
    for x in ab:
        for y in cd:
            if x[0] < y[0] and x[1] < y[1]:
                ab.remove(x)
                cd.remove(y)
                return spam(ab, cd, count + 1)
    return count


def main():
    N = int(sys.stdin.readline())
    ab = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)]
    cd = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)]
    ab1 = sorted(ab, key=lambda x: (x[0], x[1]))
    cd1 = sorted(cd, key=lambda x: (x[0], x[1]))
    ab2 = sorted(ab, key=lambda x: (x[1], x[0]))
    cd2 = sorted(cd, key=lambda x: (x[1], x[0]))
    print(max([spam(ab1, cd1), spam(ab2, cd2)]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
red = [0]*n
blue = [0]*n
for i in range(n):
    red[i] = list(map(int,input().split()))
for i in range(n):
    blue[i] = list(map(int,input().split()))
red.sort()
blue.sort()
p = [[] for j in range(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]):
            p[i].append(j)
q = list(itertools.product(*p))
o = 0
for i in q:
    o = max(o,len(set(i)))
print(o)

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [''] * N
b = [''] * N
for i in range(N):
    line = input()
    line = line.split(' ')
    a[i] = int(line[0])
    b[i] = int(line[1])

c = [''] * N
d = [''] * N
for i in range(N):
    line = input()
    line = line.split(' ')
    c[i] = int(line[0])
    d[i] = int(line[1])

count = 0
cUsed = [False] * N
dUsed = [False] * N
for i in range(N):
    distance = [10*N] * N
    for j in range(N):
        if cUsed[j] == False and dUsed[j] == False:
            if a[i] < c[j] and b[i] < d[j]:
                distance[j] = c[j] - a[i] + d[j] - b[i]
    if min(distance)<10*N:
        # print(i, j, min(distance))
        cUsed[distance.index(min(distance))] = True
        dUsed[distance.index(min(distance))] = True
        count += 1


print (count)

Submission status: Wrong Answer

Solution code:
N = int(input())
aka = [0 for _ in range(N)]
ao = [0 for _ in range(N)]
for i in range(N):
   aka[i] = list(map(int, input().split()))
for i in range(N):
   ao[i] = list(map(int, input().split()))
aka.sort()
ao.sort()

pea = [[0,] for _ in range(N)]
for i in range(N):
   a = aka[i][0]
   b = aka[i][1]
   for j in range(N):
      if (a<ao[j][0])and(b<ao[j][1]):
         pea[i] += [j]
for i in range(N):
   pea[i][0] = len(pea[i])-1
pea.sort()
count = 0
al_pea = []
for p in pea:
   if p[0] != 0:
      for k in p[1:]:
         if (k in al_pea)==False:
            count += 1
            al_pea.append(k)
            break

print(count)