Training Site
Sideways banner

Magic Square

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 256 megabytes
Time limit: 1.0 seconds

A magic square is a square grid of numbers where the sums of each row, column, and both diagonals are the same.

You will be given a 3x3 magic square of positive integers. However, the magic square is incomplete – there are N missing elements, denoted by the value 0.

Solve the magic square.

Input

There will be three lines, each containing three space-separated integers, representing elements of the incomplete magic square.

Exactly N of the elements will be 0, indicating a missing value that must be found. All remaining elements will be between 1 and 10\,000 (inclusive).

Output

You should print three lines, each containing three space-separated integers, representing elements of the completed magic square.

It is guaranteed that there is a unique solution, and that all elements of the solution will be between 1 and 10\,000 (inclusive).

Subtasks

  • Subtask 1 (25%): N = 1
  • Subtask 2 (25%): 1 \le N \le 2
  • Subtask 3 (25%): 1 \le N \le 3
  • Subtask 4 (25%): 1 \le N \le 5
  • Sample Input 1

    3 3 6
    7 0 1
    2 5 5
    

    Sample Output 1

    3 3 6
    7 4 1
    2 5 5
    
  • Sample Input 2

    6 1 0
    7 0 3
    0 9 4
    

    Sample Output 2

    6 1 8
    7 5 3
    2 9 4