CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #945 #947 →

#946. Next permutation

You get a list. Print the next permutation in lexicographic order. If it is the last one, print the first one (sorted in increasing order). ### Input The first line has n, the second line has n integers separated by spaces. ### Output One line.

Examples

Input
1
2
Output
2
Input
6
5 1 3 6 5 2
Output
5 1 5 2 3 6

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!