P2525 Uim's Valentine's Day Gift · Part I
Description
Valentine's Day has arrived, and Uim plans to prepare Valentine's Day gifts for the members of his harem. Uim has a total of $N$ ($1\le N\le 9$) girls in his harem (normies go die and be ground to ashes!).
To maintain the stability of his harem, he wrote a program and obtained an optimal order for giving the gifts. That's not our concern.
However, he believes that making things too perfect is not necessarily a good thing. Therefore, he wants to obtain the sequence that is immediately previous to the original order in lexicographic order.
Input Format
The first line contains an integer $N$.
The second line contains $N$ integers, representing the original permutation.
Output Format
Output $N$ numbers, representing the previous permutation of the given permutation. Specifically, if the current permutation is already the first in lexicographic order, output `ERROR`.
Explanation/Hint
Translated by ChatGPT 5