Under construction

Still being built. Things may change

MrCodeFormatGrader

Interview

Time limit1sMemory limit1024 MB

Summary
Given C total lines and the N error line numbers in increasing order, print the error and correct lines as comma-separated ranges, with the last item joined by "and".
Level

Medium4 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

Problem

Instructor Bob is building a website that automatically grades source code formatting. The website is called "MrCodeFormatGrader". When you run Bob's program and submit your source code, it outputs CC, the number of lines of source code; NN, the number of source code lines with format errors; and a list of the line numbers that are not properly formatted. The line numbers are separated by spaces and given in increasing order.

For example, for a 100100-line program with 1010 errors on lines 22, 33, 55, 1010, 1111, 1212, 2525, 2626, 8888, and 8989, the original program might output this:

100 10
2 3 5 10 11 12 25 26 88 89

However, the people who used this program said the output is not very readable. Your job is to read the output above and show two lists: a compressed list of errors and a compressed list of correct lines.

Input

Input consists of two lines. The first line contains two integers: CC, the number of lines of source code in the program being checked, where 2≤C≤100 0002 ≤ C ≤ 100\,000; and NN, the number of source code lines containing format errors, where 1≤N≤min⁡(C,1 000)1 ≤ N ≤ \min(C, 1\,000). The second line contains NN values identifying the line numbers of source code lines with format errors. These values are positive integers less than or equal to CC and are listed in strictly increasing order.

Output

Output consists of two lines. The first line starts with the string "Errors:", followed by a space, followed by the list of lines with errors. The second line starts with the string "Correct:", followed by a space, followed by the list of lines without errors. For both lists, a contiguous set of line numbers is represented by the first and last line, separated by a hyphen ('-'). In lists with two or more items, items are separated by a comma and space except for the last value (or last range of contiguous values), which is preceded by "and" instead of a comma and space. See the sample output. Note: every program has at least one error and at least one correct line.

Examples2

  1. Example 1

    Input
    100 10
    2 3 5 10 11 12 25 26 88 89
    
    Expected output
    Errors: 2-3, 5, 10-12, 25-26 and 88-89
    Correct: 1, 4, 6-9, 13-24, 27-87 and 90-100
    
  2. Example 2

    Input
    40 18
    1 3 4 6 7 8 9 12 13 14 20 25 26 27 28 30 38 40
    
    Expected output
    Errors: 1, 3-4, 6-9, 12-14, 20, 25-28, 30, 38 and 40
    Correct: 2, 5, 10-11, 15-19, 21-24, 29, 31-37 and 39