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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
typedef long long int LL;

struct prostokat
{
	LL x1, x2, y1, y2;
};

bool operator != (prostokat A, prostokat B)
{
	if(A.x1 == B.x1 && A.x2 == B.x2 && A.y1 == B.y1 && A.y2 == B.y2)
		return false;
	else
		return true;
}

prostokat dodaj(prostokat A, prostokat B)
{
	prostokat C;
	
	C.x1 = min(min(A.x1, A.x2), min(B.x1, B.x2));
	C.x2 = max(max(A.x1, A.x2), max(B.x1, B.x2));
	C.y1 = min(min(A.y1, A.y2), min(B.y1, B.y2));
	C.y2 = max(max(A.y1, A.y2), max(B.y1, B.y2));
	
	return C;
}

bool zachodzi(prostokat A, prostokat B)
{
	if(B.x1 >= A.x2 || B.x2 <= A.x1 || B.y1 >= A.y2 || B.y2 <= A.y1)
		return false;
	else
		return true;
}

bool operator < (prostokat A, prostokat B)
{
	if(A.x1 < B.x1)
		return true;
	else
	{
		if(A.x1 > B.x1)
			return false;
		if(A.x1 == B.x1)
		{
			if(A.x2 < B.x2)
				return true;
			else
			{
				if(A.x2> B.x2)
					return false;
				if(A.x2 == B.x2)
				{	if(A.y1 < B.y1)
						return true;
					else
					{
						if(A.y1 > B.y1)
							return false;
						if(A.y1 == B.y1)
						{
							if(A.y2 < B.y2)
								return true;
							else
								return false;
						}
					}
					
				}
			}
		}
	}
}

vector <prostokat> P;

int main()
{
	LL n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		prostokat X;
		
		cin >> X.x1 >> X.x2 >> X.y1 >> X.y2;
		
		P.push_back(X);
	}	
	
	bool t = true;
	
	while(t == true)
	{
		t = false;
		
		prostokat fuzja;
		
		int ma = -1, mb = -1;
		
		for(int i = 0 ; i < P.size(); i++)
		{
			for(int j = i + 1; j < P.size(); j++)
			{
				t = max(t, zachodzi(P[i], P[j]));
				
				if(t == true)
				{
					fuzja = dodaj(P[i], P[j]); ma = i; mb = j;
					goto A;
				}
			}
		}
		
		A:
			
		if(t == true)
		{
			vector <prostokat> P2;
			
			for(int mm = 0; mm < P.size(); mm++)
			{
				if(mm != ma && mm != mb)
				{
					P2.push_back(P[mm]);
				}
			}
			
			P2.push_back(fuzja);
			
			P = P2;
		}
		
	}
	
	cout << P.size() << endl;
	
	sort(P.begin(), P.end());
	
	for(int i = 0 ; i < P.size(); i++)
	{
		cout << P[i].x1 << " " << P[i].x2 << " " << P[i].y1 << " " << P[i].y2 << endl;
 	}
	
	return 0;
}