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

Задача 38341. Check if the situation is correct


Write a program that, according to the image of the field for playing Tic-Tac-Toe will determine whether such a situation could have arisen as a result of playing with all the rules.

Recall that the game of "Tic-tac-toe" is conducted on the field 3×3. The two players take turns. The first puts a cross, and the second – zero. Putting a cross and a zero is allowed in any cell of the field that has not yet been occupied. When one of the players puts three of his signs in one horizontal, vertical or diagonal line, or when all the cells of the field are occupied, the game ends.

Input
Enter three lines of three numbers each, describing the playing field. The number 0 denotes an empty cell, 1 – cross, 2 – zero. Numbers in a string are separated by spaces.

Imprint
It is required to output the word YES if the indicated situation could have occurred during the game, and NO otherwise.
Examples
# Input Output
1 1 1 1
1 1 1
1 1 1
NO
2 2 1 1
1 1 2
2 2 1
YES
3 1 1 1
2 0 2
0 0 0
YES
4 0 0 0
0 1 0
0 0 0
YES
5 1 1 1
2 2 2
0 0 0
NO