Hide

Problem B
Power Grid

A city consists of a rectangular $N \times M$ grid of blocks. Each block $(i, j)$ has some unknown power consumption $A_{i, j}$. Some of the city blocks house power stations, while some might have no buildings in them at all, so it’s possible that $A_{i, j}$ is positive, negative or even zero.

Previously the city lived in an era of almost unlimited free energy thanks to cheap solar power, but after an incident involving the collisions of millions of Internet-providing satellites resulted in only half of all sunlight being able to reach Earth, your power plants have reverted to more expensive energy sources. As a result, the energy company must start billing its customers for their power usage. Unfortunately nobody bothered to install proper electricity meters.

While you lack measurements of block-level power usage, the company is able to use the power consumption on a row and column basis in the city to infer, for each block, a number

\[ C_{i, j} = \left| \sum _{k=1}^ N A_{k, j} - \sum _{k=1}^ M A_{i, k} \right| \text {,} \]

that is, the difference in the total power consumption of all blocks on the $i$’th row compared to the $j$’th column for each $i, j$.

Using these numbers, can you reconstruct the original power consumptions $A_{i, j}$?

Input

The first line contains the dimensions of the city $N$ and $M$ ($1 \le N, M \le 1\, 000$). This is followed by $N$ lines each containing $M$ integers, where the $j$’th number on the $i$’th line equals $C_{i, j}$ ($0 \le C_{i, j} \le 1\, 000$).

The input has been constructed in such a way that a solution always exists.

Output

Output $N$ lines each containing $M$ integers, where the $j$’th number on the $i$’th line equals $A_{i, j}$. If there are several possible choices of $A_{i, j}$ that are valid, you may output any of them.

The numbers $A_{i, j}$ must satisfy $-2147483648 \leq A_{i, j} \leq 2147483647$, otherwise you will get wrong answer.

Grading

Group

Score

Limits

$1$

$8$

$N,M,C_{i,j} \leq 3$

$2$

$5$

$N,M,C_{i,j} \leq 6$

$3$

$11$

$N = 1$

$4$

$6$

$N,M \geq 2$ and all numbers $C_{i,j}$ are the same

$5$

$15$

$N,M \geq 2$ and all numbers $C_{i,j}$ are different

$6$

$5$

$C_{i,j} \leq 1$

$7$

$15$

$N = M$

$8$

$25$

$N,M,C_{i,j} \leq 100$

$9$

$10$

No further constraints

Sample Input 1 Sample Output 1
2 3
3 4 1
6 7 2
1 2 6
5 3 4
Sample Input 2 Sample Output 2
3 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

Please log in to submit a solution to this problem

Log in