#P2525. Uim的情人节礼物·其之壱

Uim的情人节礼物·其之壱

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 NN (1N91\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 NN.

The second line contains NN integers, representing the original permutation.

Output Format

Output NN numbers, representing the previous permutation of the given permutation. Specifically, if the current permutation is already the first in lexicographic order, output ERROR.

3
1 3 2
1 2 3

Hint

Translated by ChatGPT 5