#K39627. Summary Ranges

    ID: 26463 Type: Default 1000ms 256MiB

Summary Ranges

Summary Ranges

Given a sorted array of unique integers, your task is to summarize consecutive ranges. A consecutive range is a sequence of integers where each number is exactly 1 more than the previous. If a number does not form a range with any neighbors, it should be output on its own.

For example, if the input array is [0, 1, 2, 4, 5, 7], the output should be "0->2 4->5 7" because 0, 1, 2 form a consecutive range, 4 and 5 form another, and 7 is alone.

Note: The problem requires reading input from stdin and printing output to stdout. The integers provided in the array are guaranteed to be sorted and unique.

The summary range is defined as follows: if a range contains more than one number, it is represented as \(a \to b\) where \(a\) is the starting number and \(b\) is the last number of the consecutive range. If the range contains only one number, output it directly.

inputFormat

The input will be provided in the following format:

  1. The first line contains an integer \(N\), representing the count of numbers in the array.
  2. The second line contains \(N\) space-separated integers.

If \(N\) is 0, the second line may be omitted and the output should be empty.

outputFormat

Output the summary ranges as a space-separated list of strings. Each range should be formatted as either a single number or in the form \(a \to b\) representing a sequence from \(a\) to \(b\).

## sample
6
0 1 2 4 5 7
0->2 4->5 7