Two-dimensional domino#156

Two-dimensional domino

1 second
64 megabytes
Easy

Each element of a two-dimensional domino is a square, with its sides marked by numbers from to , written in binary. The domino is considered correctly assembled if every pair of adjacent squares has the same number on their common side.

Determine whether the domino is correctly assembled, and whether it is possible to add a given element so that it shares at least one side with one of the existing squares. The new element can be rotated in any direction, but cannot be flipped.

Input

The first line contains the dimensions of the rectangle containing the domino, separated by a space: 2 \leq N, M \leq 100. Each of the next lines describes the positions of the rectangle:

  • An empty position is denoted by ZZ.

  • A non-empty position is given as a hexadecimal string of one byte, where each pair of bits encodes the number on one of the sides. The sides are taken clockwise, starting from the left.

The last line contains the description of the element to be added. The addition must take place within the N \times M rectangle.

Output

The output should be one of the following three words:

  • ERROR (the domino is incorrectly assembled);

  • YES (the domino is correctly assembled and the element can be added);

  • NO (the domino is correctly assembled, but the element cannot be added).

Examples

Example 1

Loading
Loading