AT_past20_i 入れ替えパズル
Description
There is a grid with two horizontal rows and four vertical columns.
Each cell has a number written on it; the cell in the $ i $ -th row from the top and $ j $ -th column from the left has $ (i-1) \times 4 + j $ written on it.
You may perform the following two kinds of operations any number of times in any order.
- Choose two horizontally adjacent cells, and swap the numbers written on them.
- Choose two vertically adjacent cells, and swap the numbers written on them.
You are given $ A_{i,j} $ $ (1 \leq i \leq 2, 1 \leq j \leq 4) $ as the input.
At least how many operations are required to make the grid satisfy the following condition?
- For all $ i $ and $ j $ , $ A_{i,j} $ is written on the cell in the $ i $ -th row from the top and $ j $ -th column from the left.
Input Format
The input is given from Standard Input in the following format:
> $ A_{1,1} A_{1,2} A_{1,3} A_{1,4} $ $ A_{2,1} A_{2,2} A_{2,3} A_{2,4} $
Output Format
Print the minimum number of operations required to satisfy the condition in the problem statement.
Explanation/Hint
### Sample Explanation 1
For example, the condition in the problem statement can be satisfied with two operations as follows:
- Swap the number written on the cell in the $ 1 $ -st row from the top and $ 1 $ -st column from the left, and the number written on the cell in the $ 2 $ -nd row from the top and $ 1 $ -st column from the left.
- Swap the number written on the cell in the $ 1 $ -st row from the top and $ 3 $ -rd column from the left, and the number written on the cell in the $ 1 $ -st row from the top and $ 4 $ -th column from the left.
The condition cannot be satisfied with one operation or less, so $ 2 $ is the answer.
### Constraints
- $ 1 \leq A_{i,j} \leq 8 $
- $ A_{i,j} $ are distinct.
- All input values are integers.