Score : $2000$ points
You are given a permutation $P_1 ... P_N$ of the set {$1$, $2$, ..., $N$}.
You can apply the following operation to this permutation, any number of times (possibly zero):
Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.
The input is given from Standard Input in the following format:
$N$ $K$ $P_1$ $P_2$ $...$ $P_N$
Print the lexicographically smallest permutation that can be obtained.
4 2 4 2 3 1
2 1 4 3
One possible way to obtain the lexicographically smallest permutation is shown below:
5 1 5 4 3 2 1
1 2 3 4 5
8 3 4 5 7 8 3 1 2 6
1 2 6 7 5 3 4 8