Let $\mathbb{Z}$ be the set of integers. Determine all functions $f: \mathbb{Z} \rightarrow \mathbb{Z}$ such that, for all integers $a$ and $b$,  $$ f(2 a)+2 f(b)=f(f(a+b)) $$  (South Africa)

Solution: Substituting $a=0, b=n+1$ gives $f(f(n+1))=f(0)+2 f(n+1)$. Substituting $a=1, b=n$ gives $f(f(n+1))=f(2)+2 f(n)$.  In particular, $f(0)+2 f(n+1)=f(2)+2 f(n)$, and so $f(n+1)-f(n)=\frac{1}{2}(f(2)-f(0))$. Thus $f(n+1)-f(n)$ must be constant. Since $f$ is defined only on $\mathbb{Z}$, this tells us that $f$ must be a linear function; write $f(n)=M n+K$ for arbitrary constants $M$ and $K$, and we need only determine which choices of $M$ and $K$ work.  Now, (1) becomes  $$ 2 M a+K+2(M b+K)=M(M(a+b)+K)+K $$  which we may rearrange to form  $$ (M-2)(M(a+b)+K)=0 $$  Thus, either $M=2$, or $M(a+b)+K=0$ for all values of $a+b$. In particular, the only possible solutions are $f(n)=0$ and $f(n)=2 n+K$ for any constant $K \in \mathbb{Z}$, and these are easily seen to work.


Solution: Let $K=f(0)$. First, put $a=0$ in (1); this gives  $$ f(f(b))=2 f(b)+K $$  for all $b \in \mathbb{Z}$. Now put $b=0$ in (1); this gives  $$ f(2 a)+2 K=f(f(a))=2 f(a)+K $$  where the second equality follows from (2). Consequently,  $$ f(2 a)=2 f(a)-K $$  for all $a \in \mathbb{Z}$. Substituting (2) and (3) into (1), we obtain  $$ \begin{aligned} f(2 a)+2 f(b) & =f(f(a+b)) \\ 2 f(a)-K+2 f(b) & =2 f(a+b)+K \\ f(a)+f(b) & =f(a+b)+K \end{aligned} $$  Thus, if we set $g(n)=f(n)-K$ we see that $g$ satisfies the Cauchy equation $g(a+b)=$ $g(a)+g(b)$. The solution to the Cauchy equation over $\mathbb{Z}$ is well-known; indeed, it may be proven by an easy induction that $g(n)=M n$ for each $n \in \mathbb{Z}$, where $M=g(1)$ is a constant.  Therefore, $f(n)=M n+K$, and we may proceed as in Solution 1 . Comment 1. Instead of deriving (3) by substituting $b=0$ into (1), we could instead have observed that the right hand side of (1) is symmetric in $a$ and $b$, and thus  $$ f(2 a)+2 f(b)=f(2 b)+2 f(a) $$  Thus, $f(2 a)-2 f(a)=f(2 b)-2 f(b)$ for any $a, b \in \mathbb{Z}$, and in particular $f(2 a)-2 f(a)$ is constant. Setting $a=0$ shows that this constant is equal to $-K$, and so we obtain (3).  Comment 2. Some solutions initially prove that $f(f(n))$ is linear (sometimes via proving that $f(f(n))-3 K$ satisfies the Cauchy equation). However, one can immediately prove that $f$ is linear by substituting something of the form $f(f(n))=M^{\prime} n+K^{\prime}$ into (2).


Solution: Notice first that $b>0$ and $a<0$. Indeed, since $\sum_{i=1}^{2019} u_{i}^{2}=1$, the variables $u_{i}$ cannot be all zero, and, since $\sum_{i=1}^{2019} u_{i}=0$, the nonzero elements cannot be all positive or all negative.  Let $P=\left\{i: u_{i}>0\right\}$ and $N=\left\{i: u_{i} \leqslant 0\right\}$ be the indices of positive and nonpositive elements in the sequence, and let $p=|P|$ and $n=|N|$ be the sizes of these sets; then $p+n=2019$. By the condition $\sum_{i=1}^{2019} u_{i}=0$ we have $0=\sum_{i=1}^{2019} u_{i}=\sum_{i \in P} u_{i}-\sum_{i \in N}\left|u_{i}\right|$, so  $$ \sum_{i \in P} u_{i}=\sum_{i \in N}\left|u_{i}\right| . $$  After this preparation, estimate the sum of squares of the positive and nonpositive elements as follows:  $$ \begin{aligned} & \sum_{i \in P} u_{i}^{2} \leqslant \sum_{i \in P} b u_{i}=b \sum_{i \in P} u_{i}=b \sum_{i \in N}\left|u_{i}\right| \leqslant b \sum_{i \in N}|a|=-n a b ; \\ & \sum_{i \in N} u_{i}^{2} \leqslant \sum_{i \in N}|a| \cdot\left|u_{i}\right|=|a| \sum_{i \in N}\left|u_{i}\right|=|a| \sum_{i \in P} u_{i} \leqslant|a| \sum_{i \in P} b=-p a b . \end{aligned} $$  The sum of these estimates is  $$ 1=\sum_{i=1}^{2019} u_{i}^{2}=\sum_{i \in P} u_{i}^{2}+\sum_{i \in N} u_{i}^{2} \leqslant-(p+n) a b=-2019 a b ; $$  that proves $a b \leqslant \frac{-1}{2019}$. Comment 1. After observing $\sum_{i \in P} u_{i}^{2} \leqslant b \sum_{i \in P} u_{i}$ and $\sum_{i \in N} u_{i}^{2} \leqslant|a| \sum_{i \in P}\left|u_{i}\right|$, instead of $(2,3)$ an alternative continuation is  $$ |a b| \geqslant \frac{\sum_{i \in P} u_{i}^{2}}{\sum_{i \in P} u_{i}} \cdot \frac{\sum_{i \in N} u_{i}^{2}}{\sum_{i \in N}\left|u_{i}\right|}=\frac{\sum_{i \in P} u_{i}^{2}}{\left(\sum_{i \in P} u_{i}\right)^{2}} \sum_{i \in N} u_{i}^{2} \geqslant \frac{1}{p} \sum_{i \in N} u_{i}^{2} $$  (by the AM-QM or the Cauchy-Schwarz inequality) and similarly $|a b| \geqslant \frac{1}{n} \sum_{i \in P} u_{i}^{2}$.


Solution: As in the previous solution we conclude that $a<0$ and $b>0$. For every index $i$, the number $u_{i}$ is a convex combination of $a$ and $b$, so  $$ u_{i}=x_{i} a+y_{i} b \quad \text { with some weights } 0 \leqslant x_{i}, y_{i} \leqslant 1, \text { with } x_{i}+y_{i}=1 \text {. } $$  Let $X=\sum_{i=1}^{2019} x_{i}$ and $Y=\sum_{i=1}^{2019} y_{i}$. From $0=\sum_{i=1}^{2019} u_{i}=\sum_{i=1}^{2019}\left(x_{i} a+y_{i} b\right)=-|a| X+b Y$, we get  $$ |a| X=b Y $$  From $\sum_{i=1}^{2019}\left(x_{i}+y_{i}\right)=2019$ we have  $$ X+Y=2019 $$  The system of linear equations $(4,5)$ has a unique solution:  $$ X=\frac{2019 b}{|a|+b}, \quad Y=\frac{2019|a|}{|a|+b} $$  Now apply the following estimate to every $u_{i}^{2}$ in their sum:  $$ u_{i}^{2}=x_{i}^{2} a^{2}+2 x_{i} y_{i} a b+y_{i}^{2} b^{2} \leqslant x_{i} a^{2}+y_{i} b^{2} $$  we obtain that  $$ 1=\sum_{i=1}^{2019} u_{i}^{2} \leqslant \sum_{i=1}^{2019}\left(x_{i} a^{2}+y_{i} b^{2}\right)=X a^{2}+Y b^{2}=\frac{2019 b}{|a|+b}|a|^{2}+\frac{2019|a|}{|a|+b} b^{2}=2019|a| b=-2019 a b . $$  Hence, $a b \leqslant \frac{-1}{2019}$. Comment 2. The idea behind Solution 2 is the following thought. Suppose we fix $a<0$ and $b>0$, fix $\sum u_{i}=0$ and vary the $u_{i}$ to achieve the maximum value of $\sum u_{i}^{2}$. Considering varying any two of the $u_{i}$ while preserving their sum: the maximum value of $\sum u_{i}^{2}$ is achieved when those two are as far apart as possible, so all but at most one of the $u_{i}$ are equal to $a$ or $b$. Considering a weighted version of the problem, we see the maximum (with fractional numbers of $u_{i}$ having each value) is achieved when $\frac{2019 b}{|a|+b}$ of them are $a$ and $\frac{2019|a|}{|a|+b}$ are $b$.  In fact, this happens in the solution: the number $u_{i}$ is replaced by $x_{i}$ copies of $a$ and $y_{i}$ copies of $b$.


Let $n \geqslant 3$ be a positive integer and let $\left(a_{1}, a_{2}, \ldots, a_{n}\right)$ be a strictly increasing sequence of $n$ positive real numbers with sum equal to 2 . Let $X$ be a subset of $\{1,2, \ldots, n\}$ such that the value of  $$ \left|1-\sum_{i \in X} a_{i}\right| $$  is minimised. Prove that there exists a strictly increasing sequence of $n$ positive real numbers $\left(b_{1}, b_{2}, \ldots, b_{n}\right)$ with sum equal to 2 such that  $$ \sum_{i \in X} b_{i}=1 $$  (New Zealand)

Solution: Without loss of generality, assume $\sum_{i \in X} a_{i} \leqslant 1$, and we may assume strict inequality as otherwise $b_{i}=a_{i}$ works. Also, $X$ clearly cannot be empty.  If $n \in X$, add $\Delta$ to $a_{n}$, producing a sequence of $c_{i}$ with $\sum_{i \in X} c_{i}=\sum_{i \in X^{c}} c_{i}$, and then scale as described above to make the sum equal to 2 . Otherwise, there is some $k$ with $k \in X$ and $k+1 \in X^{c}$. Let $\delta=a_{k+1}-a_{k}$.  - If $\delta>\Delta$, add $\Delta$ to $a_{k}$ and then scale. - If $\delta<\Delta$, then considering $X \cup\{k+1\} \backslash\{k\}$ contradicts $X$ being $\left(a_{i}\right)$-minimising. - If $\delta=\Delta$, choose any $j \neq k, k+1$ (possible since $n \geqslant 3$ ), and any $\epsilon$ less than the least of $a_{1}$ and all the differences $a_{i+1}-a_{i}$. If $j \in X$ then add $\Delta-\epsilon$ to $a_{k}$ and $\epsilon$ to $a_{j}$, then scale; otherwise, add $\Delta$ to $a_{k}$ and $\epsilon / 2$ to $a_{k+1}$, and subtract $\epsilon / 2$ from $a_{j}$, then scale.


Solution: This is similar to   Suppose there exists $1 \leqslant j \leqslant n-1$ such that $j \in X$ but $j+1 \in X^{c}$. Then $a_{j+1}-a_{j} \geqslant \Delta$, because otherwise considering $X \cup\{j+1\} \backslash\{j\}$ contradicts $X$ being $\left(a_{i}\right)$-minimising.  If $a_{j+1}-a_{j}>\Delta$, put  $$ b_{i}= \begin{cases}a_{j}+\Delta / 2, & \text { if } i=j \\ a_{j+1}-\Delta / 2, & \text { if } i=j+1 \\ a_{i}, & \text { otherwise }\end{cases} $$  If $a_{j+1}-a_{j}=\Delta$, choose any $\epsilon$ less than the least of $\Delta / 2, a_{1}$ and all the differences $a_{i+1}-a_{i}$. If $|X| \geqslant 2$, choose $k \in X$ with $k \neq j$, and put  $$ b_{i}= \begin{cases}a_{j}+\Delta / 2-\epsilon, & \text { if } i=j \\ a_{j+1}-\Delta / 2, & \text { if } i=j+1 \\ a_{k}+\epsilon, & \text { if } i=k \\ a_{i}, & \text { otherwise }\end{cases} $$  Otherwise, $\left|X^{c}\right| \geqslant 2$, so choose $k \in X^{c}$ with $k \neq j+1$, and put  $$ b_{i}= \begin{cases}a_{j}+\Delta / 2, & \text { if } i=j \\ a_{j+1}-\Delta / 2+\epsilon, & \text { if } i=j+1 \\ a_{k}-\epsilon, & \text { if } i=k \\ a_{i}, & \text { otherwise }\end{cases} $$  If there is no $1 \leqslant j \leqslant n$ such that $j \in X$ but $j+1 \in X^{c}$, there must be some $1<k \leqslant n$ such that $X=[k, n]$ (certainly $X$ cannot be empty). We must have $a_{1}>\Delta$, as otherwise considering $X \cup\{1\}$ contradicts $X$ being $\left(a_{i}\right)$-minimising. Now put  $$ b_{i}= \begin{cases}a_{1}-\Delta / 2, & \text { if } i=1 \\ a_{n}+\Delta / 2, & \text { if } i=n \\ a_{i}, & \text { otherwise }\end{cases} $$


