All problems

Problem 488

Valid Sudoku

Medium · 20 pts · Matrix, Hash Table

Problem

Decide whether a partially filled 9 x 9 Sudoku board is valid. Only the filled cells need to be checked: no digit may appear twice in the same row, in the same column, or in the same 3 x 3 box. Empty cells are shown as '.'. A valid board does not have to be solvable; you only check the rules for the digits that are already there.

Input

9 lines of 9 characters each: digits 1-9 and '.' for empty cells.

Output

Print YES if the board is valid, otherwise NO.

Constraints

The board is always 9 x 9.

Example input

53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79

Example output

YES

Explanation

In this classic board every filled digit is unique within its row, its column and its 3 x 3 box, so the answer is YES.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Game of Life Next: Matrix Diagonal Sum