TITLE: Is is possible to obtain exactly 16 black cells?
QUESTION [22 upvotes]: We are given an $18*18$ table, all of whose cells may be black or white. Initially all the cells are colored white. We may perform the following operation:
Choose one column or one row and change the colour of all cells in this column or row. Is it possible by repeating the operation to obtain a table with exactly $16$ black cells?
I know that this question is based on invariant principle but I am not getting the invariant.

REPLY [13 votes]: Well, mrprottolo gave a similar answer, but not identical, and I already typed this out, so I'll hit "Post" anyway!

First of all, note that these operations commute with each other! Second, by shuffling the rows and columns as necessary, we can assume that only the first $m$ rows and the first $n$ columns are flipped.
So how many black cells are there? Measure the two rectangles:
$$n(18-m)+m(18-n)=18m+18n-2mn$$
Setting that equal to $16$, we get:
$$9m+9n-mn=8$$
Conclude that both $m$ and $n$ are even, and neither is a multiple of $3$. So $m\geq 2$, and by symmetry, we can assume $m\leq 9$, which forces $m\leq 8$. But
$$n=\frac{9m-8}{m-9}$$
is negative on that range, a contradiction.