Solution: Without loss of generality, assume $\sum_{i \in X} a_{i} \leqslant 1$, so $\Delta \geqslant 0$. If $\Delta=0$ we can take $b_{i}=a_{i}$, so now assume that $\Delta>0$.  Suppose that there is some $k \leqslant n$ such that $|X \cap[k, n]|>\left|X^{c} \cap[k, n]\right|$. If we choose the largest such $k$ then $|X \cap[k, n]|-\left|X^{c} \cap[k, n]\right|=1$. We can now find the required sequence $\left(b_{i}\right)$ by starting with $c_{i}=a_{i}$ for $i<k$ and $c_{i}=a_{i}+\Delta$ for $i \geqslant k$, and then scaling as described above.  If no such $k$ exists, we will derive a contradiction. For each $i \in X$ we can choose $i<j_{i} \leqslant n$ in such a way that $j_{i} \in X^{c}$ and all the $j_{i}$ are different. (For instance, note that necessarily $n \in X^{c}$ and now just work downwards; each time an $i \in X$ is considered, let $j_{i}$ be the least element of $X^{c}$ greater than $i$ and not yet used.) Let $Y$ be the (possibly empty) subset of $[1, n]$ consisting of those elements in $X^{c}$ that are also not one of the $j_{i}$. In any case  $$ \Delta=\sum_{i \in X}\left(a_{j_{i}}-a_{i}\right)+\sum_{j \in Y} a_{j} $$  where each term in the sums is positive. Since $n \geqslant 3$ the total number of terms above is at least two. Take a least such term and its corresponding index $i$ and consider the set $Z$ which we form from $X$ by removing $i$ and adding $j_{i}$ (if it is a term of the first type) or just by adding $j$ if it is a term of the second type. The corresponding expression of $\Delta$ for $Z$ has the sign of its least term changed, meaning that the sum is still nonnegative but strictly less than $\Delta$, which contradicts $X$ being $\left(a_{i}\right)$-minimising.


Solution: This uses some similar ideas to   Note that, for two subsets $X, Y$ of $[1, n]$, the following are equivalent:  - $|X \cap[i, n]| \leqslant|Y \cap[i, n]|$ for all $1 \leqslant i \leqslant n$; - $Y$ is at least as large as $X$, and for all $1 \leqslant j \leqslant|Y|$, the $j^{\text {th }}$ largest element of $Y$ is at least as big as the $j^{\text {th }}$ largest element of $X$; - there is an injective function $f: X \rightarrow Y$ such that $f(i) \geqslant i$ for all $i \in X$.  If these equivalent conditions are satisfied, we write $X \leq Y$. We write $X<Y$ if $X \leq Y$ and $X \neq Y$.  Note that if $X<Y$, then $\sum_{i \in X} a_{i}<\sum_{i \in Y} a_{i}$ (the second description above makes this clear). We claim first that, if $n \geqslant 3$ and $X \prec X^{c}$, then there exists $Y$ with $X \prec Y<X^{c}$. Indeed, as $|X| \leqslant\left|X^{c}\right|$, we have $\left|X^{c}\right| \geqslant 2$. Define $Y$ to consist of the largest element of $X^{c}$, together with all but the largest element of $X$; it is clear both that $Y$ is distinct from $X$ and $X^{c}$, and that $X \leq Y \leq X^{c}$, which is what we need.  But, in this situation, we have  $$ \sum_{i \in X} a_{i}<\sum_{i \in Y} a_{i}<\sum_{i \in X^{c}} a_{i} \quad \text { and } \quad 1-\sum_{i \in X} a_{i}=-\left(1-\sum_{i \in X^{c}} a_{i}\right), $$  so $\left|1-\sum_{i \in Y} a_{i}\right|<\left|1-\sum_{i \in X} a_{i}\right|$. Hence if $X$ is $\left(a_{i}\right)$-minimising, we do not have $X \prec X^{c}$, and similarly we do not have $X^{c}<X$.  Considering the first description above, this immediately implies the following Claim. Claim. There exist $1 \leqslant k, \ell \leqslant n$ such that $|X \cap[k, n]|>\frac{n-k+1}{2}$ and $|X \cap[\ell, n]|<\frac{n-\ell+1}{2}$. We now construct our sequence $\left(b_{i}\right)$ using this claim. Let $k$ and $\ell$ be the greatest values satisfying the claim, and without loss of generality suppose $k=n$ and $\ell<n$ (otherwise replace $X$ by its complement). As $\ell$ is maximal, $n-\ell$ is even and $|X \cap[\ell, n]|=\frac{n-\ell}{2}$. For sufficiently small positive $\epsilon$, we take  $$ b_{i}=i \epsilon+ \begin{cases}0, & \text { if } i<\ell \\ \delta, & \text { if } \ell \leqslant i \leqslant n-1 \\ \gamma, & \text { if } i=n\end{cases} $$  Let $M=\sum_{i \in X} i$. So we require  $$ M \epsilon+\left(\frac{n-\ell}{2}-1\right) \delta+\gamma=1 $$  and  $$ \frac{n(n+1)}{2} \epsilon+(n-\ell) \delta+\gamma=2 $$  These give  $$ \gamma=2 \delta+\left(\frac{n(n+1)}{2}-2 M\right) \epsilon $$  and for sufficiently small positive $\epsilon$, solving for $\gamma$ and $\delta$ gives $0<\delta<\gamma$ (since $\epsilon=0$ gives $\delta=1 /\left(\frac{n-\ell}{2}+1\right)$ and $\left.\gamma=2 \delta\right)$, so the sequence is strictly increasing and has positive values.  Comment. This solution also shows that the claim gives a complete description of sets $X$ that are $\left(a_{i}\right)$-minimising for some $\left(a_{i}\right)$.  Another approach to proving the claim is as follows. We prove the existence of $\ell$ with the claimed property; the existence of $k$ follows by considering the complement of $X$.  Suppose, for a contradiction, that for all $1 \leqslant \ell \leqslant n$ we have $|X \cap[\ell, n]| \geqslant\left\lceil\frac{n-\ell+1}{2}\right\rceil$. If we ever have strict inequality, consider the set $Y=\{n, n-2, n-4, \ldots\}$. This set may be obtained from $X$ by possibly removing some elements and reducing the values of others. (To see this, consider the largest $k \in X \backslash Y$, if any; remove it, and replace it by the greatest $j \in X^{c}$ with $j<k$, if any. Such steps preserve the given inequality, and are possible until we reach the set $Y$.) So if we had strict inequality, and so $X \neq Y$, we have  $$ \sum_{i \in X} a_{i}>\sum_{i \in Y} a_{i}>1 $$  contradicting $X$ being $\left(a_{i}\right)$-minimising. Otherwise, we always have equality, meaning that $X=Y$. But now consider $Z=Y \cup\{n-1\} \backslash\{n\}$. Since $n \geqslant 3$, we have  $$ \sum_{i \in Y} a_{i}>\sum_{i \in Z} a_{i}>\sum_{i \in Y^{c}} a_{i}=2-\sum_{i \in Y} a_{i} $$  and so $Z$ contradicts $X$ being $\left(a_{i}\right)$-minimising.


Let $n \geqslant 2$ be a positive integer and $a_{1}, a_{2}, \ldots, a_{n}$ be real numbers such that  $$ a_{1}+a_{2}+\cdots+a_{n}=0 $$  Define the set $A$ by  $$ A=\left\{(i, j)\left|1 \leqslant i<j \leqslant n,\left|a_{i}-a_{j}\right| \geqslant 1\right\} .\right. $$  Prove that, if $A$ is not empty, then  $$ \sum_{(i, j) \in A} a_{i} a_{j}<0 $$  (China)

Solution: Define sets $B$ and $C$ by  $$ \begin{aligned} & B=\left\{(i, j)\left|1 \leqslant i, j \leqslant n,\left|a_{i}-a_{j}\right| \geqslant 1\right\},\right. \\ & C=\left\{(i, j)\left|1 \leqslant i, j \leqslant n,\left|a_{i}-a_{j}\right|<1\right\} .\right. \end{aligned} $$  We have  $$ \begin{aligned} \sum_{(i, j) \in A} a_{i} a_{j} & =\frac{1}{2} \sum_{(i, j) \in B} a_{i} a_{j} \\ \sum_{(i, j) \in B} a_{i} a_{j} & =\sum_{1 \leqslant i, j \leqslant n} a_{i} a_{j}-\sum_{(i, j) \notin B} a_{i} a_{j}=0-\sum_{(i, j) \in C} a_{i} a_{j} . \end{aligned} $$  So it suffices to show that if $A$ (and hence $B$ ) are nonempty, then  $$ \sum_{(i, j) \in C} a_{i} a_{j}>0 $$  Partition the indices into sets $P, Q, R$, and $S$ such that  $$ \begin{aligned} P & =\left\{i \mid a_{i} \leqslant-1\right\} & R & =\left\{i \mid 0<a_{i}<1\right\} \\ Q & =\left\{i \mid-1<a_{i} \leqslant 0\right\} & S & =\left\{i \mid 1 \leqslant a_{i}\right\} . \end{aligned} $$  Then  $$ \sum_{(i, j) \in C} a_{i} a_{j} \geqslant \sum_{i \in P \cup S} a_{i}^{2}+\sum_{i, j \in Q \cup R} a_{i} a_{j}=\sum_{i \in P \cup S} a_{i}^{2}+\left(\sum_{i \in Q \cup R} a_{i}\right)^{2} \geqslant 0 . $$  The first inequality holds because all of the positive terms in the RHS are also in the LHS, and all of the negative terms in the LHS are also in the RHS. The first inequality attains equality only if both sides have the same negative terms, which implies $\left|a_{i}-a_{j}\right|<1$ whenever $i, j \in Q \cup R$; the second inequality attains equality only if $P=S=\varnothing$. But then we would have $A=\varnothing$. So $A$ nonempty implies that the inequality holds strictly, as required.


Solution: Consider $P, Q, R, S$ as in   $$ p=\sum_{i \in P} a_{i}, \quad q=\sum_{i \in Q} a_{i}, \quad r=\sum_{i \in R} a_{i}, \quad s=\sum_{i \in S} a_{i}, $$  and let  $$ t_{+}=\sum_{(i, j) \in A, a_{i} a_{j} \geqslant 0} a_{i} a_{j}, \quad t_{-}=\sum_{(i, j) \in A, a_{i} a_{j} \leqslant 0} a_{i} a_{j} . $$  We know that $p+q+r+s=0$, and we need to prove that $t_{+}+t_{-}<0$. Notice that $t_{+} \leqslant p^{2} / 2+p q+r s+s^{2} / 2$ (with equality only if $p=s=0$ ), and $t_{-} \leqslant p r+p s+q s$ (with equality only if there do not exist $i \in Q$ and $j \in R$ with $a_{j}-a_{i}>1$ ). Therefore,  $$ t_{+}+t_{-} \leqslant \frac{p^{2}+s^{2}}{2}+p q+r s+p r+p s+q s=\frac{(p+q+r+s)^{2}}{2}-\frac{(q+r)^{2}}{2}=-\frac{(q+r)^{2}}{2} \leqslant 0 $$  If $A$ is not empty and $p=s=0$, then there must exist $i \in Q, j \in R$ with $\left|a_{i}-a_{j}\right|>1$, and hence the earlier equality conditions cannot both occur.  Comment. The RHS of the original inequality cannot be replaced with any constant $c<0$ (independent of $n$ ). Indeed, take  $$ a_{1}=-\frac{n}{n+2}, a_{2}=\cdots=a_{n-1}=\frac{1}{n+2}, a_{n}=\frac{2}{n+2} . $$  Then $\sum_{(i, j) \in A} a_{i} a_{j}=-\frac{2 n}{(n+2)^{2}}$, which converges to zero as $n \rightarrow \infty$.  This page is intentionally left blank


Let $x_{1}, x_{2}, \ldots, x_{n}$ be different real numbers. Prove that  $$ \sum_{1 \leqslant i \leqslant n} \prod_{j \neq i} \frac{1-x_{i} x_{j}}{x_{i}-x_{j}}= \begin{cases}0, & \text { if } n \text { is even } \\ 1, & \text { if } n \text { is odd }\end{cases} $$


A polynomial $P(x, y, z)$ in three variables with real coefficients satisfies the identities  $$ P(x, y, z)=P(x, y, x y-z)=P(x, z x-y, z)=P(y z-x, y, z) . $$  Prove that there exists a polynomial $F(t)$ in one variable such that  $$ P(x, y, z)=F\left(x^{2}+y^{2}+z^{2}-x y z\right) . $$

