#ABC186B. [ABC186B] Blocks on Grid

[ABC186B] Blocks on Grid

提示:该题测试数据补录中,暂不支持评测提交。

No testdata at current.

No submission language available for this problem.

Score : 200200 points

Problem Statement

We have a grid with HH horizontal rows and WW vertical columns. The square at the ii-th row from the top and jj-th column from the left has Ai,jA_{i, j} blocks stacked on it.

At least how many blocks must be removed to make all squares have the same number of blocks?

Constraints

  • 1≤H,W≤1001 \leq H,W \leq 100
  • 0≤Ai,j≤1000\leq A_{i,j} \leq 100

Input

Input is given from Standard Input in the following format:

HH WW

A1,1A_{1,1} A1,2A_{1,2} …\ldots A1,WA_{1,W}

⋮\vdots

AH,1A_{H,1} AH,2A_{H,2} …\ldots AH,WA_{H,W}

Output

Print the minimum number of blocks that must be removed.

2 3
2 2 3
3 2 2
2

Removing 11 block from the top-right square and 11 from the bottom-left square makes all squares have 22 blocks.

3 3
99 99 99
99 0 99
99 99 99
792
3 2
4 4
4 4
4 4
0