Solitaire

No attempts yetTime limit1sMemory limit128 MB

Problem

Solitaire is a game played on an $8 \times 8$ chessboard. The rows and columns are numbered from $1$ to $8$ — rows from top to bottom, columns from left to right.

Four identical pieces sit on the board. In a single move you may either:

  • slide a piece onto an empty orthogonally adjacent field (up, down, left, or right), or
  • jump a piece over exactly one occupied orthogonally adjacent field, landing on the empty field immediately beyond it (up, down, left, or right).

In the configuration above, the piece at row $4$, column $4$ has four legal moves: one row up, two rows down (jumping the piece directly below it), one column left, or two columns right (jumping the piece directly to its right).

Given two configurations, decide whether the second one can be reached from the first in at most $8$ moves.

Input

Two lines, each describing one configuration of the four pieces.

Each line holds $8$ integers $a_1, a_2, \ldots, a_8$ separated by single spaces. For every $j$ with $1 \le j \le 4$, the pair $(a_{2j-1}, a_{2j})$ gives the row and column of one piece. Every coordinate lies between $1$ and $8$, and within a configuration the four pieces occupy four distinct fields.

Output

Print YES if the second configuration is reachable from the first in at most $8$ moves, and NO otherwise.