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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct P {
	int x1, x2, y1, y2;
	P () {x1 = x2 = y1 = y2 = -1;}
};
bool cmp (P a, P b) {
	if (a.x1 < b.x1) return true;
	if (a.x1 > b.x1) return false;
	if (a.x2 < b.x2) return true;
	if (a.x2 > b.x2) return false;
	if (a.y1 < b.y1) return true;
	if (a.y1 > b.y1) return false;
	if (a.y2 < b.y2) return true;
	return false;
}
bool kolizja (P a, P b) {
	if (a.y1 >= b.y2) return false;
	if (a.y2 <= b.y1) return false;
	if (a.x1 >= b.x2) return false;
	if (a.x2 <= b.x1) return false;
	return true;
}
int n;
vector <P> v;
P in;
int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; i ++) {
		scanf ("%d %d %d %d", &in.x1, &in.x2, &in.y1, &in.y2);
		for (int i = 0; i < v.size (); i ++) {
			if (kolizja (v [i], in)) {
				in.x1 = min(in.x1, v [i].x1);
				in.x2 = max(in.x2, v [i].x2);
				in.y1 = min(in.y1, v [i].y1);
				in.y2 = max(in.y2, v [i].y2);
				if (v.size () > 1) v.erase (v.begin () + i);
				else v.clear ();
				i = -1;
			}
		}
		v.push_back (in);
	}
	sort (v.begin (), v.end (), cmp);
	printf ("%d\n", v.size ());
	for (int i = 0; i < v.size (); i ++) printf ("%d %d %d %d\n", v [i].x1, v [i].x2, v [i].y1, v [i].y2);
}