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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class ple {
	private static final class Rectangle {
		int x1;
		int x2;
		int y1;
		int y2;
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x1;
			result = prime * result + x2;
			result = prime * result + y1;
			result = prime * result + y2;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Rectangle other = (Rectangle) obj;
			if (x1 != other.x1)
				return false;
			if (x2 != other.x2)
				return false;
			if (y1 != other.y1)
				return false;
			if (y2 != other.y2)
				return false;
			return true;
		}
		@Override
		public String toString() {
			return x1 + " " + x2 + " " + y1 + " " + y2;
		}
		
		
	}
	
	private static final class FirstXRectangleComparator implements Comparator<Rectangle> {
		@Override
		public int compare(Rectangle o1, Rectangle o2) {
			if (o1.x1 < o2.x1) {
				return -1;
			} else if (o1.x1 > o2.x1) {
				return 1;
			} else if (o1.x2 < o2.x2) {
				return -1;
			} else if (o1.x2 > o2.x2) {
				return 1;
			} else if (o1.y1 < o2.y1) {
				return -1;
			} else if (o1.y1 > o2.y1) {
				return 1;
			} else if (o1.y2 < o2.y2) {
				return -1;
			} else if (o1.y2 > o2.y2) {
				return 1;
			} else {
				return 0;
			}
		}
	}

	private static final class SecondXRectangleComparator implements Comparator<Rectangle> {
		@Override
		public int compare(Rectangle o1, Rectangle o2) {
			if (o1.x2 < o2.x2) {
				return -1;
			} else if (o1.x2 > o2.x2) {
				return 1;
			} else if (o1.x1 < o2.x1) {
				return -1;
			} else if (o1.x1 > o2.x1) {
				return 1;
			} else if (o1.y1 < o2.y1) {
				return -1;
			} else if (o1.y1 > o2.y1) {
				return 1;
			} else if (o1.y2 < o2.y2) {
				return -1;
			} else if (o1.y2 > o2.y2) {
				return 1;
			} else {
				return 0;
			}
		}
	}
	
	private static final class FirstYRectangleComparator implements Comparator<Rectangle> {
		@Override
		public int compare(Rectangle o1, Rectangle o2) {
			if (o1.y1 < o2.y1) {
				return -1;
			} else if (o1.y1 > o2.y1) {
				return 1;
			} else if (o1.y2 < o2.y2) {
				return -1;
			} else if (o1.y2 > o2.y2) {
				return 1;
			} else if (o1.x1 < o2.x1) {
				return -1;
			} else if (o1.x1 > o2.x1) {
				return 1;
			} else if (o1.x2 < o2.x2) {
				return -1;
			} else if (o1.x2 > o2.x2) {
				return 1;
			} else {
				return 0;
			}
		}
	}
	
	public static void main(String ... args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String line = reader.readLine();
		int n = Integer.parseInt(line);
		
		List<Rectangle> firstXSet = new ArrayList<Rectangle>(n);
		
		for(int i = 0; i < n; i++) {
			line = reader.readLine();
			String[] splittedLine = line.split(" ");
			
			Rectangle rectangle = new Rectangle();
			rectangle.x1 = Integer.parseInt(splittedLine[0]);
			rectangle.x2 = Integer.parseInt(splittedLine[1]);
			rectangle.y1 = Integer.parseInt(splittedLine[2]);
			rectangle.y2 = Integer.parseInt(splittedLine[3]);
			
			firstXSet.add(rectangle);
		}
		
		Collections.sort(firstXSet, new FirstXRectangleComparator());
		
		Rectangle rectangle = firstXSet.get(0);
		int besom = rectangle.x1;
		
		SortedSet<Rectangle> firstYSet = new TreeSet<Rectangle>(new FirstYRectangleComparator());
		firstYSet.add(rectangle);
		
		SortedSet<Rectangle> secondXSet = new TreeSet<Rectangle>(new SecondXRectangleComparator());
		secondXSet.add(rectangle);
		
		Set<String> results = new HashSet<String>();
		
		int i = 1;
		for(; i < n; i++) {
			rectangle = firstXSet.get(i);
			while (besom < rectangle.x1) {
				if (firstYSet.size() > 1) {
					Iterator<Rectangle> firstYIterator = firstYSet.iterator();
					Rectangle previousRectangle = firstYIterator.next();
					int newBesom = besom;
					Rectangle newRectangle = rectangle;
					while (firstYIterator.hasNext()) {
						Rectangle currentRectangle = firstYIterator.next();
						if (previousRectangle.y1 < currentRectangle.y2 
								&& previousRectangle.y2 > currentRectangle.y1) {
							firstYIterator.remove();
							secondXSet.remove(previousRectangle);
							secondXSet.remove(currentRectangle);
							
							if (previousRectangle.x1 > currentRectangle.x1) {
								previousRectangle.x1 = currentRectangle.x1;
							}
							if (previousRectangle.x2 < currentRectangle.x2) {
								previousRectangle.x2 = currentRectangle.x2;
							}
							if (previousRectangle.y1 > currentRectangle.y1) {
								previousRectangle.y1 = currentRectangle.y1;
								// look back
							}
							if (previousRectangle.y2 < currentRectangle.y2) {
								previousRectangle.y2 = currentRectangle.y2;
								// look back
							}
							
							for(; i >= 0; i--) {
								Rectangle pom = firstXSet.get(i);
								if (pom.equals(currentRectangle)) {
									firstXSet.remove(i);
									n--;
								}
								
								if (pom.x2 <= previousRectangle.x1) {
									break;
								}
							}
							
							newBesom = previousRectangle.x1;
							newRectangle = firstXSet.get(i + 1);
							
							results.remove(currentRectangle.toString());
							
							secondXSet.add(previousRectangle);
						} else {
							previousRectangle = currentRectangle;
						}
						
						besom = newBesom;
						rectangle = newRectangle;
					}
				}
				
				besom = rectangle.x1;
				
				Iterator<Rectangle> secondXIterator = secondXSet.iterator();
				while (secondXIterator.hasNext()) {
					Rectangle currentRectangle = secondXIterator.next();
					if (currentRectangle.x2 <= besom) {
						results.add(currentRectangle.toString());
						
						secondXIterator.remove();
						firstYSet.remove(currentRectangle);
					} else {
						break;
					}
				}
			}
			
			firstYSet.add(rectangle);
			secondXSet.add(rectangle);
		}
		
		i--;
		if (firstYSet.size() > 1) {
			Iterator<Rectangle> firstYIterator = firstYSet.iterator();
			Rectangle previousRectangle = firstYIterator.next();
			while (firstYIterator.hasNext()) {
				Rectangle currentRectangle = firstYIterator.next();
				if (previousRectangle.y1 < currentRectangle.y2 
						&& previousRectangle.y2 > currentRectangle.y1) {
					firstYIterator.remove();
					secondXSet.remove(previousRectangle);
					secondXSet.remove(currentRectangle);
					
					if (previousRectangle.x1 > currentRectangle.x1) {
						previousRectangle.x1 = currentRectangle.x1;
					}
					if (previousRectangle.x2 < currentRectangle.x2) {
						previousRectangle.x2 = currentRectangle.x2;
					}
					if (previousRectangle.y1 > currentRectangle.y1) {
						previousRectangle.y1 = currentRectangle.y1;
						// look back
					}
					if (previousRectangle.y2 < currentRectangle.y2) {
						previousRectangle.y2 = currentRectangle.y2;
						// look back
					}
					
					for(; i >= 0; i--) {
						Rectangle pom = firstXSet.get(i);
						if (pom.equals(currentRectangle)) {
							firstXSet.remove(i);
							n--;
						}
						
						if (pom.x2 <= previousRectangle.x1) {
							break;
						}
					}
					
					results.remove(currentRectangle.toString());
					
					secondXSet.add(previousRectangle);
				} else {
					previousRectangle = currentRectangle;
				}
			}
		}
		
		/*
		Iterator<Rectangle> secondXIterator = secondXSet.iterator();
		while (secondXIterator.hasNext()) {
			Rectangle currentRectangle = secondXIterator.next();
			if (currentRectangle.x2 <= besom) {
				results.add(currentRectangle.toString());
				
				secondXIterator.remove();
				firstYSet.remove(currentRectangle);
			} else {
				break;
			}
		}
		*/
		
		Iterator<Rectangle> secondXIterator = secondXSet.iterator();
		while (secondXIterator.hasNext()) {
			Rectangle currentRectangle = secondXIterator.next();
			results.add(currentRectangle.toString());
		}

		System.out.println(results.size());
		Iterator<String> iterator = new TreeSet<String>(results).iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
	}
}