#P1002. Pawn's Safe Path
Pawn's Safe Path
Pawn's Safe Path
A pawn is positioned at point \(A(0,0)\) on a grid and must reach point \(B(n,m)\). It can only move either down or to the right. On the board, there is an opponent's knight at point \(C(x,y)\). The knight controls its own cell and the cells reachable by one knight move. In other words, the knight controls the following cells (if they lie within the grid):
[ \begin{array}{l} (x, y),\ (x+2, y+1),\quad (x+2, y-1),\ (x-2, y+1),\quad (x-2, y-1),\ (x+1, y+2),\quad (x+1, y-2),\ (x-1, y+2),\quad (x-1, y-2). \end{array} ]
The pawn must not step on any of these "controlled" cells. The grid has points with coordinates from \((0,0)\) to \((n,m)\) with \(A(0,0)\) as the start and \(B(n,m)\) as the destination. Calculate the total number of valid paths from \(A\) to \(B\) following the above movement rules and avoiding all controlled cells.
inputFormat
The first line contains two integers \(n\) and \(m\), representing the coordinates of point \(B\). The second line contains two integers \(x\) and \(y\), representing the knight's position \(C\). The grid includes all points \((i,j)\) where \(0 \le i \le n\) and \(0 \le j \le m\).
outputFormat
Output a single integer which is the number of valid paths from \(A(0,0)\) to \(B(n,m)\) that avoid the knight's controlled cells.
sample
2 2
1 1
2