Task 27

lu_decomposition (256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

LU decomposition

Work over the finite field

\[ \mathbb{F}_p, \qquad p = 1\,000\,000\,007. \]

You are given an \(n\times n\) matrix \(A\). Find matrices \(L\) and \(U\)
such that

\[ A=LU \pmod p. \]

The decomposition must use unit lower-triangular \(L\): all entries above its
diagonal are zero and \(L_{i,i}=1\). Matrix \(U\) must be upper triangular,
so all entries below its diagonal are zero.

The test matrices are guaranteed to admit such a decomposition without row
permutations. Any valid pair \((L,U)\) is accepted.

Input

The first line contains \(n\). The next \(n\) lines contain \(A\), with \(n\)
entries per line.

Output

Print the \(n\) rows of \(L\), followed immediately by the \(n\) rows of
\(U\). Each row contains \(n\) integers.

All arithmetic, including the matrix product \(LU\), is modulo \(p\). Any
integer representative of an entry is accepted.

Sample test

Input
2
3 999999997
18 999999953

Output is validated by a special checker; any valid answer is accepted.