Solution: In the first two steps, we deal with any polynomial $P(x, y, z)$ satisfying $P(x, y, z)=$ $P(x, y, x y-z)$. Call such a polynomial weakly symmetric, and call a polynomial satisfying the full conditions in the problem symmetric. Step 1. We start with the description of weakly symmetric polynomials. We claim that they are exactly the polynomials in $x, y$, and $z(x y-z)$. Clearly, all such polynomials are weakly symmetric. For the converse statement, consider $P_{1}(x, y, z):=P\left(x, y, z+\frac{1}{2} x y\right)$, which satisfies $P_{1}(x, y, z)=P_{1}(x, y,-z)$ and is therefore a polynomial in $x, y$, and $z^{2}$. This means that $P$ is a polynomial in $x, y$, and $\left(z-\frac{1}{2} x y\right)^{2}=-z(x y-z)+\frac{1}{4} x^{2} y^{2}$, and therefore a polynomial in $x, y$, and $z(x y-z)$. Step 2. Suppose that $P$ is weakly symmetric. Consider the monomials in $P(x, y, z)$ of highest total degree. Our aim is to show that in each such monomial $\mu x^{a} y^{b} z^{c}$ we have $a, b \geqslant c$. Consider the expansion  $$ P(x, y, z)=\sum_{i, j, k} \mu_{i j k} x^{i} y^{j}(z(x y-z))^{k} $$  The maximal total degree of a summand in (1.1) is $m=\max _{i, j, k: \mu_{i j k} \neq 0}(i+j+3 k)$. Now, for any $i, j, k$ satisfying $i+j+3 k=m$ the summand $\mu_{i, j, k} x^{i} y^{j}(z(x y-z))^{k}$ has leading term of the form $\mu x^{i+k} y^{j+k} z^{k}$. No other nonzero summand in (1.1) may have a term of this form in its expansion, hence this term does not cancel in the whole sum. Therefore, $\operatorname{deg} P=m$, and the leading component of $P$ is exactly  $$ \sum_{i+j+3 k=m} \mu_{i, j, k} x^{i+k} y^{j+k} z^{k} $$  and each summand in this sum satisfies the condition claimed above. Step 3. We now prove the problem statement by induction on $m=\operatorname{deg} P$. For $m=0$ the claim is trivial. Consider now a symmetric polynomial $P$ with $\operatorname{deg} P>0$. By Step 2, each of its monomials $\mu x^{a} y^{b} z^{c}$ of the highest total degree satisfies $a, b \geqslant c$. Applying other weak symmetries, we obtain $a, c \geqslant b$ and $b, c \geqslant a$; therefore, $P$ has a unique leading monomial of the form $\mu(x y z)^{c}$. The polynomial $P_{0}(x, y, z)=P(x, y, z)-\mu\left(x y z-x^{2}-y^{2}-z^{2}\right)^{c}$ has smaller total degree. Since $P_{0}$ is symmetric, it is representable as a polynomial function of $x y z-x^{2}-y^{2}-z^{2}$. Then $P$ is also of this form, completing the inductive step.  Comment. We could alternatively carry out Step 1 by an induction on $n=\operatorname{deg}_{z} P$, in a manner similar to Step 3. If $n=0$, the statement holds. Assume that $n>0$ and check the leading component of $P$ with respect to $z$ :  $$ P(x, y, z)=Q_{n}(x, y) z^{n}+R(x, y, z) $$  where $\operatorname{deg}_{z} R<n$. After the change $z \mapsto x y-z$, the leading component becomes $Q_{n}(x, y)(-z)^{n}$; on the other hand, it should remain the same. Hence $n$ is even. Now consider the polynomial  $$ P_{0}(x, y, z)=P(x, y, z)-Q_{n}(x, y) \cdot(z(z-x y))^{n / 2} $$  It is also weakly symmetric, and $\operatorname{deg}_{z} P_{0}<n$. By the inductive hypothesis, it has the form $P_{0}(x, y, z)=$ $S(x, y, z(z-x y))$. Hence the polynomial  $$ P(x, y, z)=S(x, y, z(x y-z))+Q_{n}(x, y)(z(z-x y))^{n / 2} $$  also has this form. This completes the inductive step.


Solution: We will rely on the well-known identity  $$ \cos ^{2} u+\cos ^{2} v+\cos ^{2} w-2 \cos u \cos v \cos w-1=0 \quad \text { whenever } u+v+w=0 $$  Claim 1. The polynomial $P(x, y, z)$ is constant on the surface  $$ \mathfrak{S}=\{(2 \cos u, 2 \cos v, 2 \cos w): u+v+w=0\} $$  Proof. Notice that for $x=2 \cos u, y=2 \cos v, z=2 \cos w$, the Vieta jumps $x \mapsto y z-x$, $y \mapsto z x-y, z \mapsto x y-z$ in (*) replace $(u, v, w)$ by $(v-w,-v, w),(u, w-u,-w)$ and $(-u, v, u-v)$, respectively. For example, for the first type of jump we have  $$ y z-x=4 \cos v \cos w-2 \cos u=2 \cos (v+w)+2 \cos (v-w)-2 \cos u=2 \cos (v-w) . $$  Define $G(u, v, w)=P(2 \cos u, 2 \cos v, 2 \cos w)$. For $u+v+w=0$, the jumps give  $$ \begin{aligned} G(u, v, w) & =G(v-w,-v, w)=G(w-v,-v,(v-w)-(-v))=G(-u-2 v,-v, 2 v-w) \\ & =G(u+2 v, v, w-2 v) \end{aligned} $$  By induction,  $$ G(u, v, w)=G(u+2 k v, v, w-2 k v) \quad(k \in \mathbb{Z}) $$  Similarly,  $$ G(u, v, w)=G(u, v-2 \ell u, w+2 \ell u) \quad(\ell \in \mathbb{Z}) $$  And, of course, we have  $$ G(u, v, w)=G(u+2 p \pi, v+2 q \pi, w-2(p+q) \pi) \quad(p, q \in \mathbb{Z}) $$  Take two nonzero real numbers $u, v$ such that $u, v$ and $\pi$ are linearly independent over $\mathbb{Q}$. By combining (2.2-2.4), we can see that $G$ is constant on a dense subset of the plane $u+v+w=0$. By continuity, $G$ is constant on the entire plane and therefore $P$ is constant on $\mathfrak{S}$. Claim 2. The polynomial $T(x, y, z)=x^{2}+y^{2}+z^{2}-x y z-4$ divides $P(x, y, z)-P(2,2,2)$. Proof. By dividing $P$ by $T$ with remainders, there exist some polynomials $R(x, y, z), A(y, z)$ and $B(y, z)$ such that  $$ P(x, y, z)-P(2,2,2)=T(x, y, z) \cdot R(x, y, z)+A(y, z) x+B(y, z) $$  On the surface $\mathfrak{S}$ the LHS of (2.5) is zero by Claim 1 (since $(2,2,2) \in \mathfrak{S}$ ) and $T=0$ by (2.1). Hence, $A(y, z) x+B(y, z)$ vanishes on $\mathfrak{S}$.  Notice that for every $y=2 \cos v$ and $z=2 \cos w$ with $\frac{\pi}{3}<v, w<\frac{2 \pi}{3}$, there are two distinct values of $x$ such that $(x, y, z) \in \mathfrak{S}$, namely $x_{1}=2 \cos (v+w)$ (which is negative), and $x_{2}=2 \cos (v-w)$ (which is positive). This can happen only if $A(y, z)=B(y, z)=0$. Hence, $A(y, z)=B(y, z)=0$ for $|y|<1,|z|<1$. The polynomials $A$ and $B$ vanish on an open set, so $A$ and $B$ are both the zero polynomial.  The quotient $(P(x, y, z)-P(2,2,2)) / T(x, y, z)$ is a polynomial of lower degree than $P$ and it also satisfies (*). The problem statement can now be proven by induction on the degree of $P$.  Comment. In the proof of (2.2) and (2.3) we used two consecutive Vieta jumps; in fact from (*) we used only $P(x, y, x y-z)=P(x, z x-y, z)=P(y z-x, y, z)$.  Solution 3 (using algebraic geometry, just for interest). Let $Q=x^{2}+y^{2}+z^{2}-x y z$ and let $t \in \mathbb{C}$. Checking where $Q-t, \frac{\partial Q}{\partial x}, \frac{\partial Q}{\partial y}$ and $\frac{\partial Q}{\partial z}$ vanish simultaneously, we find that the surface $Q=t$ is smooth except for the cases $t=0$, when the only singular point is $(0,0,0)$, and $t=4$, when the four points $( \pm 2, \pm 2, \pm 2)$ that satisfy $x y z=8$ are the only singular points. The singular points are the fixed points of the group $\Gamma$ of polynomial automorphisms of $\mathbb{C}^{3}$ generated by the three Vieta involutions  $$ \iota_{1}:(x, y, z) \mapsto(x, y, x y-z), \quad \iota_{2}:(x, y, z) \mapsto(x, x z-y, z), \quad \iota_{3}:(x, y, z) \mapsto(y z-x, y, z) $$  $\Gamma$ acts on each surface $\mathcal{V}_{t}: Q-t=0$. If $Q-t$ were reducible then the surface $Q=t$ would contain a curve of singular points. Therefore $Q-t$ is irreducible in $\mathbb{C}[x, y, z]$. (One can also prove algebraically that $Q-t$ is irreducible, for example by checking that its discriminant as a quadratic polynomial in $x$ is not a square in $\mathbb{C}[y, z]$, and likewise for the other two variables.) In the following solution we will only use the algebraic surface $\mathcal{V}_{0}$.  Let $U$ be the $\Gamma$-orbit of $(3,3,3)$. Consider $\iota_{3} \circ \iota_{2}$, which leaves $z$ invariant. For each fixed value of $z, \iota_{3} \circ \iota_{2}$ acts linearly on $(x, y)$ by the matrix  $$ M_{z}:=\left(\begin{array}{cc} z^{2}-1 & -z \\ z & -1 \end{array}\right) $$  The reverse composition $\iota_{2} \circ \iota_{3}$ acts by $M_{z}^{-1}=M_{z}^{\text {adj }}$. Note det $M_{z}=1$ and $\operatorname{tr} M_{z}=z^{2}-2$. When $z$ does not lie in the real interval $[-2,2]$, the eigenvalues of $M_{z}$ do not have absolute value 1 , so every orbit of the group generated by $M_{z}$ on $\mathbb{C}^{2} \backslash\{(0,0)\}$ is unbounded. For example, fixing $z=3$ we find $\left(3 F_{2 k+1}, 3 F_{2 k-1}, 3\right) \in U$ for every $k \in \mathbb{Z}$, where $\left(F_{n}\right)_{n \in \mathbb{Z}}$ is the Fibonacci sequence with $F_{0}=0, F_{1}=1$.  Now we may start at any point $\left(3 F_{2 k+1}, 3 F_{2 k-1}, 3\right)$ and iteratively apply $\iota_{1} \circ \iota_{2}$ to generate another infinite sequence of distinct points of $U$, Zariski dense in the hyperbola cut out of $\mathcal{V}_{0}$ by the plane $x-3 F_{2 k+1}=0$. (The plane $x=a$ cuts out an irreducible conic when $a \notin\{-2,0,2\}$.) Thus the Zariski closure $\bar{U}$ of $U$ contains infinitely many distinct algebraic curves in $\mathcal{V}_{0}$. Since $\mathcal{V}_{0}$ is an irreducible surface this implies that $\bar{U}=\mathcal{V}_{0}$.  For any polynomial $P$ satisfying (*), we have $P-P(3,3,3)=0$ at each point of $U$. Since $\bar{U}=\mathcal{V}_{0}, P-P(3,3,3)$ vanishes on $\mathcal{V}_{0}$. Then Hilbert's Nullstellensatz and the irreducibility of $Q$ imply that $P-P(3,3,3)$ is divisible by $Q$. Now $(P-P(3,3,3)) / Q$ is a polynomial also satisfying (*), so we may complete the proof by an induction on the total degree, as in the other solutions.  Comment. We remark that Solution 2 used a trigonometric parametrisation of a real component of $\mathcal{V}_{4} ;$ in contrast $\mathcal{V}_{0}$ is birationally equivalent to the projective space $\mathbb{P}^{2}$ under the maps  $$ (x, y, z) \rightarrow(x: y: z), \quad(a: b: c) \rightarrow\left(\frac{a^{2}+b^{2}+c^{2}}{b c}, \frac{a^{2}+b^{2}+c^{2}}{a c}, \frac{a^{2}+b^{2}+c^{2}}{a b}\right) . $$  The set $U$ in Solution 3 is contained in $\mathbb{Z}^{3}$ so it is nowhere dense in $\mathcal{V}_{0}$ in the classical topology. Comment (background to the problem). A triple $(a, b, c) \in \mathbb{Z}^{3}$ is called a Markov triple if $a^{2}+b^{2}+c^{2}=3 a b c$, and an integer that occurs as a coordinate of some Markov triple is called a Markov number. (The spelling Markoff is also frequent.) Markov triples arose in A. Markov's work in the 1870s on the reduction theory of indefinite binary quadratic forms. For every Markov triple, $(3 a, 3 b, 3 c)$ lies on $Q=0$. It is well known that all nonzero Markov triples can be generated from $(1,1,1)$ by sequences of Vieta involutions, which are the substitutions described in equation (*) in the problem statement. There has been recent work by number theorists about the properties of Markov numbers (see for example Jean Bourgain, Alex Gamburd and Peter Sarnak, Markoff triples and strong approximation, Comptes Rendus Math. 345, no. 2, 131-135 (2016), arXiv:1505.06411). Each Markov number occurs in infinitely many triples, but a famous old open problem is the unicity conjecture, which asserts that each Markov number occurs in only one Markov triple (up to permutations and sign changes) as the largest coordinate in absolute value in that triple. It is a standard fact in the modern literature on Markov numbers that the Markov triples are Zariski dense in the Markov surface. Proving this is the main work of Solution 3. Algebraic geometry is definitely off-syllabus for the IMO, and one still has to work a bit to prove the Zariski density. On the other hand the approaches of Solutions 1 and 2 are elementary and only use tools expected to be known by IMO contestants. Therefore we do not think that the existence of a solution using algebraic geometry necessarily makes this problem unsuitable for the IMO.


Let $\mathbb{Z}$ be the set of integers. We consider functions $f: \mathbb{Z} \rightarrow \mathbb{Z}$ satisfying  $$ f(f(x+y)+y)=f(f(x)+y) $$  for all integers $x$ and $y$. For such a function, we say that an integer $v$ is $f$-rare if the set  $$ X_{v}=\{x \in \mathbb{Z}: f(x)=v\} $$  is finite and nonempty. (a) Prove that there exists such a function $f$ for which there is an $f$-rare integer. (b) Prove that no such function $f$ can have more than one $f$-rare integer.

