#AT1698. B - Blocks on Grid

B - Blocks on Grid

B - Blocks on Grid

Score : $200$ points

Problem Statement

We have a grid with $H$ horizontal rows and $W$ vertical columns. The square at the $i$-th row from the top and $j$-th column from the left has $A_{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 \leq H,W \leq 100$
  • $0\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 $1$ block from the top-right square and $1$ from the bottom-left square makes all squares have $2$ blocks.


3 3
99 99 99
99 0 99
99 99 99
792

3 2
4 4
4 4
4 4
0