class
GFG
{
static
int
minFlipsSub(String mat[],
int
i,
int
j)
{
int
cnt0 =
0
, cnt1 =
0
;
if
(mat[i].charAt(j) ==
'1'
)
cnt1++;
else
cnt0++;
if
(mat[i].charAt(j+
1
) ==
'1'
)
cnt1++;
else
cnt0++;
if
(mat[i +
1
].charAt(j) ==
'1'
)
cnt1++;
else
cnt0++;
if
(mat[i +
1
].charAt(j+
1
) ==
'1'
)
cnt1++;
else
cnt0++;
return
Math.min(cnt0, cnt1);
}
static
int
minFlips(String mat[],
int
r,
int
c)
{
int
res = Integer.MAX_VALUE;
for
(
int
i =
0
; i < r -
1
; i++)
{
for
(
int
j =
0
; j < c -
1
; j++)
{
res = Math.min(res, minFlipsSub(mat, i, j));
}
}
return
res;
}
public
static
void
main(String[] args)
{
String mat[] = {
"0101"
,
"0101"
,
"0101"
};
int
r = mat.length;
int
c = mat[
0
].length();
System.out.print(minFlips(mat, r, c));
}
}