[Combinatorics]
Problem: In a $999 \times 999$ square table some cells are white and the remaining ones are red. Let $T$ be the number of triples $\left(C_{1}, C_{2}, C_{3}\right)$ of cells, the first two in the same row and the last two in the same column, with $C_{1}$ and $C_{3}$ white and $C_{2}$ red. Find the maximum value $T$ can attain.

Solution: We prove that in an $n \times n$ square table there are at most $\frac{4 n^{4}}{27}$ such triples.

Let row $i$ and column $j$ contain $a_{i}$ and $b_{j}$ white cells respectively, and let $R$ be the set of red cells. For every red cell $(i, j)$ there are $a_{i} b_{j}$ admissible triples $\left(C_{1}, C_{2}, C_{3}\right)$ with $C_{2}=(i, j)$, therefore

$$
T=\sum_{(i, j) \in R} a_{i} b_{j}
$$

We use the inequality $2 a b \leq a^{2}+b^{2}$ to obtain

$$
T \leq \frac{1}{2} \sum_{(i, j) \in R}\left(a_{i}^{2}+b_{j}^{2}\right)=\frac{1}{2} \sum_{i=1}^{n}\left(n-a_{i}\right) a_{i}^{2}+\frac{1}{2} \sum_{j=1}^{n}\left(n-b_{j}\right) b_{j}^{2}
$$

This is because there are $n-a_{i}$ red cells in row $i$ and $n-b_{j}$ red cells in column $j$. Now we maximize the right-hand side.

By the AM-GM inequality we have

$$
(n-x) x^{2}=\frac{1}{2}(2 n-2 x) \cdot x \cdot x \leq \frac{1}{2}\left(\frac{2 n}{3}\right)^{3}=\frac{4 n^{3}}{27}
$$

with equality if and only if $x=\frac{2 n}{3}$. By putting everything together, we get

$$
T \leq \frac{n}{2} \frac{4 n^{3}}{27}+\frac{n}{2} \frac{4 n^{3}}{27}=\frac{4 n^{4}}{27}
$$

If $n=999$ then any coloring of the square table with $x=\frac{2 n}{3}=666$ white cells in each row and column attains the maximum as all inequalities in the previous argument become equalities. For example color a cell $(i, j)$ white if $i-j \equiv 1,2, \ldots, 666(\bmod 999)$, and red otherwise.

Therefore the maximum value $T$ can attain is $T=\frac{4 \cdot 999^{4}}{27}$.

Final answer: $\frac{4 \cdot 999^{4}}{27}$