4. (7 points) On the board, 40 ones are written. Every minute, Karlson erases two arbitrary numbers and writes their sum on the board, and then eats a number of candies equal to the product of the two erased numbers. What is the maximum number of candies he could have eaten in 40 minutes?
Answer: 780.

Solution: Let's represent 40 units as points on a plane. Each time we combine two numbers, we will connect the points corresponding to one group with all the points of the second group with line segments. Note that if we replace numbers $x$ and $y$ with $x+y$, the groups " $x$ " and " $y$ " will be connected by $x y$ line segments. Carlson will eat as many candies as there are line segments. After 40 minutes, all points will be connected. In total, $\frac{40 \cdot(40-1)}{2}=780$ line segments will be drawn. Therefore, Carlson will eat 780 candies.