Previous permutation
Easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Find the previous permutation in lexicographical order.
For the permutation (1, 2, 3, ..., N-1, N), the previous permutation is (N, N-1, ..., 3, 2, 1).
Input
The first line of the input contains the integer (N) ((1 N 10^5)), representing the number of elements in the permutation. The second line provides the permutation itself.
Output
Output (N) numbers representing the desired permutation.
Examples
Input #1
Answer #1
Submissions 304
Acceptance rate 34%