Let me tell you the things that I have been thinking for a long time.
You are given an matrix
with each number in
either
or
.
You can do the following operation on any number of times (possibly zero):
Choose a row or a column from , and flip it (i.e. all the
s in that row or column become
s, and all the
s become
s).
Define as
, which means writing all the number in the
-th row from left to right, forming a binary number
.
Define as
, which means writing all the number in the
-th column from top to bottom, forming a binary number
.
Note that and
may change after operations.
Determine whether you can achieve by operations. If so, find out the minimal number of operations needed.
The first line contains a positive integer
(
), denoting the size of matrix
.
Each of the following
lines contains a string consisting of
0and1s, denoting each row of matrix
.
If it is possible to achieve
, print the minimal number of operations in a single line. Otherwise, print
.