Igor has a huge collection of folk hits on his computer, containing
When a song first appears on the display, the software needs to access its file on disk and read metadata like artist and song name. This metadata is stored in the computer's memory so that, if the song reappears on display, the file doesn't need to be opened again.
Your program will be given the songs Igor wants to listen to, in the order in which he wants to do it. For each song, determine the interval of songs which will be displayed while it is playing, so that the total number of files that need to be accessed on disk is the smallest possible.
Note: The solution may not be unique.
Input Specification
The first line contains two integers
The second line contains the integer
The next
Output Specification
Output should consist of
On the first line output the smallest possible number of files to access while playing Igor's playlist.
After this, for each song
Scoring
An output which is not completely correct, but the first line (the least
number of files to access) is correct, will score
Sample Input 1
10 3
5
4
5
8
7
6
Sample Output 1
5
4 6
4 6
6 8
6 8
6 8
Sample Input 2
15 4
6
6
14
11
3
8
5
Sample Output 2
10
3 6
11 14
11 14
3 6
5 8
3 6
Sample Input 3
1000 301
3
300
500
700
Sample Output 3
401
300 600
350 650
400 700
Comments