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

R = [()] * N
B = [()] * N

for i in range(N):
    a, b = map(int, input().split())
    R[i] = (a,b)

for i in range(N):
    a, b = map(int, input().split())
    B[i] = (a, b)

B = sorted(B)

ans = 0
for a, b in B:
    d = -1
    mem = -1
    for i in range(len(R)):
        if R[i][0] < a and R[i][1] < b:
            if mem <= b:
                d = i
    if d != -1:
        R.pop(d)
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
r=sorted([list(map(int, input().split())) for _ in range(N)], key=lambda q: q[0])
b=sorted([list(map(int, input().split())) for _ in range(N)], key=lambda q: q[1])
ans=0
for rx,ry in r:
	for i in range(len(b)):
		bx,by=b[i]
		if bx>rx and by>ry:
			ans+=1
			b.pop(i)
			break
print(ans)

Submission status: Wrong Answer

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

R.sort()
B.sort()

C = deepcopy(B)
ans = 0
for i in range(N):
    j = 0
    for b in C:
        if R[i][0] < b[0] and R[i][1] < b[1]:
            ans += 1
            C.pop(j)
            break
        j += 1

tmp = 0
for i in range(N-1, -1, -1):
    j = len(B) - 1
    for b in reversed(B):
        if R[i][0] < b[0] and R[i][1] < b[1]:
            tmp += 1
            B.pop(j)
            break
    j -= 1
print(max(ans, tmp))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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(reverse=1)
CD.sort(reverse=1)
ab = AB.copy()
cd = CD.copy()
ab.sort(reverse=1,key=lambda x:x[1])
cd.sort(reverse=1,key=lambda x:x[1])
AB2 = AB.copy()
CD2 = CD.copy()
CD2.sort()
ab2 = ab.copy()
cd2 = cd.copy()
cd2.sort(key=lambda x:x[1])

def abX():
    ans = 0
    for a,b in AB:
        for c,d in CD:
            if a<c and b<d:
                ans+=1
                CD.remove([c,d])
                break
    return ans

def abY():
    ans = 0
    for a,b in ab:
        for c,d in cd:
            if a<c and b<d:
                ans+=1
                cd.remove([c,d])
                break
    return ans

def abX2():
    ans = 0
    for a,b in AB2:
        for c,d in CD2:
            if a<c and b<d:
                ans+=1
                CD2.remove([c,d])
                break
    return ans

def abY2():
    ans = 0
    for a,b in ab2:
        for c,d in cd2:
            if a<c and b<d:
                ans+=1
                cd2.remove([c,d])
                break
    return ans

print(max(abX(),abY(),abX2(),abY2()))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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(reverse=1)
CD.sort(reverse=1)
ab = AB.copy()
cd = CD.copy()
ab.sort(reverse=1,key=lambda x:x[1])
cd.sort(reverse=1,key=lambda x:x[1])

def abX():
    ans = 0
    for a,b in AB:
        for c,d in CD:
            if a<c and b<d:
                ans+=1
                CD.remove([c,d])
                break
    return ans

def abY():
    ans = 0
    for a,b in ab:
        for c,d in cd:
            if a<c and b<d:
                ans+=1
                cd.remove([c,d])
                break
    return ans

print(max(abX(),abY()))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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(reverse=1)
CD.sort(reverse=1)
ans = 0
for a,b in AB:
    for c,d in CD:
        if a<c and b<d:
            ans+=1
            CD.remove([c,d])
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]

ans = 0