Solution: a) Let $f$ be the function where $f(0)=0$ and $f(x)$ is the largest power of 2 dividing $2 x$ for $x \neq 0$. The integer 0 is evidently $f$-rare, so it remains to verify the functional equation.  Since $f(2 x)=2 f(x)$ for all $x$, it suffices to verify the functional equation when at least one of $x$ and $y$ is odd (the case $x=y=0$ being trivial). If $y$ is odd, then we have  $$ f(f(x+y)+y)=2=f(f(x)+y) $$  since all the values attained by $f$ are even. If, on the other hand, $x$ is odd and $y$ is even, then we already have  $$ f(x+y)=2=f(x) $$  from which the functional equation follows immediately. b) An easy inductive argument (substituting $x+k y$ for $x$ ) shows that  $$ f(f(x+k y)+y)=f(f(x)+y) $$  for all integers $x, y$ and $k$. If $v$ is an $f$-rare integer and $a$ is the least element of $X_{v}$, then by substituting $y=a-f(x)$ in the above, we see that  $$ f(x+k \cdot(a-f(x)))-f(x)+a \in X_{v} $$  for all integers $x$ and $k$, so that in particular  $$ f(x+k \cdot(a-f(x))) \geqslant f(x) $$  for all integers $x$ and $k$, by assumption on $a$. This says that on the (possibly degenerate) arithmetic progression through $x$ with common difference $a-f(x)$, the function $f$ attains its minimal value at $x$.  Repeating the same argument with $a$ replaced by the greatest element $b$ of $X_{v}$ shows that  $$ f(x+k \cdot(b-f(x)) \leqslant f(x) $$  for all integers $x$ and $k$. Combined with the above inequality, we therefore have  $$ f(x+k \cdot(a-f(x)) \cdot(b-f(x)))=f(x) $$  for all integers $x$ and $k$. Thus if $f(x) \neq a, b$, then the set $X_{f(x)}$ contains a nondegenerate arithmetic progression, so is infinite. So the only possible $f$-rare integers are $a$ and $b$.  In particular, the $f$-rare integer $v$ we started with must be one of $a$ or $b$, so that $f(v)=$ $f(a)=f(b)=v$. This means that there cannot be any other $f$-rare integers $v^{\prime}$, as they would on the one hand have to be either $a$ or $b$, and on the other would have to satisfy $f\left(v^{\prime}\right)=v^{\prime}$. Thus $v$ is the unique $f$-rare integer.  Comment 1. If $f$ is a solution to the functional equation, then so too is any conjugate of $f$ by a translation, i.e. any function $x \mapsto f(x+n)-n$ for an integer $n$. Thus in proving part (b), one is free to consider only functions $f$ for which 0 is $f$-rare, as in the following solution.  Solution 2, part (b) only. Suppose $v$ is $f$-rare, and let $a$ and $b$ be the least and greatest elements of $X_{v}$, respectively. Substituting $x=v$ and $y=a-v$ into the equation shows that  $$ f(v)-v+a \in X_{v} $$  and in particular $f(v) \geqslant v$. Repeating the same argument with $x=v$ and $y=b-v$ shows that $f(v) \leqslant v$, and hence $f(v)=v$.  Suppose now that $v^{\prime}$ is a second $f$-rare integer. We may assume that $v=0$ (see Comment 1 ). We've seen that $f\left(v^{\prime}\right)=v^{\prime}$; we claim that in fact $f\left(k v^{\prime}\right)=v^{\prime}$ for all positive integers $k$. This gives a contradiction unless $v^{\prime}=v=0$.  This claim is proved by induction on $k$. Supposing it to be true for $k$, we substitute $y=k v^{\prime}$ and $x=0$ into the functional equation to yield  $$ f\left((k+1) v^{\prime}\right)=f\left(f(0)+k v^{\prime}\right)=f\left(k v^{\prime}\right)=v^{\prime} $$  using that $f(0)=0$. This completes the induction, and hence the proof. Comment 2. There are many functions $f$ satisfying the functional equation for which there is an $f$-rare integer. For instance, one may generalise the construction in part (a) of Solution 1 by taking a sequence $1=a_{0}, a_{1}, a_{2}, \ldots$ of positive integers with each $a_{i}$ a proper divisor of $a_{i+1}$ and choosing arbitrary functions $f_{i}:\left(\mathbb{Z} / a_{i} \mathbb{Z}\right) \backslash\{0\} \rightarrow a_{i} \mathbb{Z} \backslash\{0\}$ from the nonzero residue classes modulo $a_{i}$ to the nonzero multiples of $a_{i}$. One then defines a function $f: \mathbb{Z} \rightarrow \mathbb{Z}$ by  $$ f(x):= \begin{cases}f_{i+1}\left(x \bmod a_{i+1}\right), & \text { if } a_{i} \mid x \text { but } a_{i+1} \nmid x \\ 0, & \text { if } x=0\end{cases} $$  If one writes $v(x)$ for the largest $i$ such that $a_{i} \mid x$ (with $v(0)=\infty$ ), then it is easy to verify the functional equation for $f$ separately in the two cases $v(y)>v(x)$ and $v(x) \geqslant v(y)$. Hence this $f$ satisfies the functional equation and 0 is an $f$-rare integer.  Comment 3. In fact, if $v$ is an $f$-rare integer for an $f$ satisfying the functional equation, then its fibre $X_{v}=\{v\}$ must be a singleton. We may assume without loss of generality that $v=0$. We've already seen in Solution 1 that 0 is either the greatest or least element of $X_{0}$; replacing $f$ with the function $x \mapsto-f(-x)$ if necessary, we may assume that 0 is the least element of $X_{0}$. We write $b$ for the largest element of $X_{0}$, supposing for contradiction that $b>0$, and write $N=(2 b)$ !.  It now follows from (*) that we have  $$ f(f(N b)+b)=f(f(0)+b)=f(b)=0 $$  from which we see that $f(N b)+b \in X_{0} \subseteq[0, b]$. It follows that $f(N b) \in[-b, 0)$, since by construction $N b \notin X_{v}$. Now it follows that $(f(N b)-0) \cdot(f(N b)-b)$ is a divisor of $N$, so from ( $\dagger$ ) we see that $f(N b)=f(0)=0$. This yields the desired contradiction.


The infinite sequence $a_{0}, a_{1}, a_{2}, \ldots$ of (not necessarily different) integers has the following properties: $0 \leqslant a_{i} \leqslant i$ for all integers $i \geqslant 0$, and  $$ \binom{k}{a_{0}}+\binom{k}{a_{1}}+\cdots+\binom{k}{a_{k}}=2^{k} $$  for all integers $k \geqslant 0$. Prove that all integers $N \geqslant 0$ occur in the sequence (that is, for all $N \geqslant 0$, there exists $i \geqslant 0$ with $a_{i}=N$ ).  ## (Netherlands)

Solution: We prove by induction on $k$ that every initial segment of the sequence, $a_{0}, a_{1}, \ldots, a_{k}$, consists of the following elements (counted with multiplicity, and not necessarily in order), for some $\ell \geqslant 0$ with $2 \ell \leqslant k+1$ :  $$ 0,1, \ldots, \ell-1, \quad 0,1, \ldots, k-\ell $$  For $k=0$ we have $a_{0}=0$, which is of this form. Now suppose that for $k=m$ the elements $a_{0}, a_{1}, \ldots, a_{m}$ are $0,0,1,1,2,2, \ldots, \ell-1, \ell-1, \ell, \ell+1, \ldots, m-\ell-1, m-\ell$ for some $\ell$ with $0 \leqslant 2 \ell \leqslant m+1$. It is given that  $$ \binom{m+1}{a_{0}}+\binom{m+1}{a_{1}}+\cdots+\binom{m+1}{a_{m}}+\binom{m+1}{a_{m+1}}=2^{m+1} $$  which becomes  $$ \begin{aligned} \left(\binom{m+1}{0}+\binom{m+1}{1}\right. & \left.+\cdots+\binom{m+1}{\ell-1}\right) \\ & +\left(\binom{m+1}{0}+\binom{m+1}{1}+\cdots+\binom{m+1}{m-\ell}\right)+\binom{m+1}{a_{m+1}}=2^{m+1} \end{aligned} $$  or, using $\binom{m+1}{i}=\binom{m+1}{m+1-i}$, that  $$ \begin{aligned} \left(\binom{m+1}{0}+\binom{m+1}{1}\right. & \left.+\cdots+\binom{m+1}{\ell-1}\right) \\ & +\left(\binom{m+1}{m+1}+\binom{m+1}{m}+\cdots+\binom{m+1}{\ell+1}\right)+\binom{m+1}{a_{m+1}}=2^{m+1} \end{aligned} $$  On the other hand, it is well known that  $$ \binom{m+1}{0}+\binom{m+1}{1}+\cdots+\binom{m+1}{m+1}=2^{m+1} $$  and so, by subtracting, we get  $$ \binom{m+1}{a_{m+1}}=\binom{m+1}{\ell} $$  From this, using the fact that the binomial coefficients $\binom{m+1}{i}$ are increasing for $i \leqslant \frac{m+1}{2}$ and decreasing for $i \geqslant \frac{m+1}{2}$, we conclude that either $a_{m+1}=\ell$ or $a_{m+1}=m+1-\ell$. In either case, $a_{0}, a_{1}, \ldots, a_{m+1}$ is again of the claimed form, which concludes the induction.  As a result of this description, any integer $N \geqslant 0$ appears as a term of the sequence $a_{i}$ for some $0 \leqslant i \leqslant 2 N$.


You are given a set of $n$ blocks, each weighing at least 1 ; their total weight is $2 n$. Prove that for every real number $r$ with $0 \leqslant r \leqslant 2 n-2$ you can choose a subset of the blocks whose total weight is at least $r$ but at most $r+2$. (Thailand)

Solution: We prove the following more general statement by induction on $n$. Claim. Suppose that you have $n$ blocks, each of weight at least 1 , and of total weight $s \leqslant 2 n$. Then for every $r$ with $-2 \leqslant r \leqslant s$, you can choose some of the blocks whose total weight is at least $r$ but at most $r+2$. Proof. The base case $n=1$ is trivial. To prove the inductive step, let $x$ be the largest block weight. Clearly, $x \geqslant s / n$, so $s-x \leqslant \frac{n-1}{n} s \leqslant 2(n-1)$. Hence, if we exclude a block of weight $x$, we can apply the inductive hypothesis to show the claim holds (for this smaller set) for any $-2 \leqslant r \leqslant s-x$. Adding the excluded block to each of those combinations, we see that the claim also holds when $x-2 \leqslant r \leqslant s$. So if $x-2 \leqslant s-x$, then we have covered the whole interval $[-2, s]$. But each block weight is at least 1 , so we have $x-2 \leqslant(s-(n-1))-2=s-(2 n-(n-1)) \leqslant s-(s-(n-1)) \leqslant s-x$, as desired.  Comment. Instead of inducting on sets of blocks with total weight $s \leqslant 2 n$, we could instead prove the result only for $s=2 n$. We would then need to modify the inductive step to scale up the block weights before applying the induction hypothesis.


Solution: Let $x_{1}, \ldots, x_{n}$ be the weights of the blocks in weakly increasing order. Consider the set $S$ of sums of the form $\sum_{j \in J} x_{j}$ for a subset $J \subseteq\{1,2, \ldots, n\}$. We want to prove that the mesh of $S$ - i.e. the largest distance between two adjacent elements - is at most 2.  For $0 \leqslant k \leqslant n$, let $S_{k}$ denote the set of sums of the form $\sum_{i \in J} x_{i}$ for a subset $J \subseteq\{1,2, \ldots, k\}$. We will show by induction on $k$ that the mesh of $S_{k}$ is at most 2 .  The base case $k=0$ is trivial (as $S_{0}=\{0\}$ ). For $k>0$ we have  $$ S_{k}=S_{k-1} \cup\left(x_{k}+S_{k-1}\right) $$  (where $\left(x_{k}+S_{k-1}\right)$ denotes $\left\{x_{k}+s: s \in S_{k-1}\right\}$ ), so it suffices to prove that $x_{k} \leqslant \sum_{j<k} x_{j}+2$. But if this were not the case, we would have $x_{l}>\sum_{j<k} x_{j}+2 \geqslant k+1$ for all $l \geqslant k$, and hence  $$ 2 n=\sum_{j=1}^{n} x_{j}>(n+1-k)(k+1)+k-1 $$  This rearranges to $n>k(n+1-k)$, which is false for $1 \leqslant k \leqslant n$, giving the desired contradiction.


Let $n$ be a positive integer. Harry has $n$ coins lined up on his desk, each showing  heads or tails. He repeatedly does the following operation: if there are $k$ coins showing heads and $k>0$, then he flips the $k^{\text {th }}$ coin over; otherwise he stops the process. (For example, the process starting with THT would be THT $\rightarrow H H T \rightarrow H T T \rightarrow T T T$, which takes three steps.)  Letting $C$ denote the initial configuration (a sequence of $n H$ 's and $T$ 's), write $\ell(C)$ for the number of steps needed before all coins show $T$. Show that this number $\ell(C)$ is finite, and determine its average value over all $2^{n}$ possible initial configurations $C$.

Solution: We represent the problem using a directed graph $G_{n}$ whose vertices are the length- $n$ strings of $H$ 's and $T$ 's. The graph features an edge from each string to its successor (except for $T T \cdots T T$, which has no successor). We will also write $\bar{H}=T$ and $\bar{T}=H$.  The graph $G_{0}$ consists of a single vertex: the empty string. The main claim is that $G_{n}$ can be described explicitly in terms of $G_{n-1}$ :  - We take two copies, $X$ and $Y$, of $G_{n-1}$. - In $X$, we take each string of $n-1$ coins and just append a $T$ to it. In symbols, we replace $s_{1} \cdots s_{n-1}$ with $s_{1} \cdots s_{n-1} T$. - In $Y$, we take each string of $n-1$ coins, flip every coin, reverse the order, and append an $H$ to it. In symbols, we replace $s_{1} \cdots s_{n-1}$ with $\bar{s}_{n-1} \bar{s}_{n-2} \cdots \bar{s}_{1} H$. - Finally, we add one new edge from $Y$ to $X$, namely $H H \cdots H H H \rightarrow H H \cdots H H T$.  We depict $G_{4}$ below, in a way which indicates this recursive construction: ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-034.jpg?height=515&width=1135&top_left_y=1850&top_left_x=466)  We prove the claim inductively. Firstly, $X$ is correct as a subgraph of $G_{n}$, as the operation on coins is unchanged by an extra $T$ at the end: if $s_{1} \cdots s_{n-1}$ is sent to $t_{1} \cdots t_{n-1}$, then $s_{1} \cdots s_{n-1} T$ is sent to $t_{1} \cdots t_{n-1} T$.  Next, $Y$ is also correct as a subgraph of $G_{n}$, as if $s_{1} \cdots s_{n-1}$ has $k$ occurrences of $H$, then $\bar{s}_{n-1} \cdots \bar{s}_{1} H$ has $(n-1-k)+1=n-k$ occurrences of $H$, and thus (provided that $k>0$ ), if $s_{1} \cdots s_{n-1}$ is sent to $t_{1} \cdots t_{n-1}$, then $\bar{s}_{n-1} \cdots \bar{s}_{1} H$ is sent to $\bar{t}_{n-1} \cdots \bar{t}_{1} H$.  Finally, the one edge from $Y$ to $X$ is correct, as the operation does send $H H \cdots H H H$ to HH $\cdots$ HHT.  To finish, note that the sequences in $X$ take an average of $E(n-1)$ steps to terminate, whereas the sequences in $Y$ take an average of $E(n-1)$ steps to reach $H H \cdots H$ and then an additional $n$ steps to terminate. Therefore, we have  $$ E(n)=\frac{1}{2}(E(n-1)+(E(n-1)+n))=E(n-1)+\frac{n}{2} $$  We have $E(0)=0$ from our description of $G_{0}$. Thus, by induction, we have $E(n)=\frac{1}{2}(1+\cdots+$ $n)=\frac{1}{4} n(n+1)$, which in particular is finite.


