#ABC256D. [ABC256D] Union of Interval

[ABC256D] Union of Interval

Score : 400400 points

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.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1Li<Ri2×1051 \leq L_i \lt R_i \leq 2\times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

L1L_1 R1R_1

\vdots

LNL_N RNR_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:

X1X_1 Y1Y_1

\vdots

XkX_k YkY_k

3
10 20
20 30
40 50
10 30
40 50

The union of the three right half-open intervals [10,20),[20,30),[40,50)[10,20),[20,30),[40,50) equals the union of two right half-open intervals [10,30),[40,50)[10,30),[40,50).

3
10 40
30 60
20 50
10 60

The union of the three right half-open intervals [10,40),[30,60),[20,50)[10,40),[30,60),[20,50) equals the union of one right half-open interval [10,60)[10,60).