Skip to content
UPEEC

Merge Intervals

Medium#sorting#intervals· solved by 0 · time limit 2.0 s

Merge all overlapping intervals (touching ones like [1,3] and [3,5] also merge) and print the result sorted by start.

Input

nn, then nn lines start end with start ≤ end.

Output

The merged intervals, one per line.

Constraints

1≤n≤1051 \le n \le 10^5, 0≤0 \le start ≤ end ≤ 10910^9

Sample 1

Input

4
1 3
2 6
8 10
15 18

Output

1 6
8 10
15 18

Sample 2

Input

2
1 4
4 5

Output

1 5

Sign in or join free to run and submit your solution.