QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#15368. Decryption Operation

Statistics

Little J is a diligent university student studying in the Department of Computer Science at Tsinghua University, and he encounters many challenging problems every day.

Today, Little J's teacher taught a string encryption algorithm in class. For a string of length $N$, we add a special character "." to the end of the string. Then, we treat the string as a cycle and read out $N+1$ strings starting from positions $1, 2, 3, \dots, N+1$. This gives us $N+1$ strings.

For example, for the string "ABCAAA", we can obtain these $N+1$ strings:

ABCAAA. BCAAA.A CAAA.AB AAA.ABC AA.ABCA A.ABCAA .ABCAAA

Next, we sort these $N+1$ strings in lexicographical order from smallest to largest (note that the special character "." is lexicographically smaller than any other character). The result is as follows:

.ABCAAA A.ABCAA AA.ABCA AAA.ABC ABCAAA. BCAAA.A CAAA.AB

Finally, we take the last character of each of the $N+1$ sorted strings and arrange them in order to form a new string. This is the last column of the table above, which is the encrypted ciphertext "AAAC.AB".

The clever Little J quickly understood the encryption algorithm, but due to limited class time, the teacher finished the lecture before explaining the decryption algorithm. Curious, Little J really wants to know how to decrypt the string, i.e., how to find the original string from the encrypted ciphertext. Can you help him solve this problem?

Input

The first line contains two integers $N$ and $M$, representing the length of the string before encryption and the size of the character set, respectively. The characters are numbered with integers $1, 2, 3, \dots, M$, and the added special character "." is numbered $0$.

The second line contains $N+1$ integers, representing the encrypted string.

Output

Output a single line containing $N$ integers, separated by spaces, representing the numbers of the characters in the string before encryption in order.

Examples

Input 1

6 3
1 1 1 3 0 1 2

Output 1

1 2 3 1 1 1

Note

If we treat $1, 2, 3$ in the sample input and output as A, B, and C respectively, the sample is exactly the string described in the problem statement.

Constraints

The scale of the test data is as follows:

ID $N$ $M$ Special Conditions
1 $= 10$
2 $= 15$ $\le 3$ None
3 $= 20$
4 $= 25$
5-6 $\le 50$ $\le 50$ Characters in the string are distinct
7-8 $\le 1,000$ $\le 1,000$
9-12 $\le 1,000$ $\le 1,000$ None
13-20 $\le 200,000$ $\le 200,000$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.