A concert hall has received
Given all
The first line contains a single integer KaTeX can only parse string typed expression — the number of booking requests. If KaTeX can only parse string typed expression, there are no bookings.
Each of the next KaTeX can only parse string typed expression lines contains two integers, the start and end time of a booking.
Print a single integer KaTeX can only parse string typed expression on the first line — the number of resulting merged booking blocks.
Then print KaTeX can only parse string typed expression lines, each containing the start and end time of a merged block, sorted by start time.
Input
4
1 3
2 6
8 10
15 18Output3
1 6
8 10
15 18ExplanationThe bookings KaTeX can only parse string typed expression and KaTeX can only parse string typed expression overlap (both cover time 2 to 3), so they merge into KaTeX can only parse string typed expression. The other two bookings don't overlap with anything, so they remain separate.
Example 2:
Input
1
5 10Output1
5 10ExplanationA single booking has nothing to merge with, so it is reported as-is.
Example 3:
Input
3
1 4
4 5
5 6Output1
1 6ExplanationEach booking touches the next one exactly at its boundary (booking 1 ends at time 4, booking 2 starts at time 4), which counts as overlapping, so all three merge into a single block KaTeX can only parse string typed expression.