import java.io.FileInputStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.InputStream;
import java.util.List;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.io.FileOutputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author ilyakor
*/
public class Main {
public static void main
(String[] args
) { try {
}
try {
}
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskH solver = new TaskH();
try {
int testNumber = 1;
while (true)
solver.solve(testNumber++, in, out);
out.close();
}
}
}
class TaskH {
OutputWriter out;
public void solve(int testNumber, InputReader in, OutputWriter out) {
this.out = out;
int n = in.nextInt();
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
aOld[i][j] = a[i][j];
}
l = diag(n);
lRev = diag(n);
r = diag(n);
rRev = diag(n);
for (int i = 0; i < n; ++i) {
subMatrixGcd(i);
for (int j = i + 1; j < n; ++j) {
//Assert.assertTrue(a[j][i].mod(a[i][i]).equals(BigInteger.ZERO));
subtractRow(j, i, div);
}
for (int j = i + 1; j < n; ++j) {
//Assert.assertTrue(a[i][j].mod(a[i][i]).equals(BigInteger.ZERO));
subtractCol(j, i, div);
}
}
printMatr(l);
lRev = inverse(l);
printMatr(lRev);
printMatr(r);
rRev = inverse(r);
printMatr(rRev);
assertUni(diag);
diag = multiply(r, rRev);
assertUni(diag);
diag = multiply(multiply(l, aOld), r);
assertDiag(diag);
}
for (int i = 0; i < a.length; ++i)
for (int j = 0; j < a[i].length; ++j) {
if (i
== j
) Assert.
assertTrue(a
[i
][j
].
equals(BigInteger.
ONE)); else Assert.
assertTrue(a
[i
][j
].
equals(BigInteger.
ZERO)); }
}
for (int i = 0; i < a.length; ++i)
for (int j = 0; j < a[i].length; ++j) {
if (i == j) {
if (i
> 0 && a
[i
][i
].
compareTo(BigInteger.
ZERO) != 0) Assert.
assertTrue(a
[i
][i
].
abs().
mod(a
[i
- 1][i
- 1].
abs()).
equals(BigInteger.
ZERO)); } else Assert.
assertTrue(a
[i
][j
].
equals(BigInteger.
ZERO)); }
}
private void subtractRow
(int target,
int source,
BigInteger coef
) { for (int i = 0; i < a[target].length; ++i) {
a[target][i] = a[target][i].subtract(a[source][i].multiply(coef));
l[target][i] = l[target][i].subtract(l[source][i].multiply(coef));
}
}
private void multRow(int target, int coef) {
for (int i = 0; i < a[target].length; ++i) {
a
[target
][i
] = a
[target
][i
].
multiply(BigInteger.
valueOf(coef
)); l
[target
][i
] = l
[target
][i
].
multiply(BigInteger.
valueOf(coef
)); }
}
private void subtractCol
(int target,
int source,
BigInteger coef
) { for (int i = 0; i < a.length; ++i) {
a[i][target] = a[i][target].subtract(a[i][source].multiply(coef));
r[i][target] = r[i][target].subtract(r[i][source].multiply(coef));
}
}
private void multCol(int target, int coef) {
for (int i = 0; i < a.length; ++i) {
a
[i
][target
] = a
[i
][target
].
multiply(BigInteger.
valueOf(coef
)); r
[i
][target
] = r
[i
][target
].
multiply(BigInteger.
valueOf(coef
)); }
}
void swapRows(int x, int y) {
a[x] = a[y];
a[y] = tmp;
tmp = l[x];
l[x] = l[y];
l[y] = tmp;
}
void swapCols(int x, int y) {
for (int i = 0; i < a.length; ++i) {
a[i][x] = a[i][y];
a[i][y] = tmp;
tmp = r[i][x];
r[i][x] = r[i][y];
r[i][y] = tmp;
}
}
private void subMatrixGcd(int from) {
int n = a.length;
for (int col = n - 1; col >= from; --col) {
if (col + 1 < n) {
GcdRow(from, col, col + 1);
}
for (int row = from + 1; row < n; ++row) {
GcdCol(col, from, row);
}
}
}
void GcdCol(int col, int row1, int row2) {
if (a
[row1
][col
].
compareTo(BigInteger.
ZERO) < 0) { multRow(row1, -1);
}
if (a
[row2
][col
].
compareTo(BigInteger.
ZERO) < 0) { multRow(row2, -1);
}
while (a
[row2
][col
].
compareTo(BigInteger.
ZERO) != 0) { subtractRow(row1, row2, div);
swapRows(row1, row2);
}
}
void GcdRow(int row, int col1, int col2) {
if (a
[row
][col1
].
compareTo(BigInteger.
ZERO) < 0) { multCol(col1, -1);
}
if (a
[row
][col2
].
compareTo(BigInteger.
ZERO) < 0) { multCol(col2, -1);
}
while (a
[row
][col2
].
compareTo(BigInteger.
ZERO) != 0) { subtractCol(col1, col2, div);
swapCols(col1, col2);
}
}
for (int i = 0; i < a.length; ++i) {
out.print(x + " ");
out.printLine();
}
out.printLine();
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
return res;
}
int n = a.length;
for (int x = 0; x < n; ++x) {
for (int y = 0; y < n; ++y) {
for (int i = 0, row = 0; i < n; ++i) {
if (i == y) continue;
for (int j = 0, col = 0; j < n; ++j) {
if (j == x) continue;
minor[row][col] = a[i][j];
++col;
}
++row;
}
res[x][y] = div(val, det);
if ((x + y) % 2 == 1)
res[x][y] = res[x][y].negate();
}
}
return res;
}
int n = a.length;
int[] p = new int[n];
for (int i = 0; i < n; ++i) {
p[i] = i;
}
do {
int s = 1;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (p[i] > p[j]) s = -s;
for (int i = 0; i < n; ++i)
val = val.multiply(a[i][p[i]]);
res = res.add(val);
} while (Permutations.nextPermutation(p));
return res;
}
int n = a.length;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
res[i][j] = res[i][j].add(a[i][k].multiply(b[k][j]));
return res;
}
res = res.negate();
res = res.negate();
return res;
}
}
class OutputWriter {
}
public void print
(Object...
objects) { for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void printLine
(Object...
objects) { print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
class InputReader {
private byte[] buffer = new byte[10000];
private int cur;
private int count;
this.stream = stream;
}
public static boolean isSpace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int read() {
if (count == -1) {
throw new InputMismatchException();
}
try {
if (cur >= count) {
cur = 0;
count = stream.read(buffer);
if (count <= 0)
return -1;
}
throw new InputMismatchException();
}
return buffer[cur++];
}
public int readSkipSpace() {
int c;
do {
c = read();
} while (isSpace(c));
return c;
}
public int nextInt() {
int sgn = 1;
int c = readSkipSpace();
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res = res * 10 + c - '0';
c = read();
} while (!isSpace(c));
res *= sgn;
return res;
}
}
class Assert {
public static void assertTrue(boolean flag) {
if (!flag)
while (true);
// if (!flag)
// throw new AssertionError();
}
}
class Permutations {
public static boolean nextPermutation(int[] p) {
for (int a = p.length - 2; a >= 0; --a)
if (p[a] < p[a + 1])
for (int b = p.length - 1;; --b)
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
return false;
}
}