280 传统题

[ABC256D] 区间并集 (Union of Interval)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
3

[ABC256D] 区间并集 (Union of Interval)

Problem Statement

For real numbers LL and RR, let us denote by [L,R)[L,R) the set of real numbers greater than or equal to LL and less than RR. Such a set is called a right half-open interval.

You are given NN right half-open intervals [Li,Ri)[L_i,R_i). Let SS be their union. Represent SS 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 kk be the minimum number of right half-open intervals needed to represent SS as their union. Print kk lines containing such kk right half-open intervals [Xi,Yi)[X_i,Y_i) in ascending order of XiX_i, 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:

  • 1≤N≤2×1051 \leq N \leq 2\times 10^5

  • 1≤Li<Ri≤2×1051 \leq L_i \lt R_i \leq 2\times 10^5

  • All values in input are integers.

  • Source: ABC256D