Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-sudoku-tekshirish

Sudoku check

Medium 1000 ms 128 MB 53%
Share

A completely filled $9 \times 9$ sudoku is given. If every row, every column and each of the nine $3 \times 3$ blocks contains each digit from $1$ to $9$ exactly once, print YES, otherwise print NO.

A correctly filled nine by nine sudoku grid

Input

The first line contains two positive integers $9$ and $9$. Each of the next $9$ lines contains $9$ integers.

Output

YES or NO.

Note

$1 \le a_{i,j} \le 9$

Examples

Input #1
9 9
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8
Output #1
YES
Input #2
9 9
2 1 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8
Output #2
NO

Sign in to submit a solution

Signing up is free and takes a minute.