Consider an infinite chessboard made up of square cells, extending infinitely in all directions. Let us designate one particular cell as the center. The vertical line passing through this center cell is labeled . The vertical lines to the right of the center are numbered 1, 2, 3, \ldots, while those to the left are -1, -2, -3, \ldots.
Similarly, horizontal lines are numbered with positive numbers above the center and negative numbers below. Thus, any cell can be identified by a pair of coordinates: the vertical and horizontal line numbers.
A king stands at the center cell, that is, at . The king is allowed to move to any adjacent cell—horizontally, vertically, or diagonally—according to the standard chess rules. However, some directions may be forbidden.
Your task is to determine the minimum number of moves the king needs to reach a cell at given coordinates .
The first line contains numbers indicating the allowed directions of movement. A means the direction is allowed, and a means it is forbidden. The directions are listed in counterclockwise order, starting from the positive horizontal direction (that is: right, right-up, up, left-up, left, left-down, down, right-down).
The second line contains the coordinates and of the target cell (-500 \leq x, y \leq 500).
Output a single integer—the minimum number of allowed moves the king needs to go from to . If it is not possible to reach the target cell, output -1.
Example 1