Problem:
Score : 400 points

Problem Statement

On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

All input values are integers.

1 \leq N \leq 100

0 \leq a_i, b_i, c_i, d_i < 2N

a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.

b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

Output

Print the maximum number of friendly pairs.

Sample Input 1

3
2 0
3 1
1 3
4 2
0 4
5 5

Sample Output 1

2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Sample Input 2

3
0 0
1 1
5 2
2 3
3 4
4 5

Sample Output 2

2

For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7

Sample Output 4

5

Sample Input 5

5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9

Sample Output 5

4

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)


#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC091C_2DPlane2NPoints();

#if 1
int main()
{
	ABC091C_2DPlane2NPoints();
	fflush(stdout);
	return 0;
}
#endif

class ABC091C_ball {
public:
	int px = 0;
	int py = 0;
	bool picked = false;
	bool used = true;

	bool isSmall(const ABC091C_ball& a) {
		return ((px < a.px) && (py < a.py));
	}

	static bool asc_dist(const ABC091C_ball& a, const ABC091C_ball& b) {
		return(a.px * a.py < b.px * b.py);
	}
};

static void ABC091C_2DPlane2NPoints()
{
	int N;
	get1int(N);

	auto blues = new ABC091C_ball[N + 1];
	for (int i = 0; i < N; i++) {
		get2int(blues[i].px, blues[i].py);
	}

	auto reds = new ABC091C_ball[N + 1];
	for (int i = 0; i < N; i++) {
		get2int(reds[i].px, reds[i].py);
	}

	std::sort(blues, blues + N, ABC091C_ball::asc_dist);
	std::sort(reds, reds + N, ABC091C_ball::asc_dist);

	auto smaller = new bool[N];
	std::vector<ABC091C_ball> farReds;
	for (int i = 0; i < N; i++) {
		smaller[i] = false;
		for (int j = 0; j < N; j++) {
			if (blues[i].isSmall(reds[j])) {
				smaller[i] = true;
				if (!reds[j].picked) {
					farReds.push_back(reds[j]);
					reds[j].picked = true;
					break;
				}
			}
		}
	}

	int smallBall = 0;
	for (int i = 0; i < N; i++) {
		if (smaller[i]) {
			smallBall++;
		}
	}
	printf("%d\n", tp_min((int)farReds.size(), smallBall));

	delete[] smaller;
	delete[] blues;
	delete[] reds;
}