Fred Lever just learned that knights in Chess are very good at forking, which is when they attack multiple pieces simultaneously. To practice this skill, he uses a by
board with
rooks on it. For simplicity, the top-left cell is denoted as
and the bottom-right as
. Every rook is placed on a distinct cell
on the board. Fred wants to know how many cells he can place a knight on the board that forks two or more rooks, without the knight being attacked (or on the same cell of a rook).
Remember, knights in Chess may move from a cell
to cells
or cells
and rooks may move from a cell
to cells
or cells
where
is a nonzero integer. However, all pieces must stay on the board.
.....
.....
.R.R.
.....
..K..
The above figure is an example of a knight (K
) forking two rooks (R
) on a by
board. Note that the knight can also fork the rooks if it were placed at
.
Constraints
For all subtasks,
all are pairwise distinct.
Subtask 1 [25%]
Subtask 2 [75%]
No additional constraints.
Input Specification
The first line will contain two integers and
, space-separated.
The next lines will contain two integers
and
, denoting the location of a rook on the board.
Sample Input 1
5 2
3 2
3 4
Sample Output 1
2
Explanation for Sample Output 1
This is the example in the problem statement.
Sample Input 2
6 4
4 3
4 5
4 1
3 4
Sample Output 2
3
Explanation for Sample Output 2
......
.K...K
...R..
R.R.R.
......
.K....
The above figure shows where knights can be placed to fork two or more rooks. Note that is not a valid cell as the knight would be attacked by the rook on
.
Comments