[ABC256D] 区间并集 (Union of Interval)
Problem Statement
For real numbers and , let us denote by the set of real numbers greater than or equal to and less than . Such a set is called a right half-open interval.
You are given right half-open intervals . Let be their union. Represent as a union of the minimum number of right half-open intervals.
Input
Input is given from Standard Input in the following format:
$N$
$L_1$ $R_1$
$\vdots$
$L_N$ $R_N$
Output
Let be the minimum number of right half-open intervals needed to represent as their union. Print lines containing such right half-open intervals in ascending order of , as follows:
$X_1$ $Y_1$
$\vdots$
$X_k$ $Y_k$
Example
3
10 20
20 30
40 50
10 30
40 50
Note
-
Constraints:
-
-
-
All values in input are integers.
-
Source: ABC256D