Score : 1500 points
Given are an integer K and integers a_1,\dots, a_K. Determine whether a sequence P satisfying below exists. If it exists, find the lexicographically smallest such sequence.
Input is given from Standard Input in the following format:
K a_1 a_2 \dots a_K
If there is no sequence satisfying the conditions, print -1
.
Otherwise, print the lexicographically smallest sequence satisfying the conditions.
3 2 4 3
2 1 3 2 2 3 1 2 3
For example, the fifth term, which is 2, is in the subsequence (2, 3, 1) composed of the fifth, sixth, and seventh terms.
4 3 2 3 2
1 2 3 4 1 3 1 2 4 3
5 3 1 4 1 5
-1