Maximize the matrix sum

No attempts yetTime limit2sMemory limit256 MB

Problem

You are given a matrix with RR rows and CC columns. Every cell holds one integer, and you may apply the four operations below in any order, as many times as you like.

NotationMeaning
rotR i kRotate row ii to the right by kk cells. (1iR1 \le i \le R, 1k<C1 \le k < C)
rotC j kRotate column jj downward by kk cells. (1jC1 \le j \le C, 1k<R1 \le k < R)
negR iMultiply every element of row ii by 1-1. (1iR1 \le i \le R)
negC jMultiply every element of column jj by 1-1. (1jC1 \le j \le C)

Applying each operation once to the matrix (123456789)\begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix} gives the following results.

  • rotR 3 1 gives (123456978)\begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 9 & 7 & 8 \end{pmatrix}.
  • rotC 1 2 gives (423756189)\begin{pmatrix} 4 & 2 & 3 \\ 7 & 5 & 6 \\ 1 & 8 & 9 \end{pmatrix}.
  • negR 2 gives (123456789)\begin{pmatrix} 1 & 2 & 3 \\ -4 & -5 & -6 \\ 7 & 8 & 9 \end{pmatrix}.
  • negC 2 gives (123456789)\begin{pmatrix} 1 & -2 & 3 \\ 4 & -5 & 6 \\ 7 & -8 & 9 \end{pmatrix}.

Find the largest sum of all elements of the matrix that you can reach.

Input

The first line contains two natural numbers R and C (1R,C1001 \le R, C \le 100), separated by a space.

Each of the next R lines contains C integers separated by spaces. The absolute value of each integer is at most 10410^4.

Output

Print the largest reachable sum of all elements on the first line. Do not print the list of operations you used.