A board has rows and columns. Let denote the cell in the -th row from the top and the -th column from the left.
There is a barrier between every pair of horizontally adjacent cells and in the middle row (). There are no barriers between any other orthogonally adjacent cells.
Initially, cell contains one block labeled , and the first and third rows are empty. The sequence is a permutation of the integers from to .
In one move, you may move one block to an orthogonally adjacent empty cell. A block may not cross a barrier or leave the board.
Find the minimum number of moves needed to place the block labeled in cell for every .
The input is given in the following format:
Print the minimum number of moves needed to place every block in its target cell.
The first line contains the number of columns . The second line contains the block labels in the middle row from left to right, separated by spaces.
| 3 | 23 | (). |
| 4 | 46 | No additional constraints. |