402350: GYM100735 E Restore

Memory Limit:64 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Restoretime limit per test0.25 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

Given a matrix A of size N * N. The rows are numbered from 0 to N-1, the columns are numbered from 0 to N-1. In this matrix, the sums of each row, the sums of each column, and the sum of the two diagonals are equal.

For example, a matrix with N = 3:

The sums of each row:

2 + 9 + 4 = 15

7 + 5 + 3 = 15

6 + 1 + 8 = 15

The sums of each column:

2 + 7 + 6 = 15

9 + 5 + 1 = 15

4 + 3 + 8 = 15

The sums of each diagonal:

2 + 5 + 8 = 15

4 + 5 + 6 = 15

As you can notice, all sums are equal to 15.

However, all the numbers in the main diagonal (the main diagonal consists of cells (i, i)) have been removed. Your task is to recover these cells.

Input

The first line contains the dimension of the matrix, n (1 ≤ n ≤ 100).

The following n lines contain n integers each, with removed numbers denoted by 0, and all other numbers  - 1012 ≤ Aij ≤ 1012.

Output

The restored matrix should be outputted in a similar format, with n lines consisting of n integers each.

ExamplesInput
3
0 9 4
7 0 3
6 1 0
Output
2 9 4 
7 5 3
6 1 8

加入题单

上一题 下一题 算法标签: