All problems

Problem 985

Score After Flipping Matrix

Medium · 20 pts · Matrix, Greedy, Bit Manipulation

Problem

A binary matrix is given. A move flips an entire row or an entire column (every 0 becomes 1 and every 1 becomes 0). After any number of moves, each row is read as a binary number, and the score is the sum of these numbers. Maximise the score. The leading bit is worth more than all others together, so first flip every row whose first bit is 0; then flip every column that has more 0s than 1s.

Input

The first line contains R and C. Each of the next R lines contains C values, each 0 or 1.

Output

Print the maximum score.

Constraints

1 <= R, C <= 20

Example input

3 4
0 0 1 1
1 0 1 0
1 1 0 0

Example output

39

Explanation

For 0011 / 1010 / 1100, flipping the first row and then columns 2 and 3 gives 1111 / 1001 / 1111, which reads 15 + 9 + 15 = 39.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Remove Colored Pieces if Both Neighbors are the Same Color Next: Maximum Length of Subarray With Positive Product