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
#include<cstdio>
#include<vector>
#include<algorithm>
#define MP make_pair
#define fi first
#define se second
using namespace std;
vector<pair<pair<int, int>, pair<int, int> > >v;
int n, a, b, c, d, e, f, g, h, i, j;
bool q;
int main()
{
  scanf("%d", &n);
  
  while(n--)
  {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    v.push_back(MP(MP(a, b), MP(c, d)));
  }
  
  q = false;
  
  while(q == false)
  {
    q = true;
    for(i = 0; i < v.size(); i++)
    {
      a = v[i].fi.fi;
      b = v[i].fi.se;
      c = v[i].se.fi;
      d = v[i].se.se;
      for(j = i + 1; j < v.size(); j++)
      {
	e = v[j].fi.fi;
	f = v[j].fi.se;
	g = v[j].se.fi;
	h = v[j].se.se;
	if (a < f && e < b && c < h && g < d)
	{
	  q = false;
	  v[i].fi.fi = min(a, e);
	  v[i].fi.se = max(b, f);
	  v[i].se.fi = min(c, g);
	  v[i].se.se = max(d, h);
	  a = v[i].fi.fi;
	  b = v[i].fi.se;
	  c = v[i].se.fi;
	  d = v[i].se.se;
	  swap(v[j], v.back());
	  v.pop_back();
	}
      }
    }
  }
  
  printf("%d\n", v.size());
  
  sort(v.begin(), v.end());
  
  for(i = 0; i < v.size(); i++)
  {
    printf("%d %d %d %d\n", v[i].fi.fi, v[i].fi.se, v[i].se.fi, v[i].se.se);
  }
  
return 0;
}