Under construction

Still being built. Things may change

Automatic Sprayer 2

Time limit2sMemory limit1024 MB

Summary
Given the matrix E where E[i][j] is the total Manhattan-distance-weighted spray from all cells, reconstruct any nonnegative integer matrix A that produces it.
Level

Hard8 of 10

Topics
Math, Implementation, Prefix sum, Matrix
Solved
No attempts yet

Problem

A farm is divided into n×nn \times n unit squares with nn rows and nn columns. Let (i,j)(i, j) denote the unit square in the ii-th row and the jj-th column (1≤i≤n1 \le i \le n, 1≤j≤n1 \le j \le n).

The distance between two squares (i1,j1)(i_1, j_1) and (i2,j2)(i_2, j_2) is the Manhattan distance d((i1,j1),(i2,j2))=∣i1−i2∣+∣j1−j2∣d\left(\left(i_1, j_1\right), \left(i_2, j_2\right)\right) = |i_1 - i_2| + |j_1 - j_2|.

The farm has automatic sprayers that spray fertilizer solution or herbicide so the owner can produce grain efficiently.

Each sprayer lies entirely in a unit square. The sprayer in (x,y)(x,y) sprays Ax,yA_{x,y} liters of solution onto every unit square. Ax,yA_{x,y} is a nonnegative integer.

For the sprayer in (x,y)(x, y) to spray solution onto (i,j)(i, j), the energy required is exactly d((x,y),(i,j))×Ax,yd((x, y), (i, j)) \times A_{x,y}. For each square (i,j)(i, j), let Ei,jE_{i,j} be the sum of energies needed for all sprayers to spray the square (i,j)(i, j).

Given the matrix EE, write a program that outputs any matrix AA that corresponds to EE. EE is given so that such a matrix AA of nonnegative integers whose sum is at most 101210^{12} exists.

Input

The first line contains a single positive integer nn (2≤n≤1 0002 \le n \le 1\,000).

The next nn lines each contain nn integers. The jj-th (1≤j≤n1 \le j \le n) integer in the ii-th (1≤i≤n1 \le i \le n) line is Ei,jE_{i,j} (0≤Ei,j≤10160 \le E_{i,j} \le 10^{16}).

The input is given so that a matrix AA consisting of only nonnegative integers whose sum is at most 101210^{12} exists and can produce EE.

Output

Output nn lines, each containing nn integers. The yy-th (1≤y≤n1 \le y \le n) integer in the xx-th (1≤x≤n1 \le x \le n) line is Ax,yA_{x,y}.

Examples2

  1. Example 1

    Input
    5
    4 3 2 3 4
    3 2 1 2 3
    2 1 0 1 2
    3 2 1 2 3
    4 3 2 3 4
    
    Expected output
    0 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    
  2. Example 2

    Input
    6
    43 34 25 24 33 42
    42 33 24 23 32 41
    41 32 23 22 31 40
    40 31 22 21 30 39
    39 30 21 20 29 38
    48 39 30 29 38 47
    
    Expected output
    0 0 4 0 0 0
    0 0 0 0 0 0
    0 0 0 0 0 0
    0 0 0 0 0 0
    0 0 0 5 0 0
    0 0 0 0 0 0