#C881. Merge Intervals

    ID: 52833 Type: Default 1000ms 256MiB

Merge Intervals

Merge Intervals

You are given a list of intervals. Each interval is represented as two integers \(a\) and \(b\), where \(a \leq b\). Your task is to merge all overlapping intervals and output the resulting list of non-overlapping intervals sorted by their start time.

For example, given the intervals:

[1, 3]
[2, 6]
[8, 10]
[15, 18]

After merging, the result will be:

[1, 6]
[8, 10]
[15, 18]

If there are no intervals, simply output nothing.

inputFormat

The first line contains a single integer \(N\) representing the number of intervals. Each of the following \(N\) lines contains two space-separated integers \(a\) and \(b\) where \(a \leq b\) representing an interval.

outputFormat

Output the merged intervals. For each merged interval, print two integers separated by a space on a new line. If there are no intervals, do not output anything.

## sample
4
1 3
2 6
8 10
15 18
1 6

8 10 15 18

</p>