#P335. 【例57.2】 上一个排列

【例57.2】 上一个排列

Description

Everyone on Earth knows that from 11 to nn (1n91≤n≤9), these nn numbers can form n!n! different permutations. Now, if we sort these nn permutations in lexicographical order from smallest to largest, given one permutation, find its previous permutation.

Input Format

The first line contains an integer nn, representing the length of the permutation.
The second line contains nn integers separated by spaces, representing a permutation of the numbers from 11 to nn.

Output Format

If the previous permutation exists, output it; otherwise, output "ERROR".

Sample

4
2 1 3 4
1 4 3 2