407412: GYM102785 H A self-describing sequence

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. A self-describing sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Let's call the sequence $$$a_0$$$, $$$a_1$$$, $$$a_2$$$, … $$$a_{k-1}$$$ as «self- describing»; if the value $$$a_i$$$ is the number of numbers $$$i$$$ encountered in this sequence.

For example, in a sequence 1, 2, 1, 0 - «0» occurs 1 time, «1» is found 2 times, «2» occurs once and «3» does not occur.

Your task will be to write a program that for a given length of sequence $$$k$$$, will output its elements with the specified indices, or report that such a sequence does not exist. If there are several such sequences, any of them is considered to be correct.

Input

The first line of the input file contains the length of the sequence $$$k$$$. $$$(1~\le~k~\le~2^{30})$$$.

The second line of the input file contains the number $$$n$$$ $$$(0~<~n~\le~10^5)$$$ which is the number of elements to be found in the sequence.

The third line contains the $$$n$$$ number of integers $$$r_1$$$ $$$r_2$$$ $$$r_3$$$ … $$$r_n$$$ $$$(0~\le~n_i~<~k)$$$, separated by spaces. These are the indices of those elements of the sequence which are to be put out.

Output

The first line of the output file contains 0 if the «self-describing» sequence of length $$$k$$$ does not exist. Otherwise, the first line contains the number $$$n$$$, further, in the second line of the output file it is situated by the $$$n$$$ numbers separated by spaces — elements of the sequence with the indices specified in the input file in the order of appearance of these indices in the input file.

ExamplesInput
4
4
0 1 2 3
Output
4
1 2 1 0
Input
4
4
3 2 1 0
Output
4
0 1 2 1
Input
1
1
0
Output
0
Input
5
3
4 4 4
Output
3
0 0 0

加入题单

算法标签: