Radioactive cubes
Difficulty: Hard

You have been hired by a company to develop a software to solve the following problem.

There are N radioactive objects with cubic shape. They are in three dimensions with a particular length, width, and height. Also, there are M holes in the ground with rectangular shape. The company needs to bury the radioactive cubes in the ground. Therefore, the company wants to know what is the maximum amount of radioactive cubes can be buried into holes.

Only one radioactive cube can be put in each hole because radioactive cubes might react with each other and explode.
The depth of each hole is negligible. The cubes can be rotated.

**Input format**

The first line contains two integers, N the amount of cubes and M, the amount of holes.
Next follow N lines. Each line contains three numbers A,B,C, the dimensions of each cube. Next follow M lines. Each line contains two numbers D, E the dimensions of each hole .

**Constraints**

1 &le; N,  M &le; 1000  
0.00 &le; A, B, C &le; 10.00  
0.00 &le; D, E &le; 10.00  

**Output format**

The output will consist of one single line, the maximum number of radioactive cubes can be introduced into the holes.

**Sample input**

    2 2
    3.00 2.00 2.00
    2.00 2.00 3.00
    2.00 2.00
    1.00 1.00

**Sample output**

    1

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
<pre>
	#include<iostream>
 #include< cstdio >
 #include < cmath >
 #include < queue >
 #include < cstring >
 #include < algorithm >
 #include < stack >
 #include < map >
 #include < cassert >
 #include < set >
 #include < deque >
 #include < complex >
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

//rectangle c x d fit into a x b
bool fit(double c, double d, double a, double b) {
	if (a > b) swap(a, b);
	if (c > d) swap(c, d);
	if (c > a) return 0;
	if (d-1e-12 < b) return 1;
	double l = sqrt(c*c+d*d);
	double alfa = atan2(d, c)-acos(a/l);
	return (c*sin(alfa)+d*cos(alfa)-1e-12) < b;
}


bool check(double a, double b, double c, double x, double y) {
	if(fit(a, b, x, y) || fit(a, c, x, y) || fit(b, c, x, y))
		return true;
	return false;
}

const int MAXV = 200001;
const int MAXV1 = 2 * MAXV;
int N, M;
vector<int> ady[MAXV];
int D[MAXV1], Mx[MAXV], My[MAXV];


bool BFS() {
	int u, v, i, e;
	queue<int> cola;
	bool f = 0;
	for (i = 0; i < N + M; i++)
		D[i] = 0;
	for (i = 0; i < N; i++)
		if (Mx[i] == -1)
			cola.push(i);
	while (!cola.empty()) {
		u = cola.front();
		cola.pop();
		for (e = ady[u].size() - 1; e >= 0; e--) {
			v = ady[u][e];
			if (D[v + N])
				continue;
			D[v + N] = D[u] + 1;
			if (My[v] != -1) {
				D[My[v]] = D[v + N] + 1;
				cola.push(My[v]);
			} else
				f = 1;
		}
	}
	return f;
}

int DFS(int u) {
	for (int v, e = ady[u].size() - 1; e >= 0; e--) {
		v = ady[u][e];
		if (D[v + N] != D[u] + 1)
			continue;
		D[v + N] = 0;
		if (My[v] == -1 || DFS(My[v])) {
			Mx[u] = v;
			My[v] = u;
			return 1;
		}
	}
	return 0;
}

int hopcroft_karp() {
	int i, flow = 0;
	for (i = max(N, M); i >= 0; i--)
		Mx[i] = My[i] = -1;
	while (BFS())
		for (i = 0; i < N; i++)
			if (Mx[i] == -1 && DFS(i))
				++flow;
	return flow;
}

double x,y,z;
pair<double,  pair<double, double> > cubes[1005];
pair<double, double> holes[1005];

int main() {

	scanf("%d%d", &N, &M);

	assert(N > 0 && N <= 1000 && M > 0 && M <= 1000);

	for(int i = 0;i<N;i++) {
		scanf("%lf%lf%lf", &x, &y, &z);
		assert(x>0 && x <= 10 && y>0 && y <= 10  && z>0 && z <= 10);
		cubes[i] = make_pair(x, make_pair(y,z));
	}

	for(int i = 0;i<M;i++) {
		scanf("%lf%lf", &x, &y);
		assert(x>0 && x <= 10 && y>0 && y <= 10);
		holes[i] = make_pair(x,y);
	}

	for(int i = 0;i<N;i++)
		for(int j = 0;j<M;j++)
			if(check(cubes[i].first,cubes[i].second.first,cubes[i].second.second, holes[j].first, holes[j].second)) {
				ady[i].push_back(j);
			}

	printf("%d\n", hopcroft_karp());

	return 0;
}