Consider an infinite chessboard that extends indefinitely in all directions, composed of square cells. Let us define one cell as the center. The vertical line passing through the center cell is numbered . The vertical lines to the right are numbered consecutively as , , , and so on, while those to the left are , , , etc. The horizontal lines are similarly numbered: those above the center are positive, those below are negative. Thus, the coordinates of any cell are given by a pair of numbers corresponding to the vertical and horizontal lines it is located at.
Suppose a king stands at the center of the board, at cell . The king may move, according to the standard chess rules, to any adjacent cell—horizontally, vertically, or diagonally. However, some directions may be forbidden.
Your task is to determine the minimum number of moves required for the king to reach a cell with given coordinates .
The first line contains integers, each indicating whether movement in a specific direction is allowed. A means the direction is permitted, a means it is not. These directions are listed in counterclockwise order, starting with the positive horizontal direction (right, right-up, up, left-up, left, left-down, down, right-down). The second line contains the coordinates and of the target cell, where -10^{18} \leq x, y \leq 10^{18}.
Output a single integer: the minimum number of allowed moves the king must make to travel from to . If it is impossible to reach the target cell, output .
Esempio 1