#agc046e. [agc046_e]Permutation Cover
[agc046_e]Permutation Cover
Problem Statement
Given are an integer and integers . Determine whether a sequence satisfying below exists. If it exists, find the lexicographically smallest such sequence.
- Every term in is an integer between and (inclusive).
- For each , contains occurrences of .
- For each term in , there is a contiguous subsequence of length that contains that term and is a permutation of .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If there is no sequence satisfying the conditions, print -1
. Otherwise, print the lexicographically smallest sequence satisfying the conditions.
Sample Input 1
3
2 4 3
Sample Output 1
2 1 3 2 2 3 1 2 3
For example, the fifth term, which is , is in the subsequence composed of the fifth, sixth, and seventh terms.
Sample Input 2
4
3 2 3 2
Sample Output 2
1 2 3 4 1 3 1 2 4 3
Sample Input 3
5
3 1 4 1 5
Sample Output 3
-1