Due to foreseen circumstances that were well within his control, P has found himself in quite a predicament - having to solve space-bending mazes.
The maze is presented as an n x n matrix . P can enter the matrix from any corner of the maze, but the exit lies in the maze at a position
. At position
, he can be teleported to a position
away (e.g. position
) within the maze (i.e. no wrap around). Determine if the maze is solvable.
Input
The first line contains an integer , the size of the maze.
The second line contains two integers
, the position of the exit.
The following
lines contains a row in the matrix
.
Output
if we can reach the exit from any of the four corners otherwise
.
Constraints
Example 1
Input
3
2 2
1 3 0
1 0 1
0 2 1
Output
True
Example 2
Input
5
3 4
3 4 0 1 2
3 2 1 4 0
4 1 3 0 2
4 2 3 0 1
0 4 2 1 3
Output
False
Comments