Problem 8.1. In a $5 \times 5$ square, some cells have been painted black as shown in the figure. Consider all possible squares whose sides lie along the grid lines. In how many of them is the number of black and white cells the same?

![](https://cdn.mathpix.com/cropped/2024_05_06_899cf5197845501d962eg-24.jpg?height=311&width=321&top_left_y=91&top_left_x=566)
Answer: 16.

Solution. An equal number of black and white cells can only be in squares $2 \times 2$ or $4 \times 4$ (in all other squares, there is an odd number of cells in total, so there cannot be an equal number of black and white cells). There are only two non-fitting $2 \times 2$ squares (both of which contain the center of the table, but do not contain any cells above the center), so there are exactly $16-2=14$ fitting $2 \times 2$ squares. And among the $4 \times 4$ squares, only the two lower ones fit.

Thus, the total number of squares with an equal number of black and white cells is exactly $14+2=16$.