#K88632. Range Compression

    ID: 37352 Type: Default 1000ms 256MiB

Range Compression

Range Compression

You are given a sorted list of integers in ascending order. Your task is to compress consecutive sequences of numbers into a range string in the format start-end\text{start-end} if the sequence contains at least three consecutive numbers; otherwise, output each number separately.

For example, given the list [1, 2, 3, 5, 7, 8, 9, 11], the compressed output should be ["1-3", 5, "7-9", 11] because 1,2,3 and 7,8,9 form consecutive sequences of length 3, while 5 and 11 remain as individual numbers.

inputFormat

The first line contains an integer nn, which is the number of elements in the list. The second line contains nn space-separated integers representing the sorted list.

outputFormat

Output the compressed list as space-separated values. For each consecutive sequence of at least three numbers, print the range in the format start-end. Otherwise, print the individual numbers.## sample

8
1 2 3 5 7 8 9 11
1-3 5 7-9 11