for a,b in AB:
    for c,d in CD:
        if a<c and b<d:
            ans+=1
            CD.remove([c,d])
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
y=sorted([tuple(map(int,input().split()))for i in range(n)])
#print(x)
#print(y)
ans=0
for i in y.copy():
    for j in x.copy():
        s,t=i
        p,q=j
        if p<s and q<t:
            y.remove((s,t))
            x.remove((p,q))
            #print(p,q,s,t)
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([tuple(map(int,input().split()))for i in range(n)])
y=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
#print(x)
#print(y)
ans=0
for j in x.copy():
    for i in y.copy():
        s,t=i
        p,q=j
        if p<s and q<t:
            y.remove((s,t))
            x.remove((p,q))
            #print(p,q,s,t)
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
y=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
#print(x)
#print(y)
ans=0
for i in y.copy():
    for j in x.copy():
        s,t=i
        p,q=j
        if p<s and q<t:
            y.remove((s,t))
            x.remove((p,q))
            #print(p,q,s,t)
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
y=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
#print(x)
#print(y)
ans=0
for i in range(n):
    for j in range(n):
        s,t=y[i]
        p,q=x[j]
        if p<s and q<t:
            #print(p,q,s,t)
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
y=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
print(x)
print(y)
ans=0
for i in range(n):
    for j in range(n):
        s,t=y[i]
        p,q=x[j]
        if p<s and q<t:
            #print(p,q,s,t)
            ans+=1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
y=sorted([tuple(map(int,input().split()))for i in range(n)])[::-1]
#print(x,y)
ans=0
for i in range(n):
    for j in range(n):
        s,t=y[i]
        p,q=x[i]
        if p<s and q<t:
#            print(p,q,s,t)
            ans+=1
            break
print(ans)

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import random
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    ans = 0
    red.sort()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    red.reverse()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    for _ in range(15):
        random.shuffle(red)
        for _ in range(n):
            red = red[-1:] + red[:-1]
            used = [0] * n
            res = 0
            for s, a, b in red:
                near = -1
                d = INF
                for i, (ss, x, y) in enumerate(blue):
                    if a < x and b < y:
                        tmp = x - a + y - b
                        if tmp < d and not used[i]:
                            near = i
                            d = tmp

                if near != -1:
                    used[near] = 1
                    res += 1
            ans = max(ans, res)

    return ans


print(main())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import random
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    ans = 0
    red.sort()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    red.reverse()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    for _ in range(10):
        random.shuffle(red)
        for _ in range(n):
            red = red[-1:] + red[:-1]
            used = [0] * n
            res = 0
            for s, a, b in red:
                near = -1
                d = INF
                for i, (ss, x, y) in enumerate(blue):
                    if a < x and b < y:
                        tmp = x - a + y - b
                        if tmp < d and not used[i]:
                            near = i
                            d = tmp

                if near != -1:
                    used[near] = 1
                    res += 1
            ans = max(ans, res)

    return ans


print(main())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    ans = 0
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    red.reverse()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    red.reverse()
    red.sort()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    red.reverse()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    return ans


print(main())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    red.sort()
    ans = 0
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    red.reverse()
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    return ans


print(main())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    red.sort()
    red.reverse()

    ans = 0
    for _ in range(n):
        red = red[-1:] + red[:-1]
        used = [0] * n
        res = 0
        for s, a, b in red:
            near = -1
            d = INF
            for i, (ss, x, y) in enumerate(blue):
                if a < x and b < y:
                    tmp = x - a + y - b
                    if tmp < d and not used[i]:
                        near = i
                        d = tmp

            if near != -1:
                used[near] = 1
                res += 1
        ans = max(ans, res)

    return ans


print(main())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    red.sort()

    used = [0] * n
    res = 0
    for s, a, b in red:
        near = -1
        d = INF
        for i, (ss, x, y) in enumerate(blue):
            if a < x and b < y:
                tmp = x - a + y - b
                if tmp < d and not used[i]:
                    near = i
                    d = tmp

        if near != -1:
            used[near] = 1
            res += 1

    red.reverse()
    used = [0] * n
    res2 = 0
    for s, a, b in red:
        near = -1
        d = INF
        for i, (ss, x, y) in enumerate(blue):
            if a < x and b < y:
                tmp = x - a + y - b
                if tmp < d and not used[i]:
                    near = i
                    d = tmp

        if near != -1:
            used[near] = 1
            res2 += 1

    res = max(res, res2)

    return res


