#C1377. Uniform Grid Conversion

    ID: 43344 Type: Default 1000ms 256MiB

Uniform Grid Conversion

Uniform Grid Conversion

Given an n \(\times\) m grid containing binary values (0 and 1), determine the minimum number of operations required to make all cells in the grid identical. In one operation, you can change a cell from 0 to 1 or from 1 to 0.

The optimal strategy is to convert all cells to either 0 or 1. If the grid contains \(z\) zeros and \(o\) ones, then the answer is \(\min(z, o)\). This is because converting the grid to the majority value requires fewer operations.

Input/Output Format: The input is given via standard input, and the output should be written to standard output.

inputFormat

The first line contains two integers (n) and (m), representing the number of rows and columns respectively. Each of the following (n) lines contains (m) space-separated integers (each 0 or 1) representing the grid.

outputFormat

Output a single integer representing the minimum number of operations required to make all cells in the grid identical.## sample

2 2
0 1
1 0
2