Problem 8.2. Misha suggested that Yulia move a chip from cell $A$ to cell $B$. In one step, you can move the chip to an adjacent cell by side or by corner. To make it more interesting, Misha put 30 candies in the prize fund, but said that he would take 2 candies for each horizontal or vertical move and 3 candies for each diagonal move. The remaining candies Yulia gets as a reward. What is the maximum number of candies Yulia can win?

![](https://cdn.mathpix.com/cropped/2024_05_06_ed8f792abd651132e9d3g-2.jpg?height=299&width=410&top_left_y=143&top_left_x=526)
Answer: 14.

Solution. From $A$ to $B$, one can get through the top or the bottom. If going through the top, the first 2 moves are diagonal (a diagonal move is more advantageous than 2 horizontal moves), and the next 5 moves are horizontal. Misha will take $2 \cdot 3 + 5 \cdot 2 = 16$ candies, and Yulia will win 14. If going through the bottom, the first 5 moves are diagonal, and the last move is vertical. In this case, Misha will take $5 \cdot 3 + 1 \cdot 2 = 17$ candies, and Yulia will win 13 candies. We get that the first option is more advantageous, and the win will be 14 candies.