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
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

//#define MJMREAD

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define mp make_pair
typedef pair<pii,pii> p4;
#define m4(a,b,c,d) mp(mp(a,b),mp(c,d))


#if defined(MJMREAD)
int rd[] = {5, 7,8,1,4, 1,5,2,3, 4,5,2,7, 2,3,5,9, 4,6,8,9};
inline int read() { static int i=0; return rd[i++]; }
#else // MJMREAD
inline int read() { int n; scanf("%d", &n); return n; }
#endif // MJMREAD

int main() {
    int n = read();
    vi x1(n), x2(n), y1(n), y2(n), res(n, 1);
    for (int i=0; i<n; ++i) {
        int x = read(), xx = read();
        int y = read(), yy = read();
        x1[i] = std::min(x, xx);
        x2[i] = std::max(x, xx);
        y1[i] = std::min(y, yy);
        y2[i] = std::max(y, yy);
    }

    for (int i=0; i<n; ++i) if (res[i]) for (int j=0; j<n; ++j) if (res[j]) if (i != j) {
        if (std::max(x1[i], x1[j]) < std::min(x2[i], x2[j]) && std::max(y1[i], y1[j]) < std::min(y2[i], y2[j])) {
            x1.push_back(std::min(x1[i], x1[j]));
            x2.push_back(std::max(x2[i], x2[j]));
            y1.push_back(std::min(y1[i], y1[j]));
            y2.push_back(std::max(y2[i], y2[j]));
            res.push_back(1);
            res[i] = res[j] = 0;
            ++n;
            break;
        }
    }

    priority_queue<p4, vector<p4>, greater<p4> > q;
    for (int i=0; i<n; ++i) if (res[i]) 
        q.push(m4(x1[i], x2[i], y1[i], y2[i]));

    printf("%d\n", q.size());
    while (!q.empty()) {
        p4 p = q.top();
        q.pop();
        printf("%d %d %d %d\n", p.first.first, p.first.second, p.second.first, p.second.second);
    }

    return 0;
}