Shapovalov A.V.

Having defeated Koschei, Ivan demanded gold to ransom Vasilisa from the bandits. Koschei led him to a cave and said: "In the chest lie gold ingots. But you cannot simply take them: they are enchanted. Put one or several into your bag. Then I will put one or several from the bag back into the chest, but it must be a different number. We will take turns moving them: you into the bag, I into the chest, each time a different number. When a new move becomes impossible, you will be able to take your bag with the ingots." What is the maximum number of ingots Ivan can take, no matter how Koschei acts, if initially there are a) 13; b) 14 gold ingots in the chest? How can he do it?
Ivan will act in such a way that each time Kashchey's move will be the only one: all other numbers either have already appeared in previous moves or are too large - Ivan does not have such a number of ingots at that moment. We will record the moves of the game as follows:

number of ingots moved (number of ingots Ivan has after the move).
a) 2 (2), 1 (1), 3 (4), 4 (0), 6 (6), 5 (1), 7 (8), 8 (0), 10 (10), 9 (1), 11 (12), 12 (0), 13 (13).

All possible moves have been made, Ivan has all 13 ingots, so he can take them.

b) We will act in the same way as in the previous part. After the move "13 (13)" only the move 14 is not made, but it is impossible, so Ivan can take 13 ingots.

Let's prove that Ivan cannot take 14 ingots. Suppose at some point there were 14 ingots in the bag. This means there are no ingots in the chest, so the last move was made by Ivan. But then an odd number of moves have been made in total, and therefore some number from 1 to 14 has not appeared. Kashchey can make a move with this number, so it is not yet possible to take the ingots.

## Answer

a) 13 ; b) 13 ingots.