Problem 4. Carlson has three boxes, each containing 10 candies. One box is labeled with the number 4, another with 7, and the third with 10. In one operation, Carlson sequentially performs the following two actions:

- he takes from any box a number of candies equal to the number written on it;
- he eats 3 of the taken candies, and puts the rest in any other box.

What is the maximum number of candies Carlson can eat as a result of several such operations?
Answer: 27.

Solution. Since at each step, Karlson eats 3 candies, the total number of candies eaten is divisible by 3. We will prove that it does not exceed 27; for this, it is sufficient to show that it cannot equal 30, that is, Karlson cannot eat all the candies. Indeed, if this were possible, then before the last operation, there would be exactly 3 candies left, meaning that each box would contain no more than 3 candies. However, each of the numbers $4, 7, 10$ is greater than 3, so the last operation would be impossible, leading to a contradiction.

The example below shows how Karlson could act to eat exactly 27 candies. In the $k$-th line, it is written how many candies remain in each box after the $(k-1)$-th operation. The three numbers in each line are the number of candies remaining in the boxes at the corresponding step. The notation $(a, b, c)$ means that in the box with number 4, there were $a$ candies left, in the box with number $7-b$ candies, and in the box with number $10-c$ candies.