#P1130C. Connect
Connect
Description
Alice lives on a flat planet that can be modeled as a square grid of size , with rows and columns enumerated from to . We represent the cell at the intersection of row and column with ordered pair . Each cell in the grid is either land or water.

Alice resides in land cell . She wishes to travel to land cell . At any moment, she may move to one of the cells adjacent to where she is—in one of the four directions (i.e., up, down, left, or right).
Unfortunately, Alice cannot swim, and there is no viable transportation means other than by foot (i.e., she can walk only on land). As a result, Alice's trip may be impossible.
To help Alice, you plan to create at most one tunnel between some two land cells. The tunnel will allow Alice to freely travel between the two endpoints. Indeed, creating a tunnel is a lot of effort: the cost of creating a tunnel between cells and is .
For now, your task is to find the minimum possible cost of creating at most one tunnel so that Alice could travel from to . If no tunnel needs to be created, the cost is .
The first line contains one integer () — the width of the square grid.
The second line contains two space-separated integers and () — denoting the cell where Alice resides.
The third line contains two space-separated integers and () — denoting the cell to which Alice wishes to travel.
Each of the following lines contains a string of characters. The -th character of the -th such line () is 0 if is land or 1 if is water.
It is guaranteed that and are land.
Print an integer that is the minimum possible cost of creating at most one tunnel so that Alice could travel from to .
Input
The first line contains one integer () — the width of the square grid.
The second line contains two space-separated integers and () — denoting the cell where Alice resides.
The third line contains two space-separated integers and () — denoting the cell to which Alice wishes to travel.
Each of the following lines contains a string of characters. The -th character of the -th such line () is 0 if is land or 1 if is water.
It is guaranteed that and are land.
Output
Print an integer that is the minimum possible cost of creating at most one tunnel so that Alice could travel from to .
Note
In the first sample, a tunnel between cells and should be created. The cost of doing so is , which is optimal. This way, Alice could walk from to , use the tunnel from to , and lastly walk from to .
In the second sample, clearly a tunnel between cells and needs to be created. The cost of doing so is .