LearnPy Hub
← Arena
AdvancedRating 1500

Next Arrangement

Print the next lexicographic permutation of the numbers, or the smallest one if this is the last.

Input

n, then n integers.

Output

One line.

Sample 1

Input
3
1 2 3
Output
1 3 2

Sample 2

Input
3
3 2 1
Output
1 2 3
solution.py
Output appears here
Next Arrangement · Python Arena problem · LearnPy Hub