The next permutation
Easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Find the next permutation. Assume that permutation is followed by the identity .
Input
First line contains the number of elements in the permutation. Second line contains a permutation of integers.
Output
Print numbers — the next permutation for the given one.
Examples
Input #1
Answer #1
Submissions 2K
Acceptance rate 38%