Problem: This is the easy version of the problem. The difference between the two versions is that you do not have to minimize the number of operations in this version. You can make hacks only if both versions of the problem are solved.
You have two permutations (of integers to ) and (of integers to ). Initially for , and for . You can apply the following operation on the permutations several (possibly, zero) times.
In one operation, and will change according to the following three steps:
- You choose integers , which satisfy and .
- Permutation is partitioned into three parts using as a pivot: the left part is formed by elements (this part may be empty), the middle part is the single element , and the right part is (this part may be empty). To proceed, swap the left and the right parts of this partition. Formally, after this step, will become . The elements of the newly formed will be reindexed starting from .
- Perform the same transformation on with index . Formally, after this step, will become . The elements of the newly formed will be reindexed starting from .
Your goal is to simultaneously make for , and for .
Find any valid way to achieve the goal using at most operations, or say that none exists. Please note that you do not have to minimize the number of operations.
It can be proved that if it is possible to achieve the goal, then there exists a way to do so using at most operations.
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Input Format: The first line contains two integers and ().
The second line contains integers ().
The third line contains integers ().
It is guaranteed that and are permutations.
Output Format: If there is no solution, print a single integer .
Otherwise, print an integer () — the number of operations to perform, followed by lines, each containing two integers and (, ) — the integers chosen for the operation.
If there are multiple solutions, print any of them.
Please note that you do not have to minimize the number of operations.
Note: In the first example, we can achieve the goal within operations:
- In the first operation, choose , . After this, becomes and becomes .
- In the second operation, choose , . After this, becomes and becomes .
In the third example, it is impossible to achieve the goal.