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
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
struct pro{
	int x1,y1,x2,y2;
};
bool comp(const pro &a, const pro &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;
   	if(a.y2!=b.y2)
   		return a.y2 < b.y2;
}
	pro W;
inline bool kolizja(pro  A, pro  B){

    W.x1 = max(A.x1, B.x1);
	W.y1 = max(A.y1, B.y1);
	W.x2 = min(A.x2, B.x2);
	W.y2 = min(A.y2, B.y2);
	if(W.x2-W.x1<=0)return false;
	if(W.y2-W.y1<=0)return false;
	return true;
};
vector<pro>P;
int main(){
	int n;
	cin>>n;
	int ile = 0;
	while(n--){
		pro p;
		cin>>p.x1>>p.x2>>p.y1>>p.y2;
		int ok = 1;
		while(ok){
			ok = 0;
			for(int i =0;i<ile;i++){
				if(kolizja(p,P[i])){
					p.x1=min(p.x1,P[i].x1);
					p.y1=min(p.y1,P[i].y1);
					p.x2=max(p.x2,P[i].x2);
					p.y2=max(p.y2,P[i].y2);
					P[i]=P[ile-1];
					P.pop_back();
					ile--;
					ok = 1;
					break;
				}
			}
			
		}
		P.push_back(p);
		ile++;
	}
	sort(P.begin(),P.end(),comp);
	cout<<ile<<"\n";
	for(int i =0;i<ile;i++)
		cout<<P[i].x1<<" "<<P[i].x2<<" "<<P[i].y1<<" "<<P[i].y2<<"\n";
	
	
	
	return 0;
}