This is a combinatorics-probability question, best stated however in "recreational" terms. Imagine a $N\times N$ city, meaning that we have $N$ horizontal streets, and $N$ vertical streets. At each crossroads there is a street light.

When evening comes, some of the lights are switched on, namely those corresponding to a certain given subset $E\subset(1,\ldots,N)\times(1,\ldots,N)$.

Now assume that $2N$ kids come at night and start randomly playing with the switches: there is one such on/off switch at the end of each of the $2N$ streets.

Problem: for each of the $4^N$ overall choices for the various switches, we count the number $K$ of street lights that are switched on. What is the law of this random variable $K$, as a probability measure on $(1,2,\ldots,N^2)$, depending on the initial set $E$?

[**Edit, Jan 20.** As signaled by Joseph O'Rourke in his answer below, computing the upper edge of the support of the measure $\mu_E$ in my problem is known as the *Gale-Berlekamp game*, a difficult question (details can be found via Google search). So I realise that my problem is probably extremely difficult, adding the "open-problem" tag. I'd be interested however in the case where $E$ is an Hadamard matrix, cf. discussion with Gerhard Paseman in the comments below. Is there anything known about this measure $\mu_E$? (I mean, not only about its support.)

Btw here is the only non-trivial complete computation that I have so far: concerns the case $N=4$, where there are exactly $|E|=4$ street lights, positioned on the main diagonal of the city. Here $\mu_E=\frac{1}{32}(\delta_4+12\delta_6+6\delta_8+12\delta_{10}+\delta_{12})$. Plus an experimental remark, that I'm not able to prove abstractly: the support of $\mu_E$ seems always to be an arithmetic progression.]

2more comments