Олимпиадный тренинг

Задача 38202. Chess domino


A set of chess dominoes consists of 32 2x1 tiles, each of the squares of which is colored black or white (some of the tiles consist of two white squares, some of them are two black ones, and some of them are one white and one black). A set of such dominoes is laid out on a chessboard. It is allowed to rotate dominoes by 180 degrees (swap their squares), leaving each domino in its place. It is required to find out whether it is possible to rotate some of the dominoes in such a way that each horizontal row contains squares of only one color.


Input
Enter 8 lines of 8 numbers. Each number corresponds to the number of the domino that covers the given cell. The number is positive if the domino square is white and negative – if black.


Imprint
It is required to output one word – YES or NO (in capital letters).
Examples
# Input Output
1 1   2  2  7  7  8   8   9
  1  3  6  10  10  11  11   9
  4   3  6  31  31  24  23  12
  4   5  5  30  32  24  23  12
 28  29  29  30  32  25  22  13
 28  27  27  26  26  25  22  13
 18  19  19  20 ​​ 20 ​​ 21  21  14
 18  17  17  16  16  15  15  14
YES

Note:
Dominoes are numbered from 1 to 32 in random order.