Solution: We consider what happens with configurations depending on the coins they start and end with.  - If a configuration starts with $H$, the last $n-1$ coins follow the given rules, as if they were all the coins, until they are all $T$, then the first coin is turned over. - If a configuration ends with $T$, the last coin will never be turned over, and the first $n-1$ coins follow the given rules, as if they were all the coins. - If a configuration starts with $T$ and ends with $H$, the middle $n-2$ coins follow the given rules, as if they were all the coins, until they are all $T$. After that, there are $2 n-1$ more steps: first coins $1,2, \ldots, n-1$ are turned over in that order, then coins $n, n-1, \ldots, 1$ are turned over in that order.  As this covers all configurations, and the number of steps is clearly finite for 0 or 1 coins, it follows by induction on $n$ that the number of steps is always finite.  We define $E_{A B}(n)$, where $A$ and $B$ are each one of $H, T$ or $*$, to be the average number of steps over configurations of length $n$ restricted to those that start with $A$, if $A$ is not $*$, and that end with $B$, if $B$ is not * (so * represents "either $H$ or $T$ "). The above observations tell us that, for $n \geqslant 2$ :  - $E_{H *}(n)=E(n-1)+1$. - $E_{* T}(n)=E(n-1)$. - $E_{H T}(n)=E(n-2)+1$ (by using both the observations for $H *$ and for $\left.* T\right)$. - $E_{T H}(n)=E(n-2)+2 n-1$.  Now $E_{H *}(n)=\frac{1}{2}\left(E_{H H}(n)+E_{H T}(n)\right)$, so $E_{H H}(n)=2 E(n-1)-E(n-2)+1$. Similarly, $E_{T T}(n)=2 E(n-1)-E(n-2)-1$. So  $$ E(n)=\frac{1}{4}\left(E_{H T}(n)+E_{H H}(n)+E_{T T}(n)+E_{T H}(n)\right)=E(n-1)+\frac{n}{2} $$  We have $E(0)=0$ and $E(1)=\frac{1}{2}$, so by induction on $n$ we have $E(n)=\frac{1}{4} n(n+1)$.


Solution: Let $H_{i}$ be the number of heads in positions 1 to $i$ inclusive (so $H_{n}$ is the total number of heads), and let $I_{i}$ be 1 if the $i^{\text {th }}$ coin is a head, 0 otherwise. Consider the function  $$ t(i)=I_{i}+2\left(\min \left\{i, H_{n}\right\}-H_{i}\right) $$  We claim that $t(i)$ is the total number of times coin $i$ is turned over (which implies that the process terminates). Certainly $t(i)=0$ when all coins are tails, and $t(i)$ is always a nonnegative integer, so it suffices to show that when the $k^{\text {th }}$ coin is turned over (where $k=H_{n}$ ), $t(k)$ goes down by 1 and all the other $t(i)$ are unchanged. We show this by splitting into cases:  - If $i<k, I_{i}$ and $H_{i}$ are unchanged, and $\min \left\{i, H_{n}\right\}=i$ both before and after the coin flip, so $t(i)$ is unchanged. - If $i>k, \min \left\{i, H_{n}\right\}=H_{n}$ both before and after the coin flip, and both $H_{n}$ and $H_{i}$ change by the same amount, so $t(i)$ is unchanged. - If $i=k$ and the coin is heads, $I_{i}$ goes down by 1 , as do both $\min \left\{i, H_{n}\right\}=H_{n}$ and $H_{i}$; so $t(i)$ goes down by 1 . - If $i=k$ and the coin is tails, $I_{i}$ goes up by $1, \min \left\{i, H_{n}\right\}=i$ is unchanged and $H_{i}$ goes up by 1 ; so $t(i)$ goes down by 1 .  We now need to compute the average value of  $$ \sum_{i=1}^{n} t(i)=\sum_{i=1}^{n} I_{i}+2 \sum_{i=1}^{n} \min \left\{i, H_{n}\right\}-2 \sum_{i=1}^{n} H_{i} . $$  The average value of the first term is $\frac{1}{2} n$, and that of the third term is $-\frac{1}{2} n(n+1)$. To compute the second term, we sum over choices for the total number of heads, and then over the possible values of $i$, getting  $$ 2^{1-n} \sum_{j=0}^{n}\binom{n}{j} \sum_{i=1}^{n} \min \{i, j\}=2^{1-n} \sum_{j=0}^{n}\binom{n}{j}\left(n j-\binom{j}{2}\right) . $$  Now, in terms of trinomial coefficients,  $$ \sum_{j=0}^{n} j\binom{n}{j}=\sum_{j=1}^{n}\binom{n}{n-j, j-1,1}=n \sum_{j=0}^{n-1}\binom{n-1}{j}=2^{n-1} n $$  and  $$ \sum_{j=0}^{n}\binom{j}{2}\binom{n}{j}=\sum_{j=2}^{n}\binom{n}{n-j, j-2,2}=\binom{n}{2} \sum_{j=0}^{n-2}\binom{n-2}{j}=2^{n-2}\binom{n}{2} $$  So the second term above is  $$ 2^{1-n}\left(2^{n-1} n^{2}-2^{n-2}\binom{n}{2}\right)=n^{2}-\frac{n(n-1)}{4} $$  and the required average is  $$ E(n)=\frac{1}{2} n+n^{2}-\frac{n(n-1)}{4}-\frac{1}{2} n(n+1)=\frac{n(n+1)}{4} . $$


Solution: Harry has built a Turing machine to flip the coins for him. The machine is initially positioned at the $k^{\text {th }}$ coin, where there are $k$ heads (and the position before the first coin is considered to be the $0^{\text {th }}$ coin). The machine then moves according to the following rules, stopping when it reaches the position before the first coin: if the coin at its current position is $H$, it flips the coin and moves to the previous coin, while if the coin at its current position is $T$, it flips the coin and moves to the next position.  Consider the maximal sequences of consecutive moves in the same direction. Suppose the machine has $a$ consecutive moves to the next coin, before a move to the previous coin. After those $a$ moves, the $a$ coins flipped in those moves are all heads, as is the coin the machine is now at, so at least the next $a+1$ moves will all be moves to the previous coin. Similarly, $a$ consecutive moves to the previous coin are followed by at least $a+1$ consecutive moves to the next coin. There cannot be more than $n$ consecutive moves in the same direction, so this proves that the process terminates (with a move from the first coin to the position before the first coin).  Thus we have a (possibly empty) sequence $a_{1}<\cdots<a_{t} \leqslant n$ giving the lengths of maximal sequences of consecutive moves in the same direction, where the final $a_{t}$ moves must be moves to the previous coin, ending before the first coin. We claim there is a bijection between initial configurations of the coins and such sequences. This gives  $$ E(n)=\frac{1}{2}(1+2+\cdots+n)=\frac{n(n+1)}{4} $$  as required, since each $i$ with $1 \leqslant i \leqslant n$ will appear in half of the sequences, and will contribute $i$ to the number of moves when it does.  To see the bijection, consider following the sequence of moves backwards, starting with the machine just before the first coin and all coins showing tails. This certainly determines a unique configuration of coins that could possibly correspond to the given sequence. Furthermore, every coin flipped as part of the $a_{j}$ consecutive moves is also flipped as part of all subsequent sequences of $a_{k}$ consecutive moves, for all $k>j$, meaning that, as we follow the moves backwards, each coin is always in the correct state when flipped to result in a move in the required direction. (Alternatively, since there are $2^{n}$ possible configurations of coins and $2^{n}$ possible such ascending sequences, the fact that the sequence of moves determines at most one configuration of coins, and thus that there is an injection from configurations of coins to such ascending sequences, is sufficient for it to be a bijection, without needing to show that coins are in the right state as we move backwards.)


Solution: We explicitly describe what happens with an arbitrary sequence $C$ of $n$ coins. Suppose that $C$ contain $k$ heads at positions $1 \leqslant c_{1}<c_{2}<\cdots<c_{k} \leqslant n$.  Let $i$ be the minimal index such that $c_{i} \geqslant k$. Then the first few steps will consist of turning over the $k^{\mathrm{th}},(k+1)^{\mathrm{th}}, \ldots, c_{i}^{\mathrm{th}},\left(c_{i}-1\right)^{\mathrm{th}},\left(c_{i}-2\right)^{\mathrm{th}}, \ldots, k^{\mathrm{th}}$ coins in this order. After that we get a configuration with $k-1$ heads at the same positions as in the initial one, except for $c_{i}$. This part of the process takes $2\left(c_{i}-k\right)+1$ steps.  After that, the process acts similarly; by induction on the number of heads we deduce that the process ends. Moreover, if the $c_{i}$ disappear in order $c_{i_{1}}, \ldots, c_{i_{k}}$, the whole process takes  $$ \ell(C)=\sum_{j=1}^{k}\left(2\left(c_{i_{j}}-(k+1-j)\right)+1\right)=2 \sum_{j=1}^{k} c_{j}-2 \sum_{j=1}^{k}(k+1-j)+k=2 \sum_{j=1}^{k} c_{j}-k^{2} $$  steps. Now let us find the total value $S_{k}$ of $\ell(C)$ over all $\binom{n}{k}$ configurations with exactly $k$ heads. To sum up the above expression over those, notice that each number $1 \leqslant i \leqslant n$ appears as $c_{j}$ exactly $\binom{n-1}{k-1}$ times. Thus  $$ \begin{gathered} S_{k}=2\binom{n-1}{k-1} \sum_{i=1}^{n} i-\binom{n}{k} k^{2}=2 \frac{(n-1) \cdots(n-k+1)}{(k-1)!} \cdot \frac{n(n+1)}{2}-\frac{n \cdots(n-k+1)}{k!} k^{2} \\ =\frac{n(n-1) \cdots(n-k+1)}{(k-1)!}((n+1)-k)=n(n-1)\binom{n-2}{k-1}+n\binom{n-1}{k-1} . \end{gathered} $$  Therefore, the total value of $\ell(C)$ over all configurations is  $$ \sum_{k=1}^{n} S_{k}=n(n-1) \sum_{k=1}^{n}\binom{n-2}{k-1}+n \sum_{k=1}^{n}\binom{n-1}{k-1}=n(n-1) 2^{n-2}+n 2^{n-1}=2^{n} \frac{n(n+1)}{4} $$  Hence the required average is $E(n)=\frac{n(n+1)}{4}$.


