4. At the vertices of a cube, the numbers $1^{2}, 2^{2}, \ldots, 8^{2}$ (one number per vertex) are placed. For each edge, the product of the numbers at its ends is calculated. Find the maximum possible sum of all these products.
Answer: 9420. Solution. Let's color the vertices of the cube in two colors so that the ends of each edge are of different colors. Let the numbers $a_{1}, a_{2}, a_{3}, a_{4}$ be placed in the vertices of one color, and the numbers $b_{1}, b_{2}, b_{3}, b_{4}$ in the vertices of the other color, with numbers having the same indices placed in opposite vertices. Then, as it is easy to verify, the specified sum of products will be equal to $\left(a_{1}+a_{2}+a_{3}+a_{4}\right)\left(b_{1}+b_{2}+b_{3}+b_{4}\right)-$ $\left(a_{1} b_{1}+a_{2} b_{2}+a_{3} b_{3}+a_{4} b_{4}\right)$. By the inequality of means,

$$
\left(a_{1}+a_{2}+a_{3}+a_{4}\right)\left(b_{1}+b_{2}+b_{3}+b_{4}\right) \leq\left(a_{1}+a_{2}+a_{3}+a_{4}+b_{1}+b_{2}+b_{3}+b_{4}\right)^{2} / 4=\left(1^{2}+2^{2}+\ldots+8^{2}\right)^{2} / 4=10404
$$

with equality achieved only when $a_{1}+a_{2}+a_{3}+a_{4}=b_{1}+b_{2}+b_{3}+b_{4}$ (1). On the other hand, the sum $a_{1} b_{1}+a_{2} b_{2}+a_{3} b_{3}+a_{4} b_{4}$, where $a_{i}$ and $b_{i}$ are the numbers $1^{2}, 2^{2}, \ldots, 8^{2}$, is minimal when $8^{2}$ is multiplied by $1^{2}$, $7^{2}$ by $2^{2}$, $6^{2}$ by $3^{2}$, and $5^{2}$ by $4^{2}$ (2). Indeed, if $8^{2}$ is multiplied by $a^{2} \neq 1^{2}$, and $1^{2}$ by $b^{2}$, it is clear that multiplying $8^{2}$ by $1^{2}$ and $a^{2}$ by $b^{2}$ will decrease the sum $a_{1} b_{1}+a_{2} b_{2}+a_{3} b_{3}+a_{4} b_{4}$. Then, similarly, we show that we will decrease the sum by multiplying $7^{2}$ by $2^{2}$, and so on.

Surprisingly, it is possible to achieve the simultaneous satisfaction of the condition of maximality (1) and the condition of minimality (2): for this, we need to place the numbers $1^{2}, 4^{2}, 6^{2}$, and $7^{2}$ in the vertices of one color, and the others in the vertices of the other color such that $8^{2}$ and $1^{2}$, $7^{2}$ and $2^{2}$, $6^{2}$ and $3^{2}$, $5^{2}$ and $4^{2}$ are in opposite vertices. It is clear that such an arrangement will give the desired maximum sum of products, equal to $\left(1^{2}+4^{2}+6^{2}+7^{2}\right)^{2}-\left(8^{2} \cdot 1^{2}+7^{2} \cdot 2^{2}+6^{2} \cdot 3^{2}+5^{2} \cdot 4^{2}\right)=102^{2}-984=9420$. Remark. The fact that the numbers $1^{2}, 2^{2}, \ldots, 8^{2}$ can be divided into two groups of 4 numbers with equal sums of numbers is not accidental. Note that $(n+1)^{2}-n^{2}=2 n+1$, so $\left((n+3)^{2}-(n+2)^{2}\right)-\left((n+1)^{2}-n^{2}\right)=(2 n+5)-(2 n+1)=4$ for any $n$. Therefore, $\left(1^{2}-2^{2}-3^{2}+4^{2}\right)-\left(5^{2}-6^{2}-7^{2}+8^{2}\right)=1^{2}-2^{2}-3^{2}+4^{2}-5^{2}+6^{2}+7^{2}-8^{2}=4-4=0$.