[Login|Register]
Problems

Status

Rank

Statistics

Problem A
Matrix Sum
Time Limit: 1000ms
Memory Limit: 65536kb
Description

Bob is a mathematician. One day Bob discovers a kind of matrix sum. He denotes it as [A] (A is a square matrix). This is how [A] is defined:

Suppose A=(a_ij)n*n is a matrix, then
  [A]=a_11*[A11]-a_12*[A12]+a_13*[A13]+...+(-1)^(n-1)*a_1n*[A1n],   if n>=2;
  [A]=a_11,  if n=1.
Aij is the matrix got by deleting row i and column j from matrix A. For example:
    1 2 3          4  6
  A=4 5 6      A12=
    7 8 9          7  9
Bob discovers that this sum has wonderful properties. In order to understand it more clearly, he needs to calculate some [Aij], but it's difficult for him when the matrix is large. Now, Bob needs your help. Can you write a program to work them out?
Input
There are at most 20 test cases. The first line of each case is an integer n (2<=n<=8). The following n lines are a matrix A=(a_ij)n*n. All matrix elements are integers in the range [0,9]. It is guaranteed that the matrix sum [A] is not zero.
A case with n=0 marks the end of input. This case should not be processed.
Output
For each case, print n lines with n integers each. The j-th integer on the i-th line is the value of [Aij]. The adjacent integers are separated with a space.
Sample Input
2
1 0
0 1
3
0 1 2
3 2 3
4 0 2
0
Sample Output
1 0
0 1
4 -6 -8
2 -8 -4
-1 -6 -3
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.5ms with 2 query(s).