Consider a permutation of the first
Given
Constraints
Input Specification
The first line contains an integer,
The second line contains
Output Specification
If there is no sequence
Sample Input 1
Copy
3
1 2 2
Sample Output 1
Copy
1 3 2
Explanation for Sample Output 1
Note that
- The longest increasing subsequence of
is . - The longest increasing subsequence of
is . - One of the longest increasing subsequences of
is .
Sample Input 2
Copy
3
1 2 1
Sample Output 2
Copy
-1
Explanation for Sample Output 2
No possible permutation
Comments