Under construction

Still being built. Things may change

Inverse Matrix

Time limit1sMemory limit128 MB

Summary
Invert the given N by N matrix modulo 998244353 and print no inverse when the matrix is singular.
Level

Medium4 of 10

Topics
Matrix, Number theory
Solved
No attempts yet

Problem

P=998244353P = 998244353 is a prime. Given an N×NN \times N integer matrix AA, write a program that computes the inverse of AA modulo PP.

A matrix BB with AB≡BA≡IN(modP)AB \equiv BA \equiv I_N \pmod P is called the inverse of AA and is written A−1A^{-1}. Two matrices are congruent when the entries in every matching position are congruent modulo PP. INI_N is the N×NN \times N identity matrix, where Ii,j=0I_{i,j} = 0 for i≠ji \ne j and Ii,i=1I_{i,i} = 1.

PP is prime, so the inverse is unique whenever it exists. It exists exactly when the determinant of AA is not a multiple of PP. A matrix whose determinant over the integers is nonzero still has no inverse modulo PP if that determinant is divisible by PP.

Input

The first line contains the size NN of the matrix. (1≤N≤5001 \le N \le 500)

Each of the next NN lines describes one row of AA and contains NN integers. The absolute value of each integer is at most 1,000. A negative entry is read as its residue modulo PP.

Output

If the inverse of AA modulo PP exists, print A−1A^{-1} over NN lines. Each line holds NN integers separated by a single space, and every integer is at least 00 and less than PP.

If the inverse does not exist, print no inverse.

Examples3

  1. Example 1

    Input
    2
    1 3
    2 7
    
    Expected output
    7 998244350
    998244351 1
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    2
    1 2
    2 4
    
    Expected output
    no inverse