On a flat plane in Camelot, King Arthur builds a labyrinth $\mathfrak{L}$ consisting of $n$ walls, each of which is an infinite straight line. No two walls are parallel, and no three walls have a common point. Merlin then paints one side of each wall entirely red and the other side entirely blue.  At the intersection of two walls there are four corners: two diagonally opposite corners where a red side and a blue side meet, one corner where two red sides meet, and one corner where two blue sides meet. At each such intersection, there is a two-way door connecting the two diagonally opposite corners at which sides of different colours meet.  After Merlin paints the walls, Morgana then places some knights in the labyrinth. The knights can walk through doors, but cannot walk through walls.  Let $k(\mathfrak{L})$ be the largest number $k$ such that, no matter how Merlin paints the labyrinth $\mathfrak{L}$, Morgana can always place at least $k$ knights such that no two of them can ever meet. For each $n$, what are all possible values for $k(\mathfrak{L})$, where $\mathfrak{L}$ is a labyrinth with $n$ walls? (Canada)

Solution: First we show by induction that the $n$ walls divide the plane into $\binom{n+1}{2}+1$ regions. The claim is true for $n=0$ as, when there are no walls, the plane forms a single region. When placing the $n^{\text {th }}$ wall, it intersects each of the $n-1$ other walls exactly once and hence splits each of $n$ of the regions formed by those other walls into two regions. By the induction hypothesis, this yields $\left(\binom{n}{2}+1\right)+n=\binom{n+1}{2}+1$ regions, proving the claim.  Now let $G$ be the graph with vertices given by the $\binom{n+1}{2}+1$ regions, and with two regions connected by an edge if there is a door between them.  We now show that no matter how Merlin paints the $n$ walls, Morgana can place at least $n+1$ knights. No matter how the walls are painted, there are exactly $\binom{n}{2}$ intersection points, each of which corresponds to a single edge in $G$. Consider adding the edges of $G$ sequentially and note that each edge reduces the number of connected components by at most one. Therefore the number of connected components of G is at least $\binom{n+1}{2}+1-\binom{n}{2}=n+1$. If Morgana places a knight in regions corresponding to different connected components of $G$, then no two knights can ever meet.  Now we give a construction showing that, no matter what shape the labyrinth is, Merlin can colour it such that there are exactly $n+1$ connected components, allowing Morgana to place at most $n+1$ knights.  First, we choose a coordinate system on the labyrinth so that none of the walls run due north-south, or due east-west. We then have Merlin paint the west face of each wall red, and the east face of each wall blue. We label the regions according to how many walls the region is on the east side of: the labels are integers between 0 and $n$.  We claim that, for each $i$, the regions labelled $i$ are connected by doors. First, we note that for each $i$ with $0 \leqslant i \leqslant n$ there is a unique region labelled $i$ which is unbounded to the north.  Now, consider a knight placed in some region with label $i$, and ask them to walk north (moving east or west by following the walls on the northern sides of regions, as needed). This knight will never get stuck: each region is convex, and so, if it is bounded to the north, it has a single northernmost vertex with a door northwards to another region with label $i$.  Eventually it will reach a region which is unbounded to the north, which will be the unique such region with label $i$. Hence every region with label $i$ is connected to this particular region, and so all regions with label $i$ are connected to each other.  As a result, there are exactly $n+1$ connected components, and Morgana can place at most $n+1$ knights.  Comment. Variations on this argument exist: some of them capture more information, and some of them capture less information, about the connected components according to this system of numbering.  For example, it can be shown that the unbounded regions are numbered $0,1, \ldots, n-1, n, n-1, \ldots, 1$ as one cycles around them, that the regions labelled 0 and $n$ are the only regions in their connected components, and that each other connected component forms a single chain running between the two unbounded ones. It is also possible to argue that the regions are acyclic without revealing much about their structure.


Solution: We give another description of a strategy for Merlin to paint the walls so that Morgana can place no more than $n+1$ knights.  Merlin starts by building a labyrinth of $n$ walls of his own design. He places walls in turn with increasing positive gradients, placing each so far to the right that all intersection points of previously-placed lines lie to the left of it. He paints each in such a way that blue is on the left and red is on the right.  For example, here is a possible sequence of four such lines $\ell_{1}, \ell_{2}, \ell_{3}, \ell_{4}$ : ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-039.jpg?height=441&width=558&top_left_y=982&top_left_x=749)  We say that a region is "on the right" if it has $x$-coordinate unbounded above (note that if we only have one wall, then both regions are on the right). We claim inductively that, after placing $n$ lines, there are $n+1$ connected components in the resulting labyrinth, each of which contains exactly one region on the right. This is certainly true after placing 0 lines, as then there is only one region (and hence one connected component) and it is on the right.  When placing the $n^{\text {th }}$ line, it then cuts every one of the $n-1$ previously placed lines, and since it is to the right of all intersection points, the regions it cuts are exactly the $n$ regions on the right. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-039.jpg?height=495&width=518&top_left_y=1900&top_left_x=775)  The addition of this line leaves all previous connected components with exactly one region on the right, and creates a new connected component containing exactly one region, and that region is also on the right. As a result, by induction, this particular labyrinth will have $n+1$ connected components.  Having built this labyrinth, Merlin then moves the walls one-by-one (by a sequence of continuous translations and rotations of lines) into the proper position of the given labyrinth, in such a way that no two lines ever become parallel.  The only time the configuration is changed is when one wall is moved through an intersection point of two others: ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-040.jpg?height=493&width=1472&top_left_y=353&top_left_x=289)  Note that all moves really do switch between two configurations like this: all sets of three lines have this colour configuration initially, and the rules on rotations mean they are preserved (in particular, we cannot create three lines creating a triangle with three red edges inwards, or three blue edges inwards).  However, as can be seen, such a move preserves the number of connected components, so in the painting this provides for Arthur's actual labyrinth, Morgana can still only place at most $n+1$ knights.  Comment. While these constructions are superficially distinct, they in fact result in the same colourings for any particular labyrinth. In fact, using the methods of Solution 2, it is possible to show that these are the only colourings that result in exactly $n+1$ connected components.


On a certain social network, there are 2019 users, some pairs of which are friends, where friendship is a symmetric relation. Initially, there are 1010 people with 1009 friends each and 1009 people with 1010 friends each. However, the friendships are rather unstable, so events of the following kind may happen repeatedly, one at a time:  Let $A, B$, and $C$ be people such that $A$ is friends with both $B$ and $C$, but $B$ and $C$ are not friends; then $B$ and $C$ become friends, but $A$ is no longer friends with them. Prove that, regardless of the initial friendships, there exists a sequence of such events after which each user is friends with at most one other user. (Croatia)

Solution: Note that the given graph is connected, since the total degree of any two vertices is at least 2018 and hence they are either adjacent or have at least one neighbour in common. Hence the given graph satisfies the following condition:  Every connected component of $G$ with at least three vertices is not complete and has a vertex of odd degree.  We will show that if a graph $G$ satisfies condition (1) and has a vertex of degree at least 2 , then there is a refriending on $G$ that preserves condition (1). Since refriendings decrease the total number of edges of $G$, by using a sequence of such refriendings, we must reach a graph $G$ with maximal degree at most 1 , so we are done. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-041.jpg?height=866&width=872&top_left_y=1891&top_left_x=592)  Pick a vertex $A$ of degree at least 2 in a connected component $G^{\prime}$ of $G$. Since no component of $G$ with at least three vertices is complete we may assume that not all of the neighbours of $A$ are adjacent to one another. (For example, pick a maximal complete subgraph $K$ of $G^{\prime}$. Some vertex $A$ of $K$ has a neighbour outside $K$, and this neighbour is not adjacent to every vertex of $K$ by maximality.) Removing $A$ from $G$ splits $G^{\prime}$ into smaller connected components $G_{1}, \ldots, G_{k}$ (possibly with $k=1$ ), to each of which $A$ is connected by at least one edge. We divide into several cases.  Case 1: $k \geqslant 2$ and $A$ is connected to some $G_{i}$ by at least two edges. Choose a vertex $B$ of $G_{i}$ adjacent to $A$, and a vertex $C$ in another component $G_{j}$ adjacent to $A$. The vertices $B$ and $C$ are not adjacent, and hence removing edges $A B$ and $A C$ and adding in edge $B C$ does not disconnect $G^{\prime}$. It is easy to see that this preserves the condition, since the refriending does not change the parity of the degrees of vertices.  Case 2: $k \geqslant 2$ and $A$ is connected to each $G_{i}$ by exactly one edge. Consider the induced subgraph on any $G_{i}$ and the vertex $A$. The vertex $A$ has degree 1 in this subgraph; since the number of odd-degree vertices of a graph is always even, we see that $G_{i}$ has a vertex of odd degree (in $G$ ). Thus if we let $B$ and $C$ be any distinct neighbours of $A$, then removing edges $A B$ and $A C$ and adding in edge $B C$ preserves the above condition: the refriending creates two new components, and if either of these components has at least three vertices, then it cannot be complete and must contain a vertex of odd degree (since each $G_{i}$ does).  Case 3: $k=1$ and $A$ is connected to $G_{1}$ by at least three edges. By assumption, $A$ has two neighbours $B$ and $C$ which are not adjacent to one another. Removing edges $A B$ and $A C$ and adding in edge $B C$ does not disconnect $G^{\prime}$. We are then done as in Case 1.  Case 4: $k=1$ and $A$ is connected to $G_{1}$ by exactly two edges. Let $B$ and $C$ be the two neighbours of $A$, which are not adjacent. Removing edges $A B$ and $A C$ and adding in edge $B C$ results in two new components: one consisting of a single vertex; and the other containing a vertex of odd degree. We are done unless this second component would be a complete graph on at least 3 vertices. But in this case, $G_{1}$ would be a complete graph minus the single edge $B C$, and hence has at least 4 vertices since $G^{\prime}$ is not a 4 -cycle. If we let $D$ be a third vertex of $G_{1}$, then removing edges $B A$ and $B D$ and adding in edge $A D$ does not disconnect $G^{\prime}$. We are then done as in Case 1. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-042.jpg?height=324&width=286&top_left_y=2208&top_left_x=885)  Comment. In fact, condition 1 above precisely characterises those graphs which can be reduced to a graph of maximal degree $\leqslant 1$ by a sequence of refriendings.


Solution: As in the previous solution, note that a refriending preserves the property that a graph has a vertex of odd degree and (trivially) the property that it is not complete; note also that our initial graph is connected. We describe an algorithm to reduce our initial graph to a graph of maximal degree at most 1, proceeding in two steps.  Step 1: There exists a sequence of refriendings reducing the graph to a tree. Proof. Since the number of edges decreases with each refriending, it suffices to prove the following: as long as the graph contains a cycle, there exists a refriending such that the resulting graph is still connected. We will show that the graph in fact contains a cycle $Z$ and vertices $A, B, C$ such that $A$ and $B$ are adjacent in the cycle $Z, C$ is not in $Z$, and is adjacent to $A$ but not $B$. Removing edges $A B$ and $A C$ and adding in edge $B C$ keeps the graph connected, so we are done. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-043.jpg?height=381&width=489&top_left_y=863&top_left_x=778)  To find this cycle $Z$ and vertices $A, B, C$, we pursue one of two strategies. If the graph contains a triangle, we consider a largest complete subgraph $K$, which thus contains at least three vertices. Since the graph itself is not complete, there is a vertex $C$ not in $K$ connected to a vertex $A$ of $K$. By maximality of $K$, there is a vertex $B$ of $K$ not connected to $C$, and hence we are done by choosing a cycle $Z$ in $K$ through the edge $A B$. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-043.jpg?height=380&width=498&top_left_y=1586&top_left_x=776)  If the graph is triangle-free, we consider instead a smallest cycle $Z$. This cycle cannot be Hamiltonian (i.e. it cannot pass through every vertex of the graph), since otherwise by minimality the graph would then have no other edges, and hence would have even degree at every vertex. We may thus choose a vertex $C$ not in $Z$ adjacent to a vertex $A$ of $Z$. Since the graph is triangle-free, it is not adjacent to any neighbour $B$ of $A$ in $Z$, and we are done.  Step 2: Any tree may be reduced to a disjoint union of single edges and vertices by a sequence of refriendings. Proof. The refriending preserves the property of being acyclic. Hence, after applying a sequence of refriendings, we arrive at an acyclic graph in which it is impossible to perform any further refriendings. The maximal degree of any such graph is 1 : if it had a vertex $A$ with two neighbours $B, C$, then $B$ and $C$ would necessarily be nonadjacent since the graph is cycle-free, and so a refriending would be possible. Thus we reach a graph with maximal degree at most 1 as desired.


Let $n>1$ be an integer. Suppose we are given $2 n$ points in a plane such that no three of them are collinear. The points are to be labelled $A_{1}, A_{2}, \ldots, A_{2 n}$ in some order. We then consider the $2 n$ angles $\angle A_{1} A_{2} A_{3}, \angle A_{2} A_{3} A_{4}, \ldots, \angle A_{2 n-2} A_{2 n-1} A_{2 n}, \angle A_{2 n-1} A_{2 n} A_{1}$, $\angle A_{2 n} A_{1} A_{2}$. We measure each angle in the way that gives the smallest positive value (i.e. between $0^{\circ}$ and $180^{\circ}$ ). Prove that there exists an ordering of the given points such that the resulting $2 n$ angles can be separated into two groups with the sum of one group of angles equal to the sum of the other group.

