# INMO 2021 ## Official Solutions Problem 1. Suppose $r \geq 2$ is an integer, and let $m_{1}, n_{1}, m_{2}, n_{2}, \cdots, m_{r}, n_{r}$ be $2 r$ integers such that $$ \left|m_{i} n_{j}-m_{j} n_{i}\right|=1 $$ for any two integers $i$ and $j$ satisfying $1 \leq i3$. We observe that: $$ \begin{aligned} & m_{1} n_{2} n_{3}-m_{2} n_{1} n_{3}= \pm n_{3} \\ & m_{2} n_{3} n_{1}-m_{3} n_{2} n_{1}= \pm n_{1} \\ & m_{3} n_{1} n_{2}-m_{1} n_{3} n_{2}= \pm n_{2} \end{aligned} $$ Adding, we get $\pm n_{1} \pm n_{2} \pm n_{3}=0$; which forces at least one of $n_{1}, n_{2}, n_{3}$ to be even; WLOG let $n_{1}$ be even. Repeating the argument for indices $2,3,4$, we deduce that at least one of $n_{2}, n_{3}, n_{4}$ is even; WLOG let $n_{2}$ be even. This leads to a contradiction, since $\left|m_{1} n_{2}-m_{2} n_{1}\right|=1$ cannot be even. Hence $r>3$ is not possible, as claimed. Problem 2. Find all pairs of integers $(a, b)$ so that each of the two cubic polynomials $$ x^{3}+a x+b \text { and } x^{3}+b x+a $$ has all the roots to be integers. Solution. The only such pair is $(0,0)$, which clearly works. To prove this is the only one, let us prove an auxiliary result first. Lemma If $\alpha, \beta, \gamma$ are reals so that $\alpha+\beta+\gamma=0$ and $|\alpha|,|\beta|,|\gamma| \geq 2$, then $$ |\alpha \beta+\beta \gamma+\gamma \alpha|<|\alpha \beta \gamma| $$ Proof. Some two of these reals have the same sign; WLOG, suppose $\alpha \beta>0$. Then $\gamma=$ $-(\alpha+\beta)$, so by substituting this, $$ |\alpha \beta+\beta \gamma+\gamma \alpha|=\left|\alpha^{2}+\beta^{2}+\alpha \beta\right|,|\alpha \beta \gamma|=|\alpha \beta(\alpha+\beta)| $$ So we simply need to show $|\alpha \beta(\alpha+\beta)|>\left|\alpha^{2}+\beta^{2}+\alpha \beta\right|$. Since $|\alpha| \geq 2$ and $|\beta| \geq 2$, we have $$ \begin{aligned} & |\alpha \beta(\alpha+\beta)|=|\alpha||\beta(\alpha+\beta)| \geq 2|\beta(\alpha+\beta)| \\ & |\alpha \beta(\alpha+\beta)|=|\beta||\alpha(\alpha+\beta)| \geq 2|\alpha(\alpha+\beta)| . \end{aligned} $$ Adding these and using triangle inequality, $$ \begin{aligned} 2|\alpha \beta(\alpha+\beta)| & \geq 2|\beta(\alpha+\beta)|+2|\alpha(\alpha+\beta)| \geq 2|\beta(\alpha+\beta)+\alpha(\alpha+\beta)| \\ & \geq 2\left(\alpha^{2}+\beta^{2}+2 \alpha \beta\right)>2\left(\alpha^{2}+\beta^{2}+\alpha \beta\right) \\ & =2\left|\alpha^{2}+\beta^{2}+\alpha \beta\right| \end{aligned} $$ Here we have used the fact that $\alpha^{2}+\beta^{2}+2 \alpha \beta=(\alpha+\beta)^{2}$ and $\alpha^{2}+\beta^{2}+\alpha \beta=\left(\alpha+\frac{\beta}{2}\right)^{2}+\frac{3 \beta^{2}}{4}$ are both nonnegative. This proves our claim. For our main problem, suppose the roots of $x^{3}+a x+b$ are the integers $r_{1}, r_{2}, r_{3}$ and the roots of $x^{3}+b x+a$ are the integers $s_{1}, s_{2}, s_{3}$. By Vieta's relations, we have $$ \begin{gathered} r_{1}+r_{2}+r_{3}=0=s_{1}+s_{2}+s_{3} \\ r_{1} r_{2}+r_{2} r_{3}+r_{3} r_{1}=a=-s_{1} s_{2} s_{3} \\ s_{1} s_{2}+s_{2} s_{3}+s_{3} s_{1}=b=-r_{1} r_{2} r_{3} \end{gathered} $$ If all six of these roots had an absolute value of at least 2 , by our lemma, we would have $$ |b|=\left|s_{1} s_{2}+s_{2} s_{3}+s_{3} s_{1}\right|<\left|s_{1} s_{2} s_{3}\right|=\left|r_{1} r_{2}+r_{2} r_{3}+r_{3} r_{1}\right|<\left|r_{1} r_{2} r_{3}\right|=|b| $$ which is absurd. Thus at least one of them is in the set $\{0,1,-1\}$; WLOG, suppose it's $r_{1}$. 1. If $r_{1}=0$, then $r_{2}=-r_{3}$, so $b=0$. Then the roots of $x^{3}+b x+a=x^{3}+a$ are precisely the cube roots of $-a$, and these are all real only for $a=0$. Thus $(a, b)=(0,0)$, which is a solution. 2. If $r_{1}= \pm 1$, then $\pm 1 \pm a+b=0$, so $a$ and $b$ can't both be even. If $a=-s_{1} s_{2} s_{3}$ is odd, then $s_{1}, s_{2}, s_{3}$ are all odd, so $s_{1}+s_{2}+s_{3}$ cannot be zero. Similarly, if $b$ is odd, we get a contradiction. The proof is now complete. Alternate Solution. The only such pair is $(0,0)$, which clearly works. Let us prove this is the only one. In what follows, we use $\nu_{2}(n)$ to denote the largest integer $k$ so that $2^{k} \mid n$ for any non-zero $n \in \mathbb{Z}$. If one of the cubics has 0 as a root, say the first one, then $0^{3}+0 \cdot a+b=0$, so $b=0$. Then the roots of $x^{3}+b x+a=x^{3}+a$ are precisely the cube roots of $-a$, and these are all real only for $a=0$. Thus $(a, b)=(0,0)$. So suppose none of the roots are zero. Take the cubic $x^{3}+a x+b$, and suppose its roots are $x, y, z$. We cannot have $\nu_{2}(x)=\nu_{2}(y)=\nu_{2}(z)$; indeed, if we had $x=2^{k} x_{1}, y=2^{k} y_{1}, z=$ $2^{k} z_{1}$ for odd $x_{1}, y_{1}, z_{1}$, then $$ 0=x+y+z=2^{k}\left(x_{1}+y_{1}+z_{1}\right) $$ But $x_{1}+y_{1}+z_{1}$ is odd, and hence non-zero, so this cannot happen. Thus we can assume WLOG that $\nu_{2}(x)>\nu_{2}(y)$. Then the third root is $-(x+y)$. Similarly, the three roots of $x^{3}+b x+a$ can be written as $p, q,-(p+q)$ where $\nu_{2}(p)>\nu_{2}(q)$. By Vieta's relations, $$ \begin{gathered} x y-x(x+y)-y(x+y)=-\left(x^{2}+x y+y^{2}\right)=a=p q(p+q) \\ p q-p(p+q)-q(p+q)=-\left(p^{2}+p q+q^{2}\right)=b=x y(x+y) \end{gathered} $$ Suppose $x=2^{k} x_{1}$ and $y=2^{\ell} y_{1}$ for odd $x_{1}, y_{1}$ and $k>\ell$; in particular $k>0$. Then $$ x y(x+y)=2^{k} x_{1} \cdot 2^{\ell} y_{1} \cdot\left(2^{k} x_{1}+2^{\ell} y_{1}\right)=2^{k+2 \ell} x_{1} y_{1}\left(2^{k-\ell} x_{1}+y_{1}\right) $$ Here $x_{1} y_{1}\left(2^{k-\ell} x_{1}+y_{1}\right)$ is clearly odd, so $\nu_{2}(x y(x+y))=k+2 \ell$. Also, $$ x^{2}+x y+y^{2}=2^{2 k} x_{1}^{2}+2^{k} x_{1} \cdot 2^{\ell} y_{1}+2^{2 \ell} y_{1}^{2}=2^{2 \ell}\left(2^{2 k-2 \ell} x_{1}^{2}+2^{k-\ell} x_{1} y_{1}+y_{1}^{2}\right) $$ Again, all the terms in the second factor are even except $y_{1}^{2}$, so the entire factor is odd. This means $\nu_{2}\left(x^{2}+x y+y^{2}\right)=2 \ell$. Therefore $$ \nu_{2}(x y(x+y))>\nu_{2}\left(x^{2}+x y+y^{2}\right) $$ Similarly, one may show $$ \nu_{2}(p q(p+q))>\nu_{2}\left(p^{2}+p q+q^{2}\right) $$ But then $$ \nu_{2}(b)=\nu_{2}(x y(x+y))>\nu_{2}\left(x^{2}+x y+y^{2}\right)=\nu_{2}(p q(p+q))>\nu_{2}\left(p^{2}+p q+q^{2}\right)=\nu_{2}(b) $$ Here we have used the fact that $\nu_{2}(n)=\nu_{2}(-n)$ for any integer $n$. But this is a contradiction, proving our claim. Problem 3. Betal marks 2021 points on the plane such that no three are collinear, and draws all possible line segments joining these. He then chooses any 1011 of these line segments, and marks their midpoints. Finally, he chooses a line segment whose midpoint is not marked yet, and challenges Vikram to construct its midpoint using only a straightedge. Can Vikram always complete this challenge? Note: A straightedge is an infinitely long ruler without markings, which can only be used to draw the line joining any two given distinct points. Solution. The answer is 'yes'. To prove this, we will first prove two lemmas: Lemma 1 Given any two points $A, B$, their midpoint $M$, and any point $C$, Vikram can draw a line parallel to $A B$ through $C$. Proof. If $C$ is on line $A B$ we are already done. If not, extend $B C$ to $X$ as shown, draw $P=A C \cap X M$, and then draw $D=B P \cap A X$. We claim $C D$ is the desired line. Indeed, using Ceva's theorem on triangle $A B X$ and the fact $A M=M B$, we see that $$ \frac{A M}{M B} \cdot \frac{B C}{C X} \cdot \frac{X D}{D A}=1 \Longrightarrow \frac{X C}{C B}=\frac{X D}{D A} $$ This means $C D \| A B$. ![](https://cdn.mathpix.com/cropped/2024_06_05_a0deca6809567aa4b59ag-3.jpg?height=494&width=463&top_left_y=2009&top_left_x=448) Lemma 1 ![](https://cdn.mathpix.com/cropped/2024_06_05_a0deca6809567aa4b59ag-3.jpg?height=537&width=531&top_left_y=1970&top_left_x=1094) Lemma 2 Lemma 2 Given two non-parallel segments $A B, B C$ and their midpoints $M, N$, Vikram can draw the midpoint of any other segment $X Y$. Proof. Assume first $X Y$ is not parallel to $A B$ or $B C$. Using lemma 1, draw lines $\ell_{1}$ and $\ell_{2}$ through $X$ parallel to $A B$ and $B C$ respectively, and similarly draw $m_{1}$ and $m_{2}$ through $Y$ parallel to $A B$ and $B C$ respectively. If we draw $P=\ell_{1} \cap m_{2}$ and $Q=\ell_{2} \cap m_{1}$, then $X P Y Q$ is a parallelogram, so intersecting $P Q$ and $X Y$ gives the midpoint of $X Y$. As for the remaining case, one can draw $A C$ and construct the midpoint $P$ of $A C$ by the construction described above. Since $X Y$ can be parallel to at most one of the sides $A B, B C$ and $A C$, we can pick the two non-parallel sides, and use the above construction to draw the midpoint of $X Y$. Now for the main problem, note that if no two of the 1011 chosen segments share an endpoint, then we have at least $2 \cdot 1011=2022$ distinct endpoints, a contradiction. Thus there must be two segments $A B$ and $B C$ which have their midpoints marked. Since no three of the chosen 2021 points were collinear, $A B$ and $B C$ are not parallel, so using lemma 2, Vikram can construct the midpoint of any other segment, in particular, the segment chosen by Betal. Alternate Solution As in the previous solution, note that there exist $A B$ and $A C$ whose midpoints $C^{\prime}$ and $B^{\prime}$ are marked. Using the straightedge, Vikram can draw the two medians $A C^{\prime}$ and $A B^{\prime}$ and obtain their intersection, the centroid $G$ of $\triangle A B C$. Now intersecting $A G$ with $B C$ gives $A^{\prime}$, the midpoint of $B C$. Lemma Given a point $P$ not on $A B, A C$, Vikram can draw the midpoint of $P A$. Proof. If $P B \| A C$ and $P C \| A B$, then $P B A C$ is a parallelogram, in which case $A^{\prime}$ constructed above is the midpoint of $P A$. Without loss of generality, we may assume $P B \nVdash A C$. ![](https://cdn.mathpix.com/cropped/2024_06_05_a0deca6809567aa4b59ag-4.jpg?height=668&width=991&top_left_y=1299&top_left_x=538) Using the straightedge, one can mark the points $D=P B \cap A C$ and $P B \cap A^{\prime} C^{\prime}=D^{\prime}$. Since $C A \| A^{\prime} C^{\prime}$, we have $$ \frac{B D^{\prime}}{D^{\prime} D}=\frac{B C^{\prime}}{C^{\prime} A}=1 $$ so $D^{\prime}$ is the midpoint of $B D$. Now in $\triangle A B D$, two midpoints $C^{\prime}$ and $D^{\prime}$ are known, so the midpoint of $Q^{\prime}$ of $A D$ can be constructed using the centroid construction outlined before. Let $P^{\prime}=C^{\prime} Q^{\prime} \cap P A$; this exists as $C^{\prime} Q^{\prime} \| B P \nVdash A P$. As before, $C^{\prime} P^{\prime} \| B P$, so $$ \frac{A P^{\prime}}{P^{\prime} P}=\frac{A C^{\prime}}{C^{\prime} B}=1 $$ which means $P^{\prime}$ is the desired midpoint of $P A$. Now suppose we need to find the midpoint of $P Q$. If $P, Q$ are different points from $A$, then one can draw the midpoints of $A P$ and $A Q$ using the lemma. Then by using the centroid of $\triangle A P Q$, one can find the midpoint of $P Q$ as we did for $B C$. If $P$ or $Q$ is $A$, the above lemma immediately yields the required midpoint. Problem 4 A Magician and a Detective play a game. The Magician lays down cards numbered from 1 to 52 face-down on a table. On each move, the Detective can point to two cards and inquire if the numbers on them are consecutive. The Magician replies truthfully. After a finite number of moves the Detective points to two cards. She wins if the numbers on these two cards are consecutive, and loses otherwise. Prove that the Detective can guarantee a win if and only if she is allowed to ask at least 50 questions. Solution. Strategy for the Detective: Pick a card $A$ and compare against all others except one. If he ever gets a "Yes", that pair works; else the remaining card is consecutive with A. This process takes at most 50 queries. Strategy for the Magician: We show that it is not always possible to obtain a "Yes" in 50 turns, hence showing that 49 turns are not enough to figure out a consecutive pair. It is enough to conjure a labelling of cards for which denying all 50 inquiries is valid. Replace 52 by any $N>3$. Think of the cards as vertices of a complete graph $K_{N}$. Delete all edges joining vertices which correspond to pairs of cards the Detective inquired about. We will show that deleting any $N-2$ edges of $K_{N}$ still leaves a graph that admits a path containing all the vertices. Labelling all cards along this path as 1 to $N$ would finish. Several proofs of this claim are possible. We present three of them. ## Proof 1 . For any two vertices $a$ and $b$, since $\operatorname{deg} a+\operatorname{deg} b \geq 2(N-1)-(N-2)=N$, they share a common neighbour. Hence the graph is connected. Pick the longest path $\mathcal{P}: u=u_{0} \rightarrow u_{1} \rightarrow \cdots \rightarrow u_{k}=v$. All neighbours of $u$ and $v$ must remain within the path, else we could get a longer path. Let $u$ have $x$ neighbours $\left\{u_{i_{1}}, u_{i_{2}}, \ldots, u_{i_{x}}\right\}$ with $1=i_{1}2$ so we see that $k \in\{N-2, N-1\}$. Case 1. $k=N-1$. Pick the leftover $w$ outside $\mathcal{C}$. Not all edges from $w$ to the cycle are missing (since only $N-2$ are missing in total), so follow an edge from $w$ to $\mathcal{C}$ and continue along $\mathcal{C}$ to get a path of length $N-1$. Case 2. $k=N-2$. Pick the leftover $a, b$ outside $\mathcal{C}$. It is clear that both of them have edges to the cycle and $a b$ is also an edge (since $k(N-k)=2(N-2)$ in this case). So starting at $a$, going to $b$, to some vertex of $\mathcal{C}$ and following along $\mathcal{C}$ gives us a path of length $N-1$. The proof is complete. Proof 3. The idea is to prove the stronger claim by induction on $N \geq 3$ : a graph on $N$ vertices with $\binom{N-1}{2}+2$ edges has a cycle of length $N$. Deleting the extra edge will give a path of length $N-1$ through all the vertices. The base case $N=3$ is trivial. Suppose it holds for all $k \leq N$, we prove it for $N+1$. Since $\frac{2\left(2+\binom{N}{2}\right)}{N+1}>N-2$ we see that some vertex $v$ has degree either $N-1$ or $N$. Case 1. If degree of $v$ is $N-1$. Then we have an edge $e=u v$ missing among all the edges through $v$. Delete $v$ along with all the edges through it in the graph. The induced graph has a cycle of length $N$. Pick two consecutive vertices that are not $u$, and append $v$ between them. Case 2. If degree of $v$ is $N$. Delete $v$ along with all its edges. Add an arbitrarily chosen extra edge to the graph so obtained. By induction hypothesis, this resulting graph has a cycle of length $N$. If removing the extra edge does not disrupt the cycle, append $v$ anywhere between two consecutive vertices. If it does break the cycle, use $v$ to connect the vertices it joined. The induction is complete. Problem 5 In a convex quadrilateral $A B C D, \angle A B D=30^{\circ}, \angle B C A=75^{\circ}, \angle A C D=25^{\circ}$ and $C D=C B$. Extend $C B$ to meet the circumcircle of triangle $D A C$ at $E$. Prove that $C E=B D$. Solution. First we show that $\angle D E C=30^{\circ}$. Choose a point $F$ on $A B$ such that $C F=C B$. Join $F C$ and $F D$. Observe that $\angle D C B=75^{\circ}+25^{\circ}=100^{\circ}$. Since $C D=C B$, we have $\angle C D B=\angle C B D=40^{\circ}$. Therefore $\angle C B F=40^{\circ}+30^{\circ}=70^{\circ}$. This gives $\angle C F B=70^{\circ}$. Since $C D=C B=C F$, we have the isosceles triangle $C D F$. But $\angle B C F=40^{\circ}$. Hence $\angle F C D=60^{\circ}$. Therefore we have an equilateral triangle $C D F$. This means $F D=F C=C D$ and $\angle D F C=60^{\circ}$. ![](https://cdn.mathpix.com/cropped/2024_06_05_a0deca6809567aa4b59ag-6.jpg?height=628&width=691&top_left_y=865&top_left_x=682) Observe that $\angle A F C=110^{\circ}$ and $\angle F C A=35^{\circ}$. Hence $\angle F A C=35^{\circ}$. This means $F A=$ $F C=F D$. Thus $F$ is the circumcentre of $\triangle A D C$. This implies that $$ \angle C A D=\frac{\angle C F D}{2}=30^{\circ} $$ Therefore $\angle D E C=\angle D A C=30^{\circ}$. Now concentrate on triangle $D C E$. Construct an equilateral triangle $E C G$ with $C E$ as base, on the side of $B$. Join $G D$. ![](https://cdn.mathpix.com/cropped/2024_06_05_a0deca6809567aa4b59ag-6.jpg?height=554&width=577&top_left_y=1842&top_left_x=748) We have $\angle C G E=\angle G C E=\angle C E G=60^{\circ}$ and $C E=E G=G C$. Since $\angle C E D=30^{\circ}$, we get $\angle G E D=30^{\circ}$. Thus $E D$ is the angle bisector of the isosceles triangle $G E C$. This implies that $E D$ is also the pependicular bisector of $G C$. Thus $D$ is on the pependicular bisector of $G C$. Therefore $D C=D G$ and hence $\angle D G C=\angle D C G$. But $\angle D C G=100^{\circ}-60^{\circ}=40^{\circ}$. This implies that $\angle D G C=40^{\circ}$ and hence $\angle C D G=100^{\circ}$. Consider the quadrilateral $G B C D$. We have $D G=D C=C B, \angle G D C=100^{\circ}=\angle D C B$. It is an isosceles trapezium. ( or we can show that $\triangle G D C \cong \triangle B C D$.) Therefore $D B=G C$. But $G C=C E$. Thus we get $D B=C E$. Alternate Solution As in the previous solution, one shows that $F$ is the circumcenter of $\triangle A D C$. since $E$ lies on this circumcircle, this means $F E$ is equal to all of the sides $F A, F D, F C$ and thus also to $C D$ and $C B$. Now $C D B$ and $F C E$ are both isosceles triangles with base angles $40^{\circ}$, and they have $C D=F C$, so they are in fact congruent. This directly implies $C E=B D$, as required. Problem 6. Let $\mathbb{R}[x]$ be the set of all polynomials with real coefficients, and let $\operatorname{deg} P$ denote the degree of a nonzero polynomial $P$. Find all functions $f: \mathbb{R}[x] \rightarrow \mathbb{R}[x]$ satisfying the following conditions: - $f$ maps the zero polynomial to itself, - for any non-zero polynomial $P \in \mathbb{R}[x]$, $\operatorname{deg} f(P) \leq 1+\operatorname{deg} P$, and - for any two polynomials $P, Q \in \mathbb{R}[x]$, the polynomials $P-f(Q)$ and $Q-f(P)$ have the same set of real roots. ## Solution. ## Answer We have $f(p)=p \forall p \in \mathbb{R}[x]$, or $f(p)=-p \forall p \in \mathbb{R}[x]$. These clearly satisfy the given conditions. ## Proof Claim 1 For all $p \in \mathbb{R}[x], f(f(p))=p$. Proof. Using condition 3 on the polynomials $p$ and $f(p)$, we see that $p-f(f(p))$ has the same set of real roots as $f(p)-f(p)=0$, which is $\mathbb{R}$. Therefore $p-f(f(p))$ is identically zero. Note that this implies $f$ is bijective. In what follows, $p \sim q$ will mean that $p$ and $q$ have the same set of real roots. Note that putting $f(q)$ for $q$ in condition 2 gives $p-q \sim f(p)-f(q)$ for all $p, q$ (call this statement $(\star)$ ). In particular, putting $q=0$ here, $p \sim f(p)$ for all $p$ (call this $(\star \star))$. Claim 2 For all non-zero $p \in \mathbb{R}[x]$, $\operatorname{deg} p-1 \leq \operatorname{deg} f(p) \leq \operatorname{deg} p+1$. Proof. The right inequality is simply condition 2 . Now using condition 2 on the polynomial $f(p)$, we see that $\operatorname{deg} f(f(p)) \leq \operatorname{deg} f(p)+1$ which gives $\operatorname{deg} f(p) \geq \operatorname{deg} p-1$ because of claim 1 . Claim 3 For all $p \in \mathbb{R}[x], \operatorname{deg} f(p)=\operatorname{deg} p$. Proof. Note that nonzero constant polynomials have no root, so by ( $\star \star$ ), their image must have no root. This is impossible if that image has degree 1 ; so by condition 2 , the image has degree 0, i.e., is a constant polynomial. First consider the case when $\operatorname{deg} p$ is even; assume for now the leading coefficient of $p$ is positive. That means $p(x) \rightarrow \infty$ for $x \rightarrow \pm \infty$, so it has a global minimum, say $C$. Then the polynomial $p+k(k>C)$ has no real roots. Using ( $\star$ ) on $p$ and the constant polynomial $-k$, we see that $f(p)-f(-k)$ has no roots. But this is impossible if $\operatorname{deg} f(p)$ is odd (since $f(-k)$ is a constant), so by claim 2 , we must $\operatorname{deg} f(p)=\operatorname{deg} p$. A similar argument holds if $p$ has negative leading coefficient. Now if $\operatorname{deg} p$ is odd, then $\operatorname{deg} f(p)$ cannot be even, otherwise $q=f(p)$ would be an even degree polynomial whose image $f(q)=f(f(p))=p$ has odd degree, contradicting the last paragraph. Thus $\operatorname{deg} f(p)$ is odd, and using claim 2, we infer than $\operatorname{deg} f(p)=\operatorname{deg} p$. We call a polynomial $p$ ninth-grade if all $\operatorname{deg} p$ roots of $p$ are real and distinct. Clearly for any ninth-grade $p, p$ and $f(p)$ have the roots and same degree, so $f(p)=c_{p} p$ for some non-zero $c_{p} \in \mathbb{R}$. Claim 4 Given any non-constant $q \in \mathbb{R}[x]$, we can choose $r$ with degree bigger than $q$ so that both $r$ and $q-r$ are ninth-grade. Proof. Assume that all real roots of $q$ are inside the interval $[a, b]$. Now choose a number $n$ which has the same parity as $\operatorname{deg} q$ and is bigger than $\operatorname{deg} q$, and choose numbers $c_{1}=a<$ $c_{2}<\cdots\max _{x \in[a, b]}|q(x)|$ for all $i$. Then $p+q$ has degree $n$, and has alternating signs at $a-\epsilon, x_{1}, \cdots, x_{n}, b+\epsilon$ for $\epsilon>0$, so it has exactly $n$ distinct roots. Now it is enough to take $r=-p$. Claim 5 For any $q \in \mathbb{R}[x], f(q)=c_{q} q$ for some non-zero real $c_{q}$. Proof. We have already proved this for ninth-grade polynomials. Take ninth-grade $r$ so that $q-r$ is ninth grade and $n=\operatorname{deg}(q-r)>\operatorname{deg} q$. Then $q-r \sim f(q)-f(r)=f(q)-c_{r} r$. Since $q-r$ is ninth-grade and has the same degree as $f(q)-c_{r} r, q-r=c\left(f(q)-c_{r} r\right)=c f(q)-c_{1} r$ for non-zero reals $c, c_{1}$. Comparing the leading term (which belongs to $r$ ) on both sides, $c_{1}=1$, therefore $q=c f(q) \Longrightarrow f(q)=c_{q} q$. Claim 6 For any $p, q \in \mathbb{R}[x], c_{p}=c_{q}$. Proof. We note that for any two polynomials $p, q$ if $p-q$ has a real root which is not a root of $p$, then $c_{p}=c_{q}$. Indeed, if $s$ is a root of $p-q$ (meaning $p(s)=q(s) \neq 0$ ), then it's also a root of $f(p)-f(q)=c_{p} p-c_{q} q$, so that $c_{p} p(s)=c_{q} q(s) \Longrightarrow c_{p}=c_{q}$. Now for any two $p, q$, choose odd $N$ such that $N>\max \{\operatorname{deg} p, \operatorname{deg} q\}$. Then the polynomial $r=x^{N}$ is such that $r-p$ and $r-q$ both have real roots, so $c_{q}=c_{r}=c_{p}$. Claim 6 clearly means there is $c \in \mathbb{R}$ so that $f(p)=c p$ for all $p \in \mathbb{R}[x]$. Using the fact $f(f(p))=p$, we see that the only possibilities are $c=1$ or $c=-1$, completing the proof.