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
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <set>
#include <list>
#include <algorithm>
using namespace std;
int n;
struct xxx{
	int x1, x2, y1, y2;
}tmp;
list <xxx> v;
list <xxx>::iterator it;
list <xxx>::iterator it2;
list <xxx>::iterator tmpit;
list <xxx>::iterator tmpit2;
bool cmp(xxx a, xxx b){
	if(a.x1!=b.x1)
		return a.x1<b.x1;
	if(a.x2!=b.x2)
		return a.x2<b.x2;
	if(a.y1!=b.y1)
		return a.y1<b.y1;
	return a.y2<b.y2;
}
bool czy_wspolne(xxx a, xxx b){
	if(a.x1<=b.x1 && a.x2 > b.x1){
		if(a.y1<=b.y1 && a.y2 > b.y1)
			return true;
		if(a.y1<=b.y2 && a.y1 > b.y1)
			return true;
	}
	if(a.x1<=b.x2 && a.x1 > b.x1){
		if(a.y1<=b.y1 && a.y2 > b.y1)
			return true;
		if(a.y1<=b.y2 && a.y1 > b.y1)
			return true;
	}
	return false;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>tmp.x1>>tmp.x2>>tmp.y1>>tmp.y2;
		v.push_back(tmp);
	}
	for(it=v.begin(); it!=v.end(); ++it){
		for(it2=v.begin(); it2!=v.end(); ++it2){
			if(it==it2)continue;
			if(czy_wspolne(*it, *it2)){
				tmp.x1=min(it->x1, it2->x1);
				tmp.x2=max(it->x2, it2->x2);
				tmp.y1=min(it->y1, it2->y1);
				tmp.y2=max(it->y2, it2->y2);
				tmpit=it;
				tmpit2=it2;
				it++;
				it2++;
				v.erase(tmpit);
				v.erase(tmpit2);
				it--;
				it2--;
				v.push_back(tmp);
			}
		}
	}
	v.sort(cmp);
	cout<<v.size()<<"\n";
	for(it=v.begin(); it!=v.end(); ++it)
		cout<<it->x1<<" "<<it->x2<<" "<<it->y1<<" "<<it->y2<<"\n";
	
	return 0;
}