Merge all overlapping intervals. Intervals that merely touch (e.g. 1 4 and 4 5) also merge.
1 4
4 5
Input: each line is one interval start end. Output: the merged intervals, one start end per line, sorted by start.
start end
Your program reads from stdin and prints to stdout.
Example 1
Input: 1 3 2 6 8 10 15 18
Output: 1 6 8 10 15 18
Hints