PROGRAMMING:Lexicographic order of permutations
N elements {1, 2,..., n} have n! There are two different arrangements. Put this n! They are arranged in dictionary order and numbered 0, 1,..., n- 1 。 The number of each permutation is its lexicographic value. For example, when n = 3, the dictionary order values of six different permutations are as follows:
|Dictionary order value | 0 | 1 | 2 | 3 | 4 | 5|
| -------- | ---- | ---- | ---- | ---- | ---- | ---- |
|Arrangement | 123 | 132 | 213 | 231 | 312 | 321|
###Input format:
The first line is the number of elements n (1 < n < = 8), and the next line is an arrangement of n elements {1,2,..., n}. The title does not give the last permutation.
###Output format:
The first line outputs the lexicographic value of the calculated permutation, and the second line outputs the next permutation in lexicographic order.
###Input example:
```in
three
2 3 1
```
###Output example:
```out
three
3 1 2
```
answer:If there is no answer, please comment
|Dictionary order value | 0 | 1 | 2 | 3 | 4 | 5|
| -------- | ---- | ---- | ---- | ---- | ---- | ---- |
|Arrangement | 123 | 132 | 213 | 231 | 312 | 321|
###Input format:
The first line is the number of elements n (1 < n < = 8), and the next line is an arrangement of n elements {1,2,..., n}. The title does not give the last permutation.
###Output format:
The first line outputs the lexicographic value of the calculated permutation, and the second line outputs the next permutation in lexicographic order.
###Input example:
```in
three
2 3 1
```
###Output example:
```out
three
3 1 2
```
answer:If there is no answer, please comment