print(main())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    red = [[a + b, a, b] for a, b in (LI() for _ in range(n))]
    blue = [[a + b, a, b] for a, b in (LI() for _ in range(n))]

    red.sort()
    red.reverse()

    used = [0] * n
    res = 0
    for s, a, b in red:
        near = -1
        d = INF
        for i, (ss, x, y) in enumerate(blue):
            if a < x and b < y:
                tmp = x - a + y - b
                if tmp < d and not used[i]:
                    near = i
                    d = tmp

        if near != -1:
            used[near] = 1
            res += 1

    # print(red)
    # print(blue)

    return res


print(main())

Submission status: Wrong Answer

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

ans = 0
for cd in CD:
    for ab in AB:
        if cd[0] > ab[0] and cd[1] > ab[1]:
            ans += 1
            AB.remove(ab)
            break


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for l in range(N)]
B = [list(map(int,input().split())) for l in range(N)]
A.sort()
B.sort()
for i in range(N):
    a = 0
    b = -1
    for j in range(len(A)):
        if A[j][0]<B[i][0] and A[j][1]<B[i][1]:
           if a<A[j][1]:
              a =A[j][1]  
              b = j
    if b!=-1:
        del A[b]
print(N-len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for l in range(N)]
B = [list(map(int,input().split())) for l in range(N)]
A.sort(key=lambda x:x[0]**2+x[1]**2)
B.sort(key=lambda x:x[0]**2+x[1]**2)
for i in range(N-1,-1,-1):
    a =10**6
    b = -1
    for j in range(len(A)-1,-1,-1):
        if A[j][0]<B[i][0] and A[j][1]<B[i][1]:
            if (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2<a:
                a = (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2
                b = j
    if b!=-1:
        del A[b]
print(N-len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for l in range(N)]
B = [list(map(int,input().split())) for l in range(N)]
A.sort(key=lambda x:x[0]**2+x[1]**2)
B.sort(key=lambda x:x[0]**2+x[1]**2)
for i in range(N):
    a =10**6
    b = -1
    for j in range(len(A)):
        if A[j][0]<B[i][0] and A[j][1]<B[i][1]:
            if (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2<a:
                a = (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2
                b = j
    if b!=-1:
        del A[b]
print(N-len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for l in range(N)]
B = [list(map(int,input().split())) for l in range(N)]
A.sort()
B.sort()
for i in range(N):
    a =10**10
    b = -1
    for j in range(len(A)):
        if A[j][0]<B[i][0] and A[j][1]<B[i][1]:
            if (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2<=a:
                a = (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2
                b = j
    if b!=-1:
        del A[b]
print(N-len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for l in range(N)]
B = [list(map(int,input().split())) for l in range(N)]
A.sort()
B.sort()
for i in range(N):
    a =10**10
    b = -1
    for j in range(len(A)):
        if A[j][0]<B[i][0] and A[j][1]<B[i][1]:
            if (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2<a:
                a = (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2
                b = j
    if b!=-1:
        del A[b]
print(N-len(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for l in range(N)]
B = [list(map(int,input().split())) for l in range(N)]
A.sort()
B.sort()
for i in range(N):
    a =10**6
    b = -1
    for j in range(len(A)):
        if A[j][0]<B[i][0] and A[j][1]<B[i][1]:
            if (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2<a:
                a = (B[i][0]-A[j][0])**2+(B[i][1]-A[j][1])**2
                b = j
    if b!=-1:
        del A[b]
print(N-len(A))

Submission status: Wrong Answer

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

ans = 0
for c, d in CD:
    tmp = -1
    rp = -1
    for i, (a, b) in enumerate(AB):
        if c > a and d > b:
            if b > tmp:
                tmp = b
                rp = i
    if rp >= 0:
        del AB[rp]
        ans += 1


print(ans)

Submission status: Wrong Answer

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


ans = 0
for n in range(N):
    for i, ab in enumerate(AB):
        if ab[0] < CD[0][0] and ab[1] < CD[0][1]:
            ans += 1
            del AB[i]
            CD = CD[1:]
            break


print(ans)

Submission status: Wrong Answer

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


ans = 0
for n in range(N):
    for i, ab in enumerate(AB):
        if ab[0] < CD[0][0] and ab[1] < CD[0][1]:
            ans += 1
            del AB[i]
            del CD[0]
            break


print(ans)

Submission status: Wrong Answer

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


ans = 0
for n in range(N):
    for i, ab in enumerate(AB):
        if ab[0] <= CD[0][0] and ab[1] <= CD[0][1]:
            ans += 1
            del AB[i]
            CD = CD[1:]
            break


print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator

import queue


inf = float('inf')


# globals
N = 0
A, B, C, D = [], [], [], []


def set_inputs():
    global N, A, B, C, D
    N = get_int()
    A, B = get_data(N, [int, int])
    C, D = get_data(N, [int, int])
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    reds = [(a, b) for a, b in zip(A, B)]
    blues = [(c, d) for c, d in zip(C, D)]
    b2r = defaultdict(list)
    for i in range(N):
        for j in range(N):
            a, b = reds[i]
            c, d = blues[j]
            if a < c and b < d:
                b2r[j].append(i)
    r2b = dict()
    for b, rs in b2r.items():
        for r in sorted(rs, key=lambda i: reds[i][1], reverse=True):
            if r2b.get(r, None) is None:
                r2b[r] = b
                break
    print(len(r2b.keys()))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [[0, 0]] * n
b = [[0, 0]] * n
g = [[] for i in range(0, n)]
g_r = [True] * n
g_b = [True] * n
     
for i in range(0, n):
    r[i] = [int(i) for i in input().split(" ")]
for i in range(0, n):
    b[i] = [int(i) for i in input().split(" ")]
     
for i in range(0, n):
    for j in range(0, n):
        if r[i][0] < b[j][0] or r[i][1] < b[j][1]:
            g[i].append(j)
            
c = 0
for i in range(0, n):
  for j in g[i]:
    if g_r[i] and g_b[j]:
      c += 1
      g_r[i] = False
      g_b[j] = False
            
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [[0, 0]] * n
b = [[0, 0]] * n
g = [[] for i in range(0, n)]
g_r = [True] * n
g_b = [True] * n
     
for i in range(0, n):
    r[i] = [int(i) for i in input().split(" ")]
for i in range(0, n):
    b[i] = [int(i) for i in input().split(" ")]
     
for i in range(0, n):
    for j in range(0, n):
        if r[i][0] < b[j][0] and r[i][1] < b[j][1]:
            g[i].append(j)
c = 0
for i in range(0, n):
  for j in g[i]:
    if g_r[i] and g_b[j]:
      c += 1
      g_r[i] = False
      g_b[j] = False
            
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())))
a.sort()
b.sort()
ans = 0
ls = []
for y in b:
    c = []
    for x in a:
        if x[0] < y[0] and x[1] < y[1] and not y in ls:
            c.append(x)
    if len(c) != 0:
        c.sort(reverse=True, key=lambda x: x[1])
        ls.append(c.pop(0))
        ans += 1
print(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())))
a.sort()
b.sort()
ans = 0
ls = []
for y in b:
    c = []
    for x in a:
        if x[0] < y[0] and x[1] < y[1] and not y in ls:
            c.append(y)
    if len(c) != 0:
        c.sort(reverse=True, key=lambda x: x[1])
        ls.append(c.pop(0))
        ans += 1
print(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())))
a.sort()
b.sort()
ans = 0
ls = []
for y in b:
    c = []
    for x in a:
        if x[0] < y[0] and x[1] < y[1] and not y in ls:
            c.append(y)
    if len(c) != 0:
        c.sort(key=lambda x: x[1])
        ls.append(c.pop(0))
        ans += 1
print(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())))
a.sort()
b.sort()
ans = 0
ls = []
for x in a:
    c = []
    for y in b:
        if x[0] < y[0] and x[1] < y[1] and not y in ls:
            c.append(y)
    if len(c) != 0:
        c.sort(key=lambda x: x[1])
        ls.append(c.pop(0))
        ans += 1
print(ans)