#C14359. Merge Overlapping Intervals

    ID: 43999 Type: Default 1000ms 256MiB

Merge Overlapping Intervals

Merge Overlapping Intervals

You are given a list of intervals. Your task is to merge all overlapping intervals and output the resulting non-overlapping intervals in sorted order.

An interval is represented as two integers \(l\) and \(r\) where \(l \leq r\). If two intervals \([l_1, r_1]\) and \([l_2, r_2]\) overlap (i.e., \(l_2 \leq r_1\)), they should be merged into a single interval \([l_1, \max(r_1, r_2)]\). The final set of intervals should be output in increasing order of their starting values.

Example:

Input:
2
1 3
2 6

Output: 1 6

</p>

inputFormat

The first line contains an integer \(n\), the number of intervals.

Each of the next \(n\) lines contains two integers representing the start and end of an interval.

\(0 \leq n \leq 10^5\) and each interval satisfies \(l \leq r\).

outputFormat

Output the merged intervals, each on a separate line. For each interval, print two space-separated integers representing its start and end.

If there are no intervals, output nothing.

## sample
0