#C14974. Sudoku Board Validator

    ID: 44682 Type: Default 1000ms 256MiB

Sudoku Board Validator

Sudoku Board Validator

You are given a 9x9 Sudoku board represented as a two-dimensional array. The board may contain the integer 0 to denote an empty cell. Your task is to check whether the board is valid. A board is considered valid if it satisfies the following constraints:

  • Each row contains the integers 1 through 9 at most once.
  • Each column contains the integers 1 through 9 at most once.
  • Each of the nine 3x3 sub-boxes contains the integers 1 through 9 at most once.

Formally, if we denote the Sudoku board as a matrix \(A\) where \(A_{ij}\) is the element in the \(i^{th}\) row and \(j^{th}\) column, the board is valid if for every row \(i\), column \(j\) and each subgrid, the set of nonzero numbers is contained within \(\{1,2,...,9\}\) with no duplicates.

Your program should read the board from standard input (stdin) and print either True or False to standard output (stdout) depending on whether the board is valid.

inputFormat

The input consists of 9 lines, each containing 9 space-separated integers. Each integer is between 0 and 9 inclusive where 0 represents an empty cell.

outputFormat

Print True if the board is valid according to the rules of Sudoku, or False otherwise. The output is case-sensitive.

## sample
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
True