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

#define MAXN 100003

using namespace std;

struct pro{
       int x[2];
       int y[2];       
};

int n;

pro tab[MAXN];
pro pom;
vector<pro> V;

bool aktywny[MAXN];
int ilosc;

bool maja_wspolne(const int &a, const int &b){
     
     pom.x[0] = max(tab[a].x[0],tab[b].x[0]);
     pom.x[1] = min(tab[a].x[1],tab[b].x[1]);
     pom.y[0] = max(tab[a].y[0],tab[b].y[0]);
     pom.y[1] = min(tab[a].y[1],tab[b].y[1]);
     
     if(pom.x[0] >= pom.x[1])return false;
     if(pom.y[0] >= pom.y[1])return false;
     return true;
}

bool cmp(const pro &a,const pro &b){
     if(a.x[0] < b.x[0])return true;
     else if(a.x[0] == b.x[0]){
          if(a.x[1] < b.x[1])return true;
          else if(a.x[1] == b.x[1]){
               if(a.y[0] < b.y[0])return true;
               else if(a.y[0] == b.y[0]){
                    if(a.y[1] < b.y[1])return true;     
               }     
          }     
     } 
     return false; 
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
            scanf("%d %d %d %d",&pom.x[0],&pom.x[1],&pom.y[0],&pom.y[1]);
            
            tab[i].x[0] = min(pom.x[0],pom.x[1]);
            tab[i].x[1] = max(pom.x[0],pom.x[1]);
            
            tab[i].y[0] = min(pom.y[0],pom.y[1]);
            tab[i].y[1] = max(pom.y[0],pom.y[1]);
            
            aktywny[i] = 1;        
    }
    
    for(int i=0;i<n;i++){
    	if(aktywny[i] == 1){
            for(int j=0;j<n;j++){
                    if((j != i)&&(aktywny[j] == 1)&&(maja_wspolne(i,j))){
                          aktywny[j] = 0;
                          tab[i].x[0] = min(tab[j].x[0],tab[i].x[0]);
                          tab[i].x[1] = max(tab[j].x[1],tab[i].x[1]);
                          tab[i].y[0] = min(tab[j].y[0],tab[i].y[0]);
                          tab[i].y[1] = max(tab[j].y[1],tab[i].y[1]);
                          j = (-1);
                    }        
            }   
        }     
    }
    for(int i=0;i<n;i++){
            if(aktywny[i] == 1){
                          ilosc++;
                          V.push_back(tab[i]);              
            }        
    }    
    sort(V.begin(),V.end(),cmp);
    printf("%d\n",ilosc);
    for(int i=0;i<V.size();i++){
            printf("%d %d %d %d\n",V[i].x[0],V[i].x[1],V[i].y[0],V[i].y[1]);                 
    }

    return 0;
}