P29367 [洛谷] [COCI2007-2008#4] POKLON
提高-
题目描述

Problem Description

Given $n$ intervals, Mirko wants to construct some intervals such that each subsequent interval is a subinterval of the previous one, and each number within these intervals is included in the given intervals.

Input Format

The first line of input contains an integer $n$.

The next $n$ lines each contain two integers $[A, B]$, representing a given interval.

Output Format

The first line of output contains an integer $k$, representing the number of intervals that can be constructed.

The next $k$ lines each contain two integers, representing the constructed intervals in order.

Sample Input and Output

Sample Input #1

3
3 4
2 5
1 6

Sample Output #1

3
1 6
2 5
3 4

Sample Input #2

5
10 30
20 40
30 50
10 60
30 40

Sample Output #2

3
10 60
30 50
30 40

Sample Input #3

6
1 4
1 5
1 6
1 7
2 5
3 5

Sample Output #3

5
1 7
1 6
1 5
2 5
3 5

Notes

Data Size and Constraints

For $100\%$ of the data, it is guaranteed that $1 \le n \le 10^5$ and $1 \le A < B \le 10^6$.

Notes

This problem is translated from COCI2007-2008 CONTEST #4 T5 POKLON.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 4 2 5 1 6
样例输出
3 1 6 2 5 3 4