Subfield: Combinatorics


Question: Players $A$ and $B$ play a game on a blackboard that initially contains 2020 copies of the number 1. In every round, player $A$ erases two numbers $x$ and $y$ from the blackboard, and then player $B$ writes one of the numbers $x+y$ and $|x-y|$ on the blackboard. The game terminates as soon as, at the end of some round, one of the following holds:

(1) one of the numbers on the blackboard is larger than the sum of all other numbers;

(2) there are only zeros on the blackboard.

Player $B$ must then give as many cookies to player $A$ as there are numbers on the blackboard. Player $A$ wants to get as many cookies as possible, whereas player $B$ wants to give as few as possible. Determine the number of cookies that $A$ receives if both players play optimally.

Solution:
For a positive integer $n$, we denote by $S_{2}(n)$ the sum of digits in its binary representation. We prove that, in fact, if a board initially contains an even number $n>1$ of ones, then $A$ can guarantee to obtain $S_{2}(n)$, but not more, cookies. The binary representation of 2020 is $2020=\overline{11111100100}_{2}$, so $S_{2}(2020)=7$, and the answer follows.

A strategy for A. At any round, while possible, A chooses two equal nonzero numbers on the board. Clearly, while $A$ can make such choice, the game does not terminate. On the other hand, $A$ can follow this strategy unless the game has already terminated. Indeed, if $A$ always chooses two equal numbers, then each number appearing on the board is either 0 or a power of 2 with non-negative integer exponent, this can be easily proved using induction on the number of rounds. At the moment when $A$ is unable to follow the strategy all nonzero numbers on the board are distinct powers of 2 . If the board contains at least one such power, then the largest of those powers is greater than the sum of the others. Otherwise there are only zeros on the blackboard, in both cases the game terminates.

For every number on the board, define its range to be the number of ones it is obtained from. We can prove by induction on the number of rounds that for any nonzero number $k$ written by $B$ its range is $k$, and for any zero written by $B$ its range is a power of 2 . Thus at the end of each round all the ranges are powers of two, and their sum is $n$. Since $S_{2}(a+b) \leqslant S_{2}(a)+S_{2}(b)$ for any positive integers $a$ and $b$, the number $n$ cannot be represented as a sum of less than $S_{2}(n)$ powers of 2 . Thus at the end of each round the board contains at least $S_{2}(n)$ numbers, while $A$ follows the above strategy. So $A$ can guarantee at least $S_{2}(n)$ cookies for himself.

A strategy for $B$. Denote $s=S_{2}(n)$.

Let $x_{1}, \ldots, x_{k}$ be the numbers on the board at some moment of the game after $B$ 's turn or at the beginning of the game. Say that a collection of $k \operatorname{signs} \varepsilon_{1}, \ldots, \varepsilon_{k} \in\{+1,-1\}$ is balanced if

$$
\sum_{i=1}^{k} \varepsilon_{i} x_{i}=0
$$

We say that a situation on the board is good if $2^{s+1}$ does not divide the number of balanced collections. An appropriate strategy for $B$ can be explained as follows: Perform a move so that the situation remains good, while it is possible. We intend to show that in this case $B$ will not lose more than $S_{2}(n)$ cookies. For this purpose, we prove several lemmas.

For a positive integer $k$, denote by $\nu_{2}(k)$ the exponent of the largest power of 2 that divides $k$. Recall that, by Legendre's formula, $\nu_{2}(n !)=n-S_{2}(n)$ for every positive integer $n$.



Lemma 1. The initial situation is good.

Proof. In the initial configuration, the number of balanced collections is equal to $\left(\begin{array}{c}n \\ n / 2\end{array}\right)$. We have

$$
\nu_{2}\left(\left(\begin{array}{c}
n \\
n / 2
\end{array}\right)\right)=\nu_{2}(n !)-2 \nu_{2}((n / 2) !)=\left(n-S_{2}(n)\right)-2\left(\frac{n}{2}-S_{2}(n / 2)\right)=S_{2}(n)=s
$$

Hence $2^{s+1}$ does not divide the number of balanced collections, as desired.

Lemma 2. B may play so that after each round the situation remains good.

Proof. Assume that the situation $\left(x_{1}, \ldots, x_{k}\right)$ before a round is good, and that $A$ erases two numbers, $x_{p}$ and $x_{q}$.

Let $N$ be the number of all balanced collections, $N_{+}$be the number of those having $\varepsilon_{p}=\varepsilon_{q}$, and $N_{-}$be the number of other balanced collections. Then $N=N_{+}+N_{-}$. Now, if $B$ replaces $x_{p}$ and $x_{q}$ by $x_{p}+x_{q}$, then the number of balanced collections will become $N_{+}$. If $B$ replaces $x_{p}$ and $x_{q}$ by $\left|x_{p}-x_{q}\right|$, then this number will become $N_{-}$. Since $2^{s+1}$ does not divide $N$, it does not divide one of the summands $N_{+}$and $N_{-}$, hence $B$ can reach a good situation after the round.

Lemma 3. Assume that the game terminates at a good situation. Then the board contains at most $s$ numbers.

Proof. Suppose, one of the numbers is greater than the sum of the other numbers. Then the number of balanced collections is 0 and hence divisible by $2^{s+1}$. Therefore, the situation is not good.

Then we have only zeros on the blackboard at the moment when the game terminates. If there are $k$ of them, then the number of balanced collections is $2^{k}$. Since the situation is good, we have $k \leqslant s$.

By Lemmas 1 and 2, $B$ may act in such way that they keep the situation good. By Lemma 3, when the game terminates, the board contains at most $s$ numbers. This is what we aimed to prove.

Final answer: 7