Solution: Let $\ell$ be a line separating the points into two groups ( $L$ and $R$ ) with $n$ points in each. Label the points $A_{1}, A_{2}, \ldots, A_{2 n}$ so that $L=\left\{A_{1}, A_{3}, \ldots, A_{2 n-1}\right\}$. We claim that this labelling works.  Take a line $s=A_{2 n} A_{1}$. (a) Rotate $s$ around $A_{1}$ until it passes through $A_{2}$; the rotation is performed in a direction such that $s$ is never parallel to $\ell$. (b) Then rotate the new $s$ around $A_{2}$ until it passes through $A_{3}$ in a similar manner. (c) Perform $2 n-2$ more such steps, after which $s$ returns to its initial position.  The total (directed) rotation angle $\Theta$ of $s$ is clearly a multiple of $180^{\circ}$. On the other hand, $s$ was never parallel to $\ell$, which is possible only if $\Theta=0$. Now it remains to partition all the $2 n$ angles into those where $s$ is rotated anticlockwise, and the others.


Solution: When tracing a cyclic path through the $A_{i}$ in order, with straight line segments between consecutive points, let $\theta_{i}$ be the exterior angle at $A_{i}$, with a sign convention that it is positive if the path turns left and negative if the path turns right. Then $\sum_{i=1}^{2 n} \theta_{i}=360 k^{\circ}$ for some integer $k$. Let $\phi_{i}=\angle A_{i-1} A_{i} A_{i+1}($ indices $\bmod 2 n)$, defined as in the problem; thus $\phi_{i}=180^{\circ}-\left|\theta_{i}\right|$.  Let $L$ be the set of $i$ for which the path turns left at $A_{i}$ and let $R$ be the set for which it turns right. Then $S=\sum_{i \in L} \phi_{i}-\sum_{i \in R} \phi_{i}=(180(|L|-|R|)-360 k)^{\circ}$, which is a multiple of $360^{\circ}$ since the number of points is even. We will show that the points can be labelled such that $S=0$, in which case $L$ and $R$ satisfy the required condition of the problem.  Note that the value of $S$ is defined for a slightly larger class of configurations: it is OK for two points to coincide, as long as they are not consecutive, and OK for three points to be collinear, as long as $A_{i}, A_{i+1}$ and $A_{i+2}$ do not appear on a line in that order. In what follows it will be convenient, although not strictly necessary, to consider such configurations.  Consider how $S$ changes if a single one of the $A_{i}$ is moved along some straight-line path (not passing through any $A_{j}$ and not lying on any line $A_{j} A_{k}$, but possibly crossing such lines). Because $S$ is a multiple of $360^{\circ}$, and the angles change continuously, $S$ can only change when a point moves between $R$ and $L$. Furthermore, if $\phi_{j}=0$ when $A_{j}$ moves between $R$ and $L, S$ is unchanged; it only changes if $\phi_{j}=180^{\circ}$ when $A_{j}$ moves between those sets.  For any starting choice of points, we will now construct a new configuration, with labels such that $S=0$, that can be perturbed into the original one without any $\phi_{i}$ passing through $180^{\circ}$, so that $S=0$ for the original configuration with those labels as well.  Take some line such that there are $n$ points on each side of that line. The new configuration has $n$ copies of a single point on each side of the line, and a path that alternates between sides of the line; all angles are 0 , so this configuration has $S=0$. Perturbing the points into their original positions, while keeping each point on its side of the line, no angle $\phi_{i}$ can pass through $180^{\circ}$, because no straight line can go from one side of the line to the other and back. So the perturbation process leaves $S=0$.  Comment. More complicated variants of this solution are also possible; for example, a path defined using four quadrants of the plane rather than just two half-planes.


Solution: First, let $\ell$ be a line in the plane such that there are $n$ points on one side and the other $n$ points on the other side. For convenience, assume $\ell$ is horizontal (otherwise, we can rotate the plane). Then we can use the terms "above", "below", "left" and "right" in the usual way. We denote the $n$ points above the line in an arbitrary order as $P_{1}, P_{2}, \ldots, P_{n}$, and the $n$ points below the line as $Q_{1}, Q_{2}, \ldots, Q_{n}$.  If we connect $P_{i}$ and $Q_{j}$ with a line segment, the line segment will intersect with the line $\ell$. Denote the intersection as $I_{i j}$. If $P_{i}$ is connected to $Q_{j}$ and $Q_{k}$, where $j<k$, then $I_{i j}$ and $I_{i k}$ are two different points, because $P_{i}, Q_{j}$ and $Q_{k}$ are not collinear.  Now we define a "sign" for each angle $\angle Q_{j} P_{i} Q_{k}$. Assume $j<k$. We specify that the sign is positive for the following two cases:  - if $i$ is odd and $I_{i j}$ is to the left of $I_{i k}$, - if $i$ is even and $I_{i j}$ is to the right of $I_{i k}$.  Otherwise the sign of the angle is negative. If $j>k$, then the sign of $\angle Q_{j} P_{i} Q_{k}$ is taken to be the same as for $\angle Q_{k} P_{i} Q_{j}$.  Similarly, we can define the sign of $\angle P_{j} Q_{i} P_{k}$ with $j<k$ (or equivalently $\angle P_{k} Q_{i} P_{j}$ ). For example, it is positive when $i$ is odd and $I_{j i}$ is to the left of $I_{k i}$.  Henceforth, whenever we use the notation $\angle Q_{j} P_{i} Q_{k}$ or $\angle P_{j} Q_{i} P_{k}$ for a numerical quantity, it is understood to denote either the (geometric) measure of the angle or the negative of this measure, depending on the sign as specified above.  We now have the following important fact for signed angle measures:  $$ \angle Q_{i_{1}} P_{k} Q_{i_{3}}=\angle Q_{i_{1}} P_{k} Q_{i_{2}}+\angle Q_{i_{2}} P_{k} Q_{i_{3}} $$  for all points $P_{k}, Q_{i_{1}}, Q_{i_{2}}$ and $Q_{i_{3}}$ with $i_{1}<i_{2}<i_{3}$. The following figure shows a "natural" arrangement of the points. Equation (1) still holds for any other arrangement, as can be easily verified. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-045.jpg?height=346&width=806&top_left_y=2163&top_left_x=631)  Similarly, we have  $$ \angle P_{i_{1}} Q_{k} P_{i_{3}}=\angle P_{i_{1}} Q_{k} P_{i_{2}}+\angle P_{i_{2}} Q_{k} P_{i_{3}}, $$  for all points $Q_{k}, P_{i_{1}}, P_{i_{2}}$ and $P_{i_{3}}$, with $i_{1}<i_{2}<i_{3}$.  We are now ready to specify the desired ordering $A_{1}, \ldots, A_{2 n}$ of the points:  - if $i \leqslant n$ is odd, put $A_{i}=P_{i}$ and $A_{2 n+1-i}=Q_{i}$; - if $i \leqslant n$ is even, put $A_{i}=Q_{i}$ and $A_{2 n+1-i}=P_{i}$.  For example, for $n=3$ this ordering is $P_{1}, Q_{2}, P_{3}, Q_{3}, P_{2}, Q_{1}$. This sequence alternates between $P$ 's and $Q$ 's, so the above conventions specify a sign for each of the angles $A_{i-1} A_{i} A_{i+1}$. We claim that the sum of these $2 n$ signed angles equals 0 . If we can show this, it would complete the proof.  We prove the claim by induction. For brevity, we use the notation $\angle P_{i}$ to denote whichever of the $2 n$ angles has its vertex at $P_{i}$, and $\angle Q_{i}$ similarly.  First let $n=2$. If the four points can be arranged to form a convex quadrilateral, then the four line segments $P_{1} Q_{1}, P_{1} Q_{2}, P_{2} Q_{1}$ and $P_{2} Q_{2}$ constitute a self-intersecting quadrilateral. We use several figures to illustrate the possible cases.  The following figure is one possible arrangement of the points. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-046.jpg?height=435&width=803&top_left_y=1047&top_left_x=632)  Then $\angle P_{1}$ and $\angle Q_{1}$ are positive, $\angle P_{2}$ and $\angle Q_{2}$ are negative, and we have  $$ \left|\angle P_{1}\right|+\left|\angle Q_{1}\right|=\left|\angle P_{2}\right|+\left|\angle Q_{2}\right| . $$  With signed measures, we have  $$ \angle P_{1}+\angle Q_{1}+\angle P_{2}+\angle Q_{2}=0 $$  If we switch the labels of $P_{1}$ and $P_{2}$, we have the following picture: ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-046.jpg?height=438&width=809&top_left_y=2031&top_left_x=629)  Switching labels $P_{1}$ and $P_{2}$ has the effect of flipping the sign of all four angles (as well as swapping the magnitudes on the relabelled points); that is, the new values of ( $\angle P_{1}, \angle P_{2}, \angle Q_{1}, \angle Q_{2}$ ) equal the old values of ( $-\angle P_{2},-\angle P_{1},-\angle Q_{1},-\angle Q_{2}$ ). Consequently, equation (3) still holds. Similarly, when switching the labels of $Q_{1}$ and $Q_{2}$, or both the $P$ 's and the $Q$ 's, equation (3) still holds.  The remaining subcase of $n=2$ is that one point lies inside the triangle formed by the other three. We have the following picture. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-047.jpg?height=495&width=820&top_left_y=358&top_left_x=615)  We have  $$ \left|\angle P_{1}\right|+\left|\angle Q_{1}\right|+\left|\angle Q_{2}\right|=\left|\angle P_{2}\right| . $$  and equation (3) holds. Again, switching the labels for $P$ 's or the $Q$ 's will not affect the validity of equation (3). Also, if the point lying inside the triangle of the other three is one of the $Q$ 's rather than the $P$ 's, the result still holds, since our sign convention is preserved when we relabel $Q$ 's as $P$ 's and vice-versa and reflect across $\ell$.  We have completed the proof of the claim for $n=2$. Assume the claim holds for $n=k$, and we wish to prove it for $n=k+1$. Suppose we are given our $2(k+1)$ points. First ignore $P_{k+1}$ and $Q_{k+1}$, and form $2 k$ angles from $P_{1}, \ldots, P_{k}$, $Q_{1}, \ldots, Q_{k}$ as in the $n=k$ case. By the induction hypothesis we have  $$ \sum_{i=1}^{k}\left(\angle P_{i}+\angle Q_{i}\right)=0 $$  When we add in the two points $P_{k+1}$ and $Q_{k+1}$, this changes our angles as follows:  - the angle at $P_{k}$ changes from $\angle Q_{k-1} P_{k} Q_{k}$ to $\angle Q_{k-1} P_{k} Q_{k+1}$; - the angle at $Q_{k}$ changes from $\angle P_{k-1} Q_{k} P_{k}$ to $\angle P_{k-1} Q_{k} P_{k+1}$; - two new angles $\angle Q_{k} P_{k+1} Q_{k+1}$ and $\angle P_{k} Q_{k+1} P_{k+1}$ are added.  We need to prove the changes have no impact on the total sum. In other words, we need to prove  $$ \left(\angle Q_{k-1} P_{k} Q_{k+1}-\angle Q_{k-1} P_{k} Q_{k}\right)+\left(\angle P_{k-1} Q_{k} P_{k+1}-\angle P_{k-1} Q_{k} P_{k}\right)+\left(\angle P_{k+1}+\angle Q_{k+1}\right)=0 $$  In fact, from equations (1) and (2), we have  $$ \angle Q_{k-1} P_{k} Q_{k+1}-\angle Q_{k-1} P_{k} Q_{k}=\angle Q_{k} P_{k} Q_{k+1} $$  and  $$ \angle P_{k-1} Q_{k} P_{k+1}-\angle P_{k-1} Q_{k} P_{k}=\angle P_{k} Q_{k} P_{k+1} $$  Therefore, the left hand side of equation (4) becomes $\angle Q_{k} P_{k} Q_{k+1}+\angle P_{k} Q_{k} P_{k+1}+\angle Q_{k} P_{k+1} Q_{k+1}+$ $\angle P_{k} Q_{k+1} P_{k+1}$, which equals 0 , simply by applying the $n=2$ case of the claim. This completes the induction.


