A square matrix of size that contains only zeros and ones, and only zeros in the diagonal, is called a binary matrix.
The Laplacian of a binary matrix is another square matrix with the following content:
All cells (i.e. the diagonal of ), are equal to the number of ones in row of .
Any other cell in contains the same value than the corresponding cell in but with opposite sign (since contains only 0 and 1, these cells will contain 0 or -1 accordingly).
For example, the following binary matrix :
0 1 1 0 0
1 0 0 1 1
0 1 0 0 1
1 1 1 0 1
0 0 0 0 0
has as Laplacian the following Matrix:
2 -1 -1 0 0
-1 3 0 -1 -1
0 -1 2 0 -1
-1 -1 -1 4 -1
0 0 0 0 0
Write a program that reads one binary matrix and prints its Laplacian following the format shown in the examples.
Input consists of a number , the dimension of the binary matrix, followed by integers describing the matrix: all of them either 0 or 1, where all the diagonal entries are zero.
The output must contain the Laplacian transform of the input matrix.
Input
3 0 1 0 0 0 1 1 1 0
Output
1 -1 0 0 1 -1 -1 -1 2
Input
4 0 1 1 0 1 0 0 1 1 1 0 1 0 1 1 0
Output
2 -1 -1 0 -1 2 0 -1 -1 -1 3 -1 0 -1 -1 2
Input
3 0 0 0 0 0 0 0 0 0
Output
0 0 0 0 0 0 0 0 0