cswork / OAOpen practice workspace

CiscoOA #12

Compact the List

Estimated EasyJudge-ready

Topics (AI-labelled)In-place ArraysStrings

Given a strictly increasing list of integers, output each maximal run of consecutive integers as a to b, and output a single-element run as just that element. Runs keep their original order.

Input

The first line contains n, followed by n strictly increasing integers. The original gave no numeric bounds; this site adds 0≤n≤100000 and −10^9≤a[i]≤10^9. An empty list produces empty output text.

Output

Output one line per maximal consecutive run: a single item is written as a, and two or more items as a to b. An empty list produces empty output text.

Example 1

Input:

7
1 2 3 6 8 9 10

Output:

1 to 3
6
8 to 10

Example 2

Input:

4
-2 -1 0 2

Output:

-2 to 0
2

Example 3

Input:

0

Output:

Example notes

The outputs of the three public examples are, in order: 1 to 3 / 6 / 8 to 10; -2 to 0 / 2; empty text. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…