Trunk Roads

Choose one horizontal and one vertical line in an H by W grid to minimize the total distance residents at each cell pay to the nearer chosen line.

Medium5Brute forcePrefix sumMathNo attempts yetTime limit2sMemory limit512 MB

Problem

JOI City is cut into a grid by HH roads that run straight from east to west and WW roads that run straight from north to south. Neighbouring parallel roads are 11 apart. The city will choose 22 of these H+WH + W roads as trunk roads: one east-west road and one north-south road.

Call the point where the ii-th east-west road from the north (1iH1 \le i \le H) meets the jj-th north-south road from the west (1jW1 \le j \le W) intersection (i,j)(i, j). The distance between intersection (i,j)(i, j) and the mm-th east-west road from the north (1mH1 \le m \le H) is im|i - m|, and the distance between intersection (i,j)(i, j) and the nn-th north-south road from the west (1nW1 \le n \le W) is jn|j - n|. Ai,jA_{i,j} residents live near intersection (i,j)(i, j).

Each resident pays the distance from the intersection where they live to whichever of the two trunk roads is closer. Over all ways of choosing the 22 trunk roads, find the smallest possible total paid by all residents.

Input

Input is given from standard input in the following format.

H W
A_{1,1} A_{1,2} ... A_{1,W}
...
A_{H,1} A_{H,2} ... A_{H,W}

The first line contains HH and WW separated by a space. The ii-th of the next HH lines contains Ai,1,Ai,2,,Ai,WA_{i,1}, A_{i,2}, \dots, A_{i,W} separated by spaces.

Output

Print on one line the smallest possible total paid by all residents.

Constraints

  • 2H252 \le H \le 25
  • 2W252 \le W \le 25
  • 0Ai,j1000 \le A_{i,j} \le 100 (1iH1 \le i \le H, 1jW1 \le j \le W)