Solution: We shall think instead of the problem as asking us to assign a weight $\pm 1$ to each angle, such that the weighted sum of all the angles is zero.  Given an ordering $A_{1}, \ldots, A_{2 n}$ of the points, we shall assign weights according to the following recipe: walk in order from point to point, and assign the left turns +1 and the right turns -1 . This is the same weighting as in Solution 3, and as in that solution, the weighted sum is a multiple of $360^{\circ}$.  We now aim to show the following: Lemma. Transposing any two consecutive points in the ordering changes the weighted sum by $\pm 360^{\circ}$ or 0 .  Knowing that, we can conclude quickly: if the ordering $A_{1}, \ldots, A_{2 n}$ has weighted angle sum $360 k^{\circ}$, then the ordering $A_{2 n}, \ldots, A_{1}$ has weighted angle sum $-360 k^{\circ}$ (since the angles are the same, but left turns and right turns are exchanged). We can reverse the ordering of $A_{1}$, $\ldots, A_{2 n}$ by a sequence of transpositions of consecutive points, and in doing so the weighted angle sum must become zero somewhere along the way.  We now prove that lemma: Proof. Transposing two points amounts to taking a section $A_{k} A_{k+1} A_{k+2} A_{k+3}$ as depicted, reversing the central line segment $A_{k+1} A_{k+2}$, and replacing its two neighbours with the dotted lines. ![](https://cdn.mathpix.com/cropped/2024_11_18_9ee8c2ac2c2f5002ff14g-048.jpg?height=424&width=1357&top_left_y=1156&top_left_x=354)  Figure 1: Transposing two consecutive vertices: before (left) and afterwards (right) In each triangle, we alter the sum by $\pm 180^{\circ}$. Indeed, using (anticlockwise) directed angles modulo $360^{\circ}$, we either add or subtract all three angles of each triangle.  Hence both triangles together alter the sum by $\pm 180 \pm 180^{\circ}$, which is $\pm 360^{\circ}$ or 0 .


There are 60 empty boxes $B_{1}, \ldots, B_{60}$ in a row on a table and an unlimited supply of pebbles. Given a positive integer $n$, Alice and Bob play the following game.  In the first round, Alice takes $n$ pebbles and distributes them into the 60 boxes as she wishes. Each subsequent round consists of two steps: (a) Bob chooses an integer $k$ with $1 \leqslant k \leqslant 59$ and splits the boxes into the two groups $B_{1}, \ldots, B_{k}$ and $B_{k+1}, \ldots, B_{60}$. (b) Alice picks one of these two groups, adds one pebble to each box in that group, and removes one pebble from each box in the other group.  Bob wins if, at the end of any round, some box contains no pebbles. Find the smallest $n$ such that Alice can prevent Bob from winning. (Czech Republic)


Alice has a map of Wonderland, a country consisting of $n \geqslant 2$ towns. For every pair of towns, there is a narrow road going from one town to the other. One day, all the roads are declared to be "one way" only. Alice has no information on the direction of the roads, but the King of Hearts has offered to help her. She is allowed to ask him a number of questions. For each question in turn, Alice chooses a pair of towns and the King of Hearts tells her the direction of the road connecting those two towns.  Alice wants to know whether there is at least one town in Wonderland with at most one outgoing road. Prove that she can always find out by asking at most $4 n$ questions.  Comment. This problem could be posed with an explicit statement about points being awarded for weaker bounds $c n$ for some $c>4$, in the style of IMO 2014 Problem 6. (Thailand)

Solution: We will show Alice needs to ask at most $4 n-7$ questions. Her strategy has the following phases. In what follows, $S$ is the set of towns that Alice, so far, does not know to have more than one outgoing road (so initially $|S|=n$ ).  Phase 1. Alice chooses any two towns, say $A$ and $B$. Without loss of generality, suppose that the King of Hearts' answer is that the road goes from $A$ to $B$.  At the end of this phase, Alice has asked 1 question. Phase 2. During this phase there is a single (variable) town $T$ that is known to have at least one incoming road but not yet known to have any outgoing roads. Initially, $T$ is $B$. Alice does the following $n-2$ times: she picks a town $X$ she has not asked about before, and asks the direction of the road between $T$ and $X$. If it is from $X$ to $T, T$ is unchanged; if it is from $T$ to $X, X$ becomes the new choice of town $T$, as the previous $T$ is now known to have an outgoing road.  At the end of this phase, Alice has asked a total of $n-1$ questions. The final town $T$ is not yet known to have any outgoing roads, while every other town has exactly one outgoing road known. The undirected graph of roads whose directions are known is a tree.  Phase 3. During this phase, Alice asks about the directions of all roads between $T$ and another town she has not previously asked about, stopping if she finds two outgoing roads from $T$. This phase involves at most $n-2$ questions. If she does not find two outgoing roads from $T$, she has answered her original question with at most $2 n-3 \leqslant 4 n-7$ questions, so in what follows we suppose that she does find two outgoing roads, asking a total of $k$ questions in this phase, where $2 \leqslant k \leqslant n-2$ (and thus $n \geqslant 4$ for what follows).  For every question where the road goes towards $T$, the town at the other end is removed from $S$ (as it already had one outgoing road known), while the last question resulted in $T$ being removed from $S$. So at the end of this phase, $|S|=n-k+1$, while a total of $n+k-1$ questions have been asked. Furthermore, the undirected graph of roads within $S$ whose directions are known contains no cycles (as $T$ is no longer a member of $S$, all questions asked in this phase involved $T$ and the graph was a tree before this phase started). Every town in $S$ has exactly one outgoing road known (not necessarily to another town in $S$ ).  Phase 4. During this phase, Alice repeatedly picks any pair of towns in $S$ for which she does not know the direction of the road between them. Because every town in $S$ has exactly one outgoing road known, this always results in the removal of one of those two towns from $S$. Because there are no cycles in the graph of roads of known direction within $S$, this can continue until there are at most 2 towns left in $S$.  If it ends with $t$ towns left, $n-k+1-t$ questions were asked in this phase, so a total of $2 n-t$ questions have been asked.  Phase 5. During this phase, Alice asks about all the roads from the remaining towns in $S$ that she has not previously asked about. She has definitely already asked about any road between those towns (if $t=2$ ). She must also have asked in one of the first two phases about at least one other road involving one of those towns (as those phases resulted in a tree with $n>2$ vertices). So she asks at most $t(n-t)-1$ questions in this phase.  At the end of this phase, Alice knows whether any town has at most one outgoing road. If $t=1$, at most $3 n-3 \leqslant 4 n-7$ questions were needed in total, while if $t=2$, at most $4 n-7$ questions were needed in total.  Comment 1. The version of this problem originally submitted asked only for an upper bound of $5 n$, which is much simpler to prove. The Problem Selection Committee preferred a version with an asymptotically optimal constant. In the following comment, we will show that the constant is optimal.  Comment 2. We will show that Alice cannot always find out by asking at most $4 n-3\left(\log _{2} n\right)-$ 15 questions, if $n \geqslant 8$.  To show this, we suppose the King of Hearts is choosing the directions as he goes along, only picking the direction of a road when Alice asks about it for the first time. We provide a strategy for the King of Hearts that ensures that, after the given number of questions, the map is still consistent both with the existence of a town with at most one outgoing road, and with the nonexistence of such a town. His strategy has the following phases. When describing how the King of Hearts' answer to a question is determined below, we always assume he is being asked about a road for the first time (otherwise, he just repeats his previous answer for that road). This strategy is described throughout in graph-theoretic terms (vertices and edges rather than towns and roads).  Phase 1. In this phase, we consider the undirected graph formed by edges whose directions are known. The phase terminates when there are exactly 8 connected components whose undirected graphs are trees. The following invariant is maintained: in a component with $k$ vertices whose undirected graph is a tree, every vertex has at most $\left[\log _{2} k\right\rfloor$ edges into it.  - If the King of Hearts is asked about an edge between two vertices in the same component, or about an edge between two components at least one of which is not a tree, he chooses any direction for that edge arbitrarily. - If he is asked about an edge between a vertex in component $A$ that has $a$ vertices and is a tree and a vertex in component $B$ that has $b$ vertices and is a tree, suppose without loss of generality that $a \geqslant b$. He then chooses the edge to go from $A$ to $B$. In this case, the new number of edges into any vertex is at most $\max \left\{\left\lfloor\log _{2} a\right\rfloor,\left\lfloor\log _{2} b\right\rfloor+1\right\} \leqslant\left\lfloor\log _{2}(a+b)\right\rfloor$.  In all cases, the invariant is preserved, and the number of tree components either remains unchanged or goes down by 1. Assuming Alice does not repeat questions, the process must eventually terminate with 8 tree components, and at least $n-8$ questions having been asked.  Note that each tree component contains at least one vertex with no outgoing edges. Colour one such vertex in each tree component red.  Phase 2. Let $V_{1}, V_{2}$ and $V_{3}$ be the three of the red vertices whose components are smallest (so their components together have at most $\left\lfloor\frac{3}{8} n\right\rfloor$ vertices, with each component having at most $\left\lfloor\frac{3}{8} n-2\right\rfloor$ vertices). Let sets $C_{1}, C_{2}, \ldots$ be the connected components after removing the $V_{j}$. By construction, there are no edges with known direction between $C_{i}$ and $C_{j}$ for $i \neq j$, and there are at least five such components.  If at any point during this phase, the King of Hearts is asked about an edge within one of the $C_{i}$, he chooses an arbitrary direction. If he is asked about an edge between $C_{i}$ and $C_{j}$ for $i \neq j$, he answers so that all edges go from $C_{i}$ to $C_{i+1}$ and $C_{i+2}$, with indices taken modulo the number of components, and chooses arbitrarily for other pairs. This ensures that all vertices other than the $V_{j}$ will have more than one outgoing edge.  For edges involving one of the $V_{j}$ he answers as follows, so as to remain consistent for as long as possible with both possibilities for whether one of those vertices has at most one outgoing edge. Note that as they were red vertices, they have no outgoing edges at the start of this phase. For edges between two of the $V_{j}$, he answers that the edges go from $V_{1}$ to $V_{2}$, from $V_{2}$ to $V_{3}$ and from $V_{3}$ to $V_{1}$. For edges between $V_{j}$ and some other vertex, he always answers that the edge goes into $V_{j}$, except for the last such edge for which he is asked the question for any given $V_{j}$, for which he answers that the edge goes out of $V_{j}$. Thus, as long as at least one of the $V_{j}$ has not had the question answered for all the vertices that are not among the $V_{j}$, his answers are still compatible both with all vertices having more than one outgoing edge, and with that $V_{j}$ having only one outgoing edge.  At the start of this phase, each of the $V_{j}$ has at most $\left\lfloor\log _{2}\left\lfloor\frac{3}{8} n-2\right\rfloor\right\rfloor<\left(\log _{2} n\right)-1$ incoming edges. Thus, Alice cannot determine whether some vertex has only one outgoing edge within $3(n-$ $\left.3-\left(\left(\log _{2} n\right)-1\right)\right)-1$ questions in this phase; that is, $4 n-3\left(\log _{2} n\right)-15$ questions total.  Comment 3. We can also improve the upper bound slightly, to $4 n-2\left(\log _{2} n\right)+1$. (We do not know where the precise minimum number of questions lies between $4 n-3\left(\log _{2} n\right)+O(1)$ and $4 n-2\left(\log _{2} n\right)+$ $O(1)$.) Suppose $n \geqslant 5$ (otherwise no questions are required at all).  To do this, we replace Phases 1 and 2 of the given solution with a different strategy that also results in a spanning tree where one vertex $V$ is not known to have any outgoing edges, and all other vertices have exactly one outgoing edge known, but where there is more control over the numbers of incoming edges. In Phases 3 and 4 we then take more care about the order in which pairs of towns are chosen, to ensure that each of the remaining towns has already had a question asked about at least $\log _{2} n+O(1)$ edges.  Define trees $T_{m}$ with $2^{m}$ vertices, exactly one of which (the root) has no outgoing edges and the rest of which have exactly one outgoing edge, as follows: $T_{0}$ is a single vertex, while $T_{m}$ is constructed by joining the roots of two copies of $T_{m-1}$ with an edge in either direction. If $n=2^{m}$ we can readily ask $n-1$ questions, resulting in a tree $T_{m}$ for the edges with known direction: first ask about $2^{m-1}$ disjoint pairs of vertices, then about $2^{m-2}$ disjoint pairs of the roots of the resulting $T_{1}$ trees, and so on. For the general case, where $n$ is not a power of 2 , after $k$ stages of this process we have $\left\lfloor n / 2^{k}\right\rfloor$ trees, each of which is like $T_{k}$ but may have some extra vertices (but, however, a unique root). If there are an even number of trees, then ask about pairs of their roots. If there are an odd number (greater than 1) of trees, when a single $T_{k}$ is left over, ask about its root together with that of one of the $T_{k+1}$ trees.  Say $m=\left\lfloor\log _{2} n\right\rfloor$. The result of that process is a single $T_{m}$ tree, possibly with some extra vertices but still a unique root $V$. That root has at least $m$ incoming edges, and we may list vertices $V_{0}$, $\ldots, V_{m-1}$ with edges to $V$, such that, for all $0 \leqslant i<m$, vertex $V_{i}$ itself has at least $i$ incoming edges.  Now divide the vertices other than $V$ into two parts: $A$ has all vertices at an odd distance from $V$ and $B$ has all the vertices at an even distance from $B$. Both $A$ and $B$ are nonempty; $A$ contains the $V_{i}$, while $B$ contains a sequence of vertices with at least $0,1, \ldots, m-2$ incoming edges respectively, similar to the $V_{i}$. There are no edges with known direction within $A$ or within $B$.  In Phase 3, then ask about edges between $V$ and other vertices: first those in $B$, in order of increasing number of incoming edges to the other vertex, then those in $A$, again in order of increasing number of incoming edges, which involves asking at most $n-1-m$ questions in this phase. If two outgoing edges are not found from $V$, at most $2 n-2-m \leqslant 4 n-2\left(\log _{2} n\right)+1$ questions needed to be asked in total, so we suppose that two outgoing edges were found, with $k$ questions asked in this phase, where $2 \leqslant k \leqslant n-1-m$. The state of $S$ is as described in the solution above, with the additional property that, since $S$ must still contain all vertices with edges to $V$, it contains the vertices $V_{i}$ described above.  In Phase 4, consider the vertices left in $B$, in increasing order of number of edges incoming to a vertex. If $s$ is the least number of incoming edges to such a vertex, then, for any $s \leqslant t \leqslant m-2$, there are at least $m-t-2$ vertices with more than $t$ incoming edges. Repeatedly asking about the pair of vertices left in $B$ with the least numbers of incoming edges results in a single vertex left over (if any were in $B$ at all at the start of this phase) with at least $m-2$ incoming edges. Doing the same with $A$ (which must be nonempty) leaves a vertex with at least $m-1$ incoming edges.  Thus if only $A$ is nonempty we ask at most $n-m$ questions in Phase 5 , so in total at most $3 n-m-1$ questions, while if both are nonempty we ask at most $2 n-2 m+1$ questions in Phase 5 , so in total at most $4 n-2 m-1<4 n-2\left(\log _{2} n\right)+1$ questions.  This page is intentionally left blank