#P1783F. Double Sort II
Double Sort II
No submission language available for this problem.
Description
You are given two permutations and , both of size . A permutation of size is an array of elements, where each integer from to appears exactly once. The elements in each permutation are indexed from to .
You can perform the following operation any number of times:
- choose an integer from to ;
- let be the integer such that . Swap with ;
- let be the integer such that . Swap with .
Your goal is to make both permutations sorted in ascending order (i. e. the conditions and must be satisfied) using minimum number of operations. Note that both permutations must be sorted after you perform the sequence of operations you have chosen.
The first line contains one integer ().
The second line contains integers (; all are distinct).
The third line contains integers (; all are distinct).
First, print one integer () — the minimum number of operations required to sort both permutations. Note that it can be shown that operations are always enough.
Then, print integers (), where is the value of you choose during the -th operation.
If there are multiple answers, print any of them.
Input
The first line contains one integer ().
The second line contains integers (; all are distinct).
The third line contains integers (; all are distinct).
Output
First, print one integer () — the minimum number of operations required to sort both permutations. Note that it can be shown that operations are always enough.
Then, print integers (), where is the value of you choose during the -th operation.
If there are multiple answers, print any of them.