Maximize the matrix sum
Time limit2sMemory limit256 MB
Reorder entries by rotating rows and columns and flipping row and column signs to maximize the sum of all cells.
Problem
You are given a matrix with rows and columns. Every cell holds one integer, and you may apply the four operations below in any order, as many times as you like.
Applying each operation once to the matrix gives the following results.
rotR 3 1gives .rotC 1 2gives .negR 2gives .negC 2gives .
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 (), 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 .
Output
Print the largest reachable sum of all elements on the first line. Do not print the list of operations you used.