atcoder#ARC135D. [ARC135D] Add to Square
[ARC135D] Add to Square
Score : points
Problem Statement
We have an grid, where each square has one integer written on it. For and , let denote the integer written on the square at the -th row and -th column.
You can do the operation below any number of times (possibly zero).
- Choose integers and such that and .
- Choose another integer .
- Add to each of , , , and .
Print the minimum possible value of after your operations, and the integers on the grid when that value is achieved.
Constraints
Input
Input is given from Standard Input from the following format:
Output
Print lines. The -st line should contain the value of . The -nd through -th lines should contain the integers on the grid, in the following format:
If there are multiple solutions, you may print any of them.
2 3
1 2 3
4 5 6
9
0 -3 -1
3 0 2
Here is a sequence of operations that produces the grid in the Sample Output.
- Do the operation with .
- Do the operation with .
Here, we have $\sum_{i=1}^H \sum_{j=1}^W |A_{i,j}| = 0 + 3 + 1 + 3 + 0 + 2 = 9$.
2 2
1000000000 -1000000000
-1000000000 1000000000
4000000000
2000000000 0
0 2000000000
It is fine if after your operations.
3 4
0 2 0 -2
-3 -1 2 0
-3 -3 2 2
0
0 0 0 0
0 0 0 0
0 0 0 0