Lame King High
Consider an infinite chessboard that extends indefinitely in all directions, composed of square cells. Let's identify a specific cell as the center. The vertical line passing through this center cell is labeled as 0. The vertical lines to the right of the center are numbered sequentially as 1, 2, 3, and so on, while those to the left are labeled as -1, -2, -3, etc. Similarly, the horizontal lines are numbered, with lines above the center having positive numbers and those below having negative numbers. Thus, the coordinates of any cell are given by a pair of numbers representing the vertical and horizontal lines it intersects.
Imagine a king positioned at the center of the board, specifically at the cell with coordinates (0, 0). The king moves according to standard chess rules, meaning it can move to any adjacent cell horizontally, vertically, or diagonally. However, certain directions may be restricted.
Your task is to determine the minimum number of moves required for the king to reach a cell with given coordinates (x, y).
Input
The first line of the input contains 8 numbers, each indicating whether movement in a specific direction is allowed. A 1 means the direction is permitted, while a 0 means it is not. These directions are listed in counterclockwise order, starting from the positive horizontal direction (i.e., right, right-up, up, left-up, left, left-down, down, right-down). The second line provides the coordinates x and y of the target cell (-10^18 ≤ x, y ≤ 10^18).
Output
Output a single integer representing the minimum number of allowed moves the king needs to make to travel from the cell (0, 0) to the cell (x, y). If it is impossible to reach the target cell, output -1.