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
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

const int N = 1048576;
const int DN = 2097152;

int n, a, b, c, d, p, k, licz;
bool czy;
bool usuniete[100005];

vector < pair < pair <int, int>, pair <int, int> > > v;
vector < pair < pair <int, int>, pair <int, int> > > result;
vector < pair < pair <int, int>, pair <int, int> > >::iterator iter;

map < int, set < pair < int,int > > > mapa[2100000];
map < int, set < pair < int,int > > >::iterator it;

set < pair <int,int> >::iterator ite;

void usun (int nr)
{
	usuniete[nr] = 1;
	int x1 = v[nr].first.first;
	int x2 = v[nr].first.second;
	int x3 = v[nr].second.first;
	int x4 = v[nr].second.second;
	for (int i = x2 + N; i > 0; i >>= 1) for (int j = x3 + N; j > 0; j >>= 1)
	{
		mapa[i][j].erase(make_pair(x4, nr));
	}
}

bool sprawdz (int vv, int gdzie)
{
	if (mapa[vv].find(gdzie) == mapa[vv].end()) return 0;
	ite = mapa[vv][gdzie].lower_bound(make_pair(c, 0));
	if (ite == mapa[vv][gdzie].end()) return 0;
	int nr = ite->second;
	usun(nr);
	a = min(v[nr].first.first, a);
	b = max(v[nr].first.second, b);
	c = min(v[nr].second.first, c);
	d = max(v[nr].second.second, d);
	czy = true;
	return 0;
}

void sprawdzenie (int vv)
{
	int gdzie = 1;
	int numer = N - 1;
	int spadek = (N >> 1);
	while (1)
	{
		gdzie <<= 1;
		numer -= spadek;
		if (d == numer)
		{
			sprawdz(vv, gdzie);
			break;
		}
		if (d < numer)
		{
			spadek >>= 1;
			continue;
		}
		sprawdz(vv, gdzie);
		if (czy == true) break;
		gdzie++;
		numer += spadek;
		spadek >>= 1;
	}
}

int main ()
{
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		v.push_back(make_pair(make_pair(a, b - 1), make_pair(c, d - 1)));
	}
	sort(v.begin(), v.end());
	licz = 0;
	for (iter = v.begin(); iter != v.end(); ++iter)
	{
		a = iter->first.first;
		b = iter->first.second;
		c = iter->second.first;
		d = iter->second.second;
		czy = true;
		while (1)
		{
			czy = false;
			p = a + N;
			k = DN - 1;
			while (p < k)
			{
				if (p & 1)
				{
				    sprawdzenie(p);
				    p++;
				}
				if (czy == true) break;
				if ((k & 1) == 0)
				{
				    sprawdzenie(k);
				    k--;
				}
				if (czy == true) break;
				p >>= 1;
				k >>= 1;
			}
			if (czy == true) continue;
			if (p == k) sprawdzenie(p);
			if (czy == false) break;
		}
		v[licz] = (make_pair(make_pair(a, b), make_pair(c, d)));
		for (int i = b + N; i > 0; i >>= 1) for (int j = c + N; j > 0; j >>= 1)
		{
			mapa[i][j].insert(make_pair(d, licz));
		}
		licz++;
	}
	for (int i = 0; i < n; ++i) if (!usuniete[i]) result.push_back(v[i]);
	sort(result.begin(), result.end());
	printf("%d\n",result.size());
	for (iter = result.begin(); iter != result.end(); ++iter)
	{
		printf("%d %d %d %d\n", iter->first.first, iter->first.second + 1, iter->second.first, iter->second.second + 1);
	}
	return 0;
}