1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#define f first
#define s second
using namespace std;

const int INF = 1000000004;
int n;

bool inter(pair<pair<int, int>, pair<int, int> > &A, pair<pair<int, int>, pair<int, int> > &B) {
	bool a = false, b = false;
	vector<pair<int, int>> V;
	V.push_back(make_pair(A.f.f, 1));
	V.push_back(make_pair(A.f.s, -1));
	V.push_back(make_pair(B.f.f, 1));
	V.push_back(make_pair(B.f.s, -1));
	sort(V.begin(), V.end());
	if(V[1].s == 1) a = true;
	V.clear();
	V.push_back(make_pair(A.s.f, 1));
	V.push_back(make_pair(A.s.s, -1));
	V.push_back(make_pair(B.s.f, 1));
	V.push_back(make_pair(B.s.s, -1));
	sort(V.begin(), V.end());
	if(V[1].s == 1) b = true;
	return a && b;
}

int main() {
	scanf("%d", &n);
	vector<pair<pair<int, int>, pair<int, int> > > G, R;
	for(int i = 0; i<n; i++) {
		int x1, x2, y1, y2;
		scanf("%d %d %d %d", &x1, &x2, &y1, &y2);
		G.push_back(make_pair(make_pair(x1, x2), make_pair(y1, y2)));
	}
	while(G.size() > 0) {
		pair<pair<int, int>, pair<int, int> > x = G[G.size()-1];
		G.pop_back();
		vector<pair<pair<int, int>, pair<int, int> > > A, B;
		for(int i = 0; i<R.size(); i++) {
			if(inter(x, R[i])) A.push_back(R[i]);
			else B.push_back(R[i]); 
		}
		A.push_back(x);
		swap(R,B);
		int x1 = INF, x2 = -INF, y1 = INF, y2 = -INF;
		for(int i = 0; i<A.size(); i++) {
			x1 = min(x1, A[i].f.f);
			x2 = max(x2, A[i].f.s);
			y1 = min(y1, A[i].s.f);
			y2 = max(y2, A[i].s.s);
		}
		if(A.size() == 1) R.push_back(make_pair(make_pair(x1, x2), make_pair(y1, y2)));
		else G.push_back(make_pair(make_pair(x1, x2), make_pair(y1, y2)));
	}
	sort(R.begin(), R.end());
	printf("%d\n", R.size());
	for(int i = 0; i<R.size(); i++) printf("%d %d %d %d\n", R[i].f.f, R[i].f.s, R[i].s.f, R[i].s.s);
	return 0;
}