$\underline{\text { templesovv }}$ D:

Two pirates are dividing a treasure consisting of two bags of coins and a diamond, acting according to the following rules. First, the first pirate takes some coins from any bag and moves the same number of coins from this bag to the other. Then the second pirate does the same (choosing the bag from which he takes the coins at his discretion) and so on until it is possible to take coins according to these rules. The pirate who takes the coins last gets the diamond. Who will get the diamond, if each pirate is trying to get it? Give the answer depending on the initial number of coins in the bags.
Consider the case when the number of coins in the bags differs by no more than 1.

Let the second pirate take as many coins as the first on each turn, but from a different bag. It is not hard to see that in this case, the second pirate can always make a counter move.

Each time after the second pirate's move, the difference in the number of coins in the bags will be the same as at the beginning, so after some move, there will be no coins in one bag, and no more than one in the other, meaning the first pirate will not be able to make a move and will lose.

In the other case - if the difference is greater than 1 - the first pirate, by his move, takes $m$ coins from the larger bag, if the difference is of the form $3m$ or $3m \pm 1$, thereby reducing the number of coins in the bags to the first case and then uses the strategy described above.

## Answer

If the number of coins in the bags differs by no more than 1, the diamond will go to the second pirate, otherwise to the first.