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
#include <iostream>
#include <algorithm>

using namespace std;

struct rect { int xa, xb, ya, yb; };

rect p[100000];
int q[100000];

bool rs (int a, int b) {
	if (p[a].xa == p[b].xa) {
		if (p[a].xb == p[b].xb) {
			if (p[a].ya == p[b].ya) {
				return p[a].yb < p[a].yb;
			} else {
				return p[a].ya < p[b].ya;
			}
		} else {
			return p[a].xb < p[b].xb;
		}
	} else {
		return p[a].xa < p[b].xa;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> p[i].xa >> p[i].xb >> p[i].ya >> p[i].yb;
		for (int j = 0; j < i; j++) {
			if (p[j].xa != -1 && p[j].ya < p[i].yb && p[j].yb > p[i].ya && p[j].xa < p[i].xb && p[j].xb > p[i].xa) {
				rect nr;
				nr.xa = min(p[i].xa, p[j].xa);
				nr.xb = max(p[i].xb, p[j].xb);
				nr.ya = min(p[i].ya, p[j].ya);
				nr.yb = max(p[i].yb, p[j].yb);
				p[j].xa = -1;
				p[i] = nr;
			}
		}
	}

	int ls = 0;
	for (int i = 0; i < n; i++) {
		if (p[i].xa != -1) {
			q[ls] = i;
			ls++;
		}
	}

	sort(q, q+ls, rs);

	cout << ls << endl;
	for (int i = 0; i < ls; i++) {
		cout << p[q[i]].xa << ' ' << p[q[i]].xb << ' ' << p[q[i]].ya << ' ' << p[q[i]].yb << endl;
	}

	return 0;
}