LU decomposition of a band matrix

Factor a tridiagonal matrix into unit-diagonal L and upper U, printing -1 when the factors do not exist or a pivot is zero.

Medium5MatrixMathImplementationNo attempts yetTime limit3sMemory limit128 MB

Problem

You are given an N×NN \times N matrix AA. An LU decomposition splits AA into a product A=LUA = LU, where LL is a lower triangular matrix and UU is an upper triangular matrix.

  • A lower triangular matrix has Lij=0L_{ij} = 0 whenever i<ji < j.
  • An upper triangular matrix has Uij=0U_{ij} = 0 whenever i>ji > j.

This problem only deals with band matrices whose band has width 1. In other words, AA carries values on the main diagonal and on the two diagonals next to it, and every other entry is 0.

A=[b1c100a2b2c200an1bn1cn100anbn]A = \begin{bmatrix} b_1 & c_1 & 0 & \cdots & 0 \\ a_2 & b_2 & c_2 & \cdots & \vdots \\ 0 & \ddots & \ddots & \ddots & 0 \\ \vdots & \ddots & a_{n-1} & b_{n-1} & c_{n-1} \\ 0 & \cdots & 0 & a_n & b_n \end{bmatrix}

Find LL and UU such that every diagonal entry of LL is 1. When such a pair exists, it is unique.

Input

The first line contains the size NN of the square matrix (1N10001 \le N \le 1000). Each of the next NN lines contains the NN entries of one row of AA, in order.

Every entry is an integer with absolute value at most 1000, and every position with ij2|i - j| \ge 2 holds 0. For inputs whose decomposition exists, every entry of LL and UU has absolute value at most 10610^6.

Output

If the decomposition exists and no diagonal entry of UU is 0, print LL on NN lines and then UU on the next NN lines. Each line holds the NN entries of that row, separated by one space.

Round the exact value of each entry at the fourth decimal place and print three decimals. Round halves away from zero, so 0.06250.0625 becomes 0.063 and 0.0625-0.0625 becomes -0.063. When the rounded value is zero, print 0.000 without a sign.

If the decomposition is impossible, or some diagonal entry of UU is 0, print -1 on the first line and nothing else.