5. Each cell of a $100 \times 100$ board is painted blue or white. We call a cell balanced if among its neighbors there are an equal number of blue and white cells. For which $n$ can the board be painted so that there are exactly $n$ balanced cells? (Cells are considered neighbors if they share a side.)
Solution. Note that the minimum number of equilibrium cells is 0 (for example, if all cells are white).

Let's find the maximum number of equilibrium cells. Cells lying on the edge of the board but not in a corner cannot be equilibrium, as they have an odd number of neighbors (three). There are $4 \cdot 98 = 392$ such cells. All other cells can be made equilibrium, for example, with a striped coloring (see figure a). The number of these cells is $10000 - 392 = 9608$.
![](https://cdn.mathpix.com/cropped/2024_05_06_decbdd56c766804727cag-1.jpg?height=432&width=1174&top_left_y=1974&top_left_x=434)

We will call a number $r$ achievable if there exists a coloring with $r$ equilibrium cells. We know that the numbers 0 and 9608 are achievable. We will prove that all numbers from 0 to 9608 are also achievable.

For this, we will take a white board and gradually color it in a striped pattern. Since coloring one cell affects only the equilibrium of its neighbors, the number of equilibrium cells changes by no more than 4 with each newly colored cell. At the beginning of the process, this number is 0, and at the end, it is 9608. Therefore, the difference between two consecutive achievable numbers in the range from 0 to 9608 does not exceed 4.

It remains to learn how to change the number of equilibrium cells by 1, 2, or 3. For this, we will prove two auxiliary statements.

1) If the number $r \leqslant 5000$ is achievable, then the numbers $r+1, r+2, r+3$ are achievable. Indeed, in this case, there is a lot of free (white) space on the board. You can place two blue cells far from the other blue cells, with exactly one white cell between them (see figure b) - this will increase the number of equilibrium cells by 1; this can be done even three times.
2) If the number $r \geqslant 5000$ is achievable, then the numbers $r-1, r-2, r-3$ are achievable. Indeed, in this case, there are many blue stripes on the board. You can repaint the leftmost cell of any of these stripes to white (see figure c), and the adjacent cell will no longer be equilibrium. This can be done even three times.

From statement 1, it follows that all numbers from 0 to 5000 are achievable; from statement 2, it follows that all numbers from 5000 to 9608 are achievable.

Answer: from 0 to 9608 inclusive.