#K11761. Expand Intervals

    ID: 23541 Type: Default 1000ms 256MiB

Expand Intervals

Expand Intervals

Given a list of intervals, each defined by a pair of integers \(a\) and \(b\) (with \(a \leq b\)), your task is to expand these intervals into a sorted list of unique integers. The intervals might overlap, and each integer that falls within any of the intervals should appear exactly once in the output.

For example, for the intervals \((1, 3)\), \((5, 7)\) and \((4, 6)\), the correct output is:

1 2 3 4 5 6 7

You are required to read input from stdin and output your result to stdout using the specified format.

inputFormat

The input begins with a line containing a single integer \(n\), which denotes the number of intervals. Each of the following \(n\) lines contains two space-separated integers, representing the start and end of an interval respectively.

For example:

3
1 3
5 7
4 6

If \(n = 0\), it means there are no intervals, and the output should be empty.

outputFormat

Output a single line containing all unique integers covered by any of the intervals in ascending order. Separate the integers with a single space.

For example, for the input above, the output should be:

1 2 3 4 5 6 7
## sample
3
1 3
5 7
4 6
1 2 3 4 5 6 7