Previous permutation#4839

Previous permutation

1 second
64 megabytes
Easy

Find the previous permutation in lexicographical order.

For the permutation 1, 2, 3, \ldots, N-1, N, the previous permutation is N, N-1, \ldots, 3, 2, 1.

Input

The first line of the input contains the integer (1 \leq N \leq 10^5), representing the number of elements in the permutation. The second line provides the permutation itself.

Output

Output numbers representing the desired permutation.

Examples

Example 1

Loading
Loading