You are given a matrix A with N rows and M columns. Both N and M are even, and every element of the matrix is 0 or 1.
Rows are numbered 1 to N from the top, and columns are numbered 1 to M from the left.
A palindrome is a string that reads the same forward and backward. For example, "1001" and "0111001110" are palindromes, while "1101" and "000001" are not.
Each row and each column is read as a string of 0s and 1s, so it is either a palindrome or not. In the matrix below, row 1 is "0000" and column 4 is "0110", and both are palindromes.
0000
0011
0111
1110
You are given the matrix A and two integers R and C. Changing one element means flipping a 0 to a 1, or a 1 to a 0. Write a program that finds the minimum number of elements you have to change so that at least R rows are palindromes and at least C columns are palindromes.