Consider a chess board with rows (indexed , , , from top to bottom) and columns (indexed , , , from left to right). Each position of the board is determined by a pair , where is the index of the row and is the index of the column.
Let us define the following game. We begin with a knight (see the figure to recall how it moves) at the upper left corner. Given a sequence of goal positions of the board , , ..., , we have to move the knight to goal position doing knight jumps; from there we have to get to goal position , doing knight jumps; and so on until getting to the last goal position . For each goal we reach, we get points. But for each knight jump we do, we lose points. The match is over when the next goal position cannot be reached, or we decide to stop moving. What is the maximum score that we can get if we play optimally?
Input contains different cases, only with integer numbers. Each case starts with and , followed by and . Finally, we have and the goal positions represented by pairs of integers separated by blank spaces, where and . It holds that , that , that and that .
For each case, write in a line the maximum score that can be achieved if we play optimally.
Input
3 3 10 1 1 2 1 3 3 10 1 2 0 2 1 0 3 3 10 1 4 0 0 2 1 0 2 0 2 3 3 10 1 1 1 1 3 3 10 1 2 2 1 1 1 2 13 7 3 3 0 4 1 10 0 12 8 8 25 3 4 5 6 7 6 3 4 2 0
Output
9 17 38 0 9 3 64