NPERM - Next Permuation
Given a permutation P of the integers between 1 and n, find the smallest permutation Q sctrictly greater than P.
Permutations are compared lexicographically.
In the first line there is an integer 1≤n≤105, the size of the permutation P.
In the next line, n different integers, 1 ≤ ai ≤ n, representing the permutation P.
Single line with n integers, containing the permutation Q, or "NO" if the permutation does not exist.
Output: 2 1
3 2 1