For his birthday, his friends bought Mosey a permutation of the first
Before he can sort his array, his friends challenge him to sort it using only
Mosey immediately points out that it might not be possible to sort the array, so his friends decide that they will be satisfied if Mosey can produce the lexicographically least possible output, using only the
Constraints
In other words, the unordered swap pairs will be pairwise distinct.
Subtask 1 [1/15]
Subtask 2 [2/15]
Subtask 3 [3/15]
For each
Subtask 4 [9/15]
No additional constraints.
Input Specification
The first line will contain two integers,
The next line will contain
The next
Output Specification
On the first line, output
On the next line, output the lexicographically least possible permutation.
On the next
Sample Input
4 4
4 2 3 1
1 2
2 3
3 4
4 1
Sample Output
3
1 2 3 4
3 2
1 4
3 2
Explanation for Sample Output
Note that it is not required that you output a sequence of moves of minimum length.
Comments
Data has been updated post-contest in order to prevent certain unintended solutions from passing.
:(