matrix_inverse

(256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

Matrix inverse

Work in the finite field

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

You are given an \(n\times n\) matrix \(A\). If there is a matrix
\(A^{-1}\) satisfying

\[ AA^{-1}=A^{-1}A=I \pmod p, \]

output it. Otherwise, report that \(A\) is singular.

Input

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

Output

If \(A\) is singular, print:

NO

Otherwise print `YES`, followed by the \(n\) rows of \(A^{-1}\), with \(n\)
integers per row.

All arithmetic is modulo \(p\), and any integer representative of an entry is
accepted.

Constraints