Type: Default 1000ms 64MiB

【例57.2】 上一个排列

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

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

20251025D班作业(4)

Not Claimed
Status
Done
Problem
12
Open Since
2025-10-26 0:00
Deadline
2025-11-3 23:59
Extension
24 hour(s)