#P335. 【例57.2】 上一个排列
【例57.2】 上一个排列
Description
Everyone on Earth knows that from to (), these numbers can form different permutations. Now, if we sort these permutations in lexicographical order from smallest to largest, given one permutation, find its previous permutation.
Input Format
The first line contains an integer , representing the length of the permutation.
The second line contains integers separated by spaces, representing a permutation of the numbers from to .
Output Format
If the previous permutation exists, output it; otherwise, output "ERROR".
Sample
4
2 1 3 41 4 3 2
Related
In following homework: