#K94562. Sudoku Solver

    ID: 38669 Type: Default 1000ms 256MiB

Sudoku Solver

Sudoku Solver

In this problem, you are given a 9x9 Sudoku puzzle represented as a grid of integers. Empty cells are represented by 0. Your task is to complete the board so that every row, every column, and every 3 \(\times\) 3 sub-grid contains all of the digits from 1 to 9. Formally, a Sudoku board is solved when:

  • Each row contains the digits \(1,2,\ldots,9\) without repetition.
  • Each column contains the digits \(1,2,\ldots,9\) without repetition.
  • Each of the nine \(3\times3\) sub-grids contains the digits \(1,2,\ldots,9\) without repetition.

If there exists a solution, output the solved board; otherwise, the input puzzle is unsolvable. It is guaranteed that the given puzzle has a unique solution.

inputFormat

The input consists of 9 lines. Each line contains 9 space-separated integers representing a row of the Sudoku grid. The integer 0 represents an empty cell.

outputFormat

Output the solved Sudoku board in the same format as the input: 9 lines with 9 space-separated integers on each line. If the board is already solved, simply output the board.

## sample
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9
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

</p>