# Day 2. Solutions Problem 4 (Poland). Let $A B C$ be a triangle with incentre $I$. The circle through $B$ tangent to $A I$ at $I$ meets side $A B$ again at $P$. The circle through $C$ tangent to $A I$ at $I$ meets side $A C$ again at $Q$. Prove that $P Q$ is tangent to the incircle of $A B C$. Solution 1. Let $Q X, P Y$ be tangent to the incircle of $A B C$, where $X, Y$ lie on the incircle and do not lie on $A C, A B$. Denote $\angle B A C=\alpha, \angle C B A=\beta, \angle A C B=\gamma$. Since $A I$ is tangent to the circumcircle of $C Q I$ we get $\angle Q I A=\angle Q C I=\frac{\gamma}{2}$. Thus $$ \angle I Q C=\angle I A Q+\angle Q I A=\frac{\alpha}{2}+\frac{\gamma}{2} . $$ By the definition of $X$ we have $\angle I Q C=\angle X Q I$, therefore $$ \angle A Q X=180^{\circ}-\angle X Q C=180^{\circ}-\alpha-\gamma=\beta $$ Similarly one can prove that $\angle A P Y=\gamma$. This means that $Q, P, X, Y$ are collinear which leads us to the conclusion that $X=Y$ and $Q P$ is tangent to the incircle at $X$. ![](https://cdn.mathpix.com/cropped/2024_11_22_43b43e98da9917bcb8e0g-01.jpg?height=478&width=1456&top_left_y=1212&top_left_x=336) Solution 2. By the power of a point we have $$ A D \cdot A C=A I^{2}=A P \cdot A B, \quad \text { which means that } \quad \frac{A Q}{A P}=\frac{A B}{A C} $$ and therefore triangles $A D P, A B C$ are similar. Let $J$ be the incenter of $A Q P$. We obtain $$ \angle J P Q=\angle I C B=\angle Q C I=\angle Q I J $$ thus $J, P, I, Q$ are concyclic. Let $S$ be the intersection of $A I$ and $B C$. It follows that $$ \angle I Q P=\angle I J P=\angle S I C=\angle I Q C . $$ This means that $I Q$ is the angle bisector of $\angle C Q P$, so $Q P$ is indeed tangent to the incircle of $A B C$. Comment. The final angle chasing from the Solution 2 may simply be replaced by the observation that since $J, P, I, Q$ are concyclic, then $I$ is the $A$-excenter of triangle $A P Q$. Solution 3. Like before, notice that $A Q \cdot A C=A P \cdot A B=A I^{2}$. Consider the positive inversion $\Psi$ with center $A$ and power $A I^{2}$. This maps $P$ to $B$ (and vice-versa), $Q$ to $C$ (and vice-versa), and keeps the incenter $I$ fixed. The problem statement will follow from the fact that the image of the incircle of triangle $A B C$ under $\Psi$ is the so-called mixtilinear incircle of $A B C$, which is defined to be the circle tangent to the lines $A B, A C$, and the circumcircle of $A B C$. Indeed, since the image of the line $Q P$ is the circumcircle of $A B C$, and inversion preserves tangencies, this implies that $Q P$ is tangent to the incircle of $A B C$. We justify the claim as follows: let $\gamma$ be the incircle of $A B C$ and let $\Gamma_{A}$ be the $A$-mixtilinear incircle of $A B C$. Let $K$ and $L$ be the tangency points of $\gamma$ with the sides $A B$ and $A C$, and let $U$ and $V$ be the tangency points of $\Gamma_{A}$ with the sides $A B$ and $A C$, respectively. It is well-known that the incenter $I$ is the midpoint of segment $U V$. In particular, since also $A I \perp U V$, this implies that $A U=A V=\frac{A I}{\cos \frac{A}{2}}$. Note that $A K=A L=A I \cdot \cos \frac{A}{2}$. Therefore, $A U \cdot A K=A V \cdot A L=A I^{2}$, which means that $U$ and $V$ are the images of $K$ and $L$ under $\Psi$. Since $\Gamma_{A}$ is the unique circle simultaneously tangent to $A B$ at $U$ and to $A C$ at $V$, it follows that the image of $\gamma$ under $\Psi$ must be precisely $\Gamma_{A}$, as claimed. Solution by Achilleas Sinefakopoulos, Greece. From the power of a point theorem, we have $$ A P \cdot A B=A I^{2}=A Q \cdot A C $$ Hence $P B C Q$ is cyclic, and so, $\angle A P Q=\angle B C A$. Let $K$ be the circumcenter of $\triangle B I P$ and let $L$ be the circumcenter of $\triangle Q I C$. Then $\overline{K L}$ is perpendicular to $\overline{A I}$ at $I$. Let $N$ be the point of intersection of line $\overline{K L}$ with $\overline{A B}$.Then in the right triangle $\triangle N I A$, we have $\angle A N I=90^{\circ}-\frac{\angle B A C}{2}$ and from the external angle theorem for triangle $\triangle B N I$, we have $\angle A N I=\frac{\angle A B C}{2}+\angle N I B$. Hence $$ \angle N I B=\angle A N I-\frac{\angle A B C}{2}=\left(90^{\circ}-\frac{\angle B A C}{2}\right)-\frac{\angle A B C}{2}=\frac{\angle B C A}{2} . $$ Since $M I$ is tangent to the circumcircle of $\triangle B I P$ at $I$, we have $$ \angle B P I=\angle B I M=\angle N I M-\angle N I B=90^{\circ}-\frac{\angle B C A}{2} . $$ Also, since $\angle A P Q=\angle B C A$, we have $$ \angle Q P I=180^{\circ}-\angle A P Q-\angle B P I=180^{\circ}-\angle B C A-\left(90^{\circ}-\frac{\angle B C A}{2}\right)=90^{\circ}-\frac{\angle B C A}{2} $$ as well. Hence $I$ lies on the angle bisector of $\angle B P Q$, and so it is equidistant from its sides $\overline{P Q}$ and $\overline{P B}$. Therefore, the distance of $I$ from $\overline{P Q}$ equals the inradius of $\triangle A B C$, as desired. ![](https://cdn.mathpix.com/cropped/2024_11_22_43b43e98da9917bcb8e0g-03.jpg?height=967&width=1529&top_left_y=316&top_left_x=309) Solution by Eirini Miliori (HEL2). Let $D$ be the point of intersection of $\overline{A I}$ and $\overline{B C}$ and let $R$ be the point of intersection of $\overline{A I}$ and $\overline{P Q}$. We have $\angle R I P=\angle P B I=\frac{\angle B}{2}$, $\angle R I Q=\angle I C Q=\frac{\angle C}{2}, \angle I Q C=\angle D I C=x$ and $\angle B P I=\angle B I D=\varphi$, since $\overline{A I}^{2}$ is tangent to both circles. ![](https://cdn.mathpix.com/cropped/2024_11_22_43b43e98da9917bcb8e0g-03.jpg?height=730&width=1157&top_left_y=1708&top_left_x=444) From the angle bisector theorem, we have $$ \frac{R Q}{R P}=\frac{A Q}{A P} \quad \text { and } \quad \frac{A C}{A B}=\frac{D C}{B D} $$ Since $\overline{A I}$ is tangent to both circles at $I$, we have $A I^{2}=A Q \cdot A C$ and $A I^{2}=A P \cdot A B$. Therefore, $$ \frac{R Q}{R P} \cdot \frac{D C}{B D}=\frac{A Q \cdot A C}{A B \cdot A P}=1 $$ From the sine law in triangles $\triangle Q R I$ and $\triangle P R I$, it follows that $\frac{R Q}{\sin \frac{\angle C}{2}}=\frac{R I}{\sin y}$ and $\frac{R P}{\sin \frac{\angle B}{2}}=\frac{R I}{\sin \omega}$, respectively. Hence $$ \frac{R Q}{R P} \cdot \frac{\sin \frac{\angle B}{2}}{\sin \frac{\angle C}{2}}=\frac{\sin \omega}{\sin y} $$ Similarly, from the sine law in triangles $\triangle I D C$ and $\triangle I D B$, it is $\frac{D C}{\sin x}=\frac{I D}{\sin \frac{\angle C}{2}}$ and $\frac{B D}{\sin \varphi}=\frac{I D}{\sin \frac{\angle B}{2}}$, and so $$ \frac{D C}{B D} \cdot \frac{\sin \varphi}{\sin x}=\frac{\sin \frac{\angle B}{2}}{\sin \frac{\angle C}{2}} $$ By multiplying equations (2) with (3), we obtain $\frac{R Q}{R P} \cdot \frac{D C}{B D} \cdot \frac{\sin \varphi}{\sin x}=\frac{\sin \omega}{\sin y}$, which combined with (1) and cross-multiplying yields $$ \sin \varphi \cdot \sin y=\sin \omega \cdot \sin x $$ Let $\theta=90^{\circ}+\frac{\angle A}{2}$. Since $I$ is the incenter of $\triangle A B C$, we have $x=90^{\circ}+\frac{\angle A}{2}-\varphi=\theta-\phi$. Also, in triangle $\triangle P I Q$, we see that $\omega+y+\frac{\angle B}{2}+\frac{\angle C}{2}=180^{\circ}$, and so $y=\theta-\omega$. Therefore, equation (4) yields $$ \sin \varphi \cdot \sin (\theta-\omega)=\sin \omega \cdot \sin (\theta-\varphi) $$ or $$ \frac{1}{2}(\cos (\varphi-\theta+\omega)-\cos (\varphi+\theta-\omega))=\frac{1}{2}(\cos (\omega-\theta+\varphi)-\cos (\omega+\theta-\varphi)) $$ which is equivalent to $$ \cos (\varphi+\theta-\omega)=\cos (\omega+\theta-\varphi) $$ So $$ \varphi+\theta-\omega=2 k \cdot 180^{\circ} \pm(\omega+\theta-\varphi), \quad(k \in \mathbb{Z} .) $$ If $\varphi+\theta-\omega=2 k \cdot 180^{\circ}+(\omega+\theta-\varphi)$, then $2(\varphi-\omega)=2 k \cdot 180^{\circ}$, with $|\varphi-\omega|<180^{\circ}$ forcing $k=0$ and $\varphi=\omega$. If $\varphi+\theta-\omega=2 k \cdot 180^{\circ}-(\omega+\theta-\varphi)$, then $2 \theta=2 k \cdot 180^{\circ}$, which contradicts the fact that $0^{\circ}<\theta<180^{\circ}$. Hence $\varphi=\omega$, and so $P I$ is the angle bisector of $\angle Q P B$. Therefore the distance of $I$ from $\overline{P Q}$ is the same with the distance of $I$ from $A B$, which is equal to the inradius of $\triangle A B C$. Consequently, $\overline{P Q}$ is tangent to the incircle of $\triangle A B C$. ## Problem 5 (Netherlands). Let $n \geq 2$ be an integer, and let $a_{1}, a_{2}, \ldots, a_{n}$ be positive integers. Show that there exist positive integers $b_{1}, b_{2}, \ldots, b_{n}$ satisfying the following three conditions: 1. $a_{i} \leq b_{i}$ for $i=1,2, \ldots, n$; 2. the remainders of $b_{1}, b_{2}, \ldots, b_{n}$ on division by $n$ are pairwise different; and 3. $b_{1}+\cdots+b_{n} \leq n\left(\frac{n-1}{2}+\left\lfloor\frac{a_{1}+\cdots+a_{n}}{n}\right\rfloor\right)$. (Here, $\lfloor x\rfloor$ denotes the integer part of real number $x$, that is, the largest integer that does not exceed $x$.) Solution 1. We define the $b_{i}$ recursively by letting $b_{i}$ be the smallest integer such that $b_{i} \geq a_{i}$ and such that $b_{i}$ is not congruent to any of $b_{1}, \ldots, b_{i-1}$ modulo $n$. Then $b_{i}-a_{i} \leq i-1$, since of the $i$ consecutive integers $a_{i}, a_{i}+1, \ldots, a_{i}+i-1$, at most $i-1$ are congruent to one of $b_{1}, \ldots, b_{i-1}$ modulo $n$. Since all $b_{i}$ are distinct modulo $n$, we have $\sum_{i=1}^{n} b_{i} \equiv \sum_{i=1}^{n}(i-1)=\frac{1}{2} n(n-1)$ modulo $n$, so $n$ divides $\sum_{i=1}^{n} b_{i}-\frac{1}{2} n(n-1)$. Moreover, we have $\sum_{i=1}^{n} b_{i}-\sum_{i=1}^{n} a_{i} \leq \sum_{i=1}^{n}(i-1)=\frac{1}{2} n(n-1)$, hence $\sum_{i=1}^{n} b_{i}-\frac{1}{2} n(n-1) \leq \sum_{i=1}^{n}$. As the left hand side is divisible by $n$, we have $$ \frac{1}{n}\left(\sum_{i=1}^{n} b_{i}-\frac{1}{2} n(n-1)\right) \leq\left[\frac{1}{n} \sum_{i=1}^{n} a_{i}\right] $$ which we can rewrite as $$ \sum_{i=1}^{n} b_{i} \leq n\left(\frac{n-1}{2}+\left[\frac{1}{n} \sum_{i=1}^{n} a_{i}\right]\right) $$ as required. Solution 2. Note that the problem is invariant under each of the following operations: - adding a multiple of $n$ to some $a_{i}$ (and the corresponding $b_{i}$ ); - adding the same integer to all $a_{i}$ (and all $b_{i}$ ); - permuting the index set $1,2, \ldots, n$. We may therefore remove the restriction that our $a_{i}$ and $b_{i}$ be positive. For each congruence class $\bar{k}$ modulo $n(\bar{k}=\overline{0}, \ldots, \overline{n-1})$, let $h(k)$ be the number of $i$ such that $a_{i}$ belongs to $\bar{k}$. We will now show that the problem is solved if we can find a $t \in \mathbb{Z}$ such that $$ \begin{array}{cl} h(t) & \geq 1, \\ h(t)+h(t+1) & \geq 2 \\ h(t)+h(t+1)+h(t+2) & \geq 3 \end{array} $$ Indeed, these inequalities guarantee the existence of elements $a_{i_{1}} \in \bar{t}, a_{i_{2}} \in \bar{t} \cup \overline{t+1}$, $a_{i_{3}} \in \bar{t} \cup \overline{t+1} \cup \overline{t+2}$, et cetera, where all $i_{k}$ are different. Subtracting appropriate multiples of $n$ and reordering our elements, we may assume $a_{1}=t, a_{2} \in\{t, t+1\}$, $a_{3} \in\{t, t+1, t+2\}$, et cetera. Finally subtracting $t$ from the complete sequence, we may assume $a_{1}=0, a_{2} \in\{0,1\}, a_{3} \in\{0,1,2\}$ et cetera. Now simply setting $b_{i}=i-1$ for all $i$ suffices, since $a_{i} \leq b_{i}$ for all $i$, the $b_{i}$ are all different modulo $n$, and $$ \sum_{i=1}^{n} b_{i}=\frac{n(n-1)}{2} \leq \frac{n(n-1)}{2}+n\left[\frac{\sum_{i=1}^{n} a_{i}}{n}\right] . $$ Put $x_{i}=h(i)-1$ for all $i=0, \ldots, n-1$. Note that $x_{i} \geq-1$, because $h(i) \geq 0$. If we have $x_{i} \geq 0$ for all $i=0, \ldots, n-1$, then taking $t=0$ completes the proof. Otherwise, we can pick some index $j$ such that $x_{j}=-1$. Let $y_{i}=x_{i}$ where $i=0, \ldots, j-1, j+1, \ldots, n-1$ and $y_{j}=0$. For sequence $\left\{y_{i}\right\}$ we have $$ \sum_{i=0}^{n-1} y_{i}=\sum_{i=0}^{n-1} x_{i}+1=\sum_{i=0}^{n-1} h(i)-n+1=1 $$ so from Raney's lemma there exists index $k$ such that $\sum_{i=k}^{k+j} y_{i}>0$ for all $j=0, \ldots, n-1$ where $y_{n+j}=y_{j}$ for $j=0, \ldots, k-1$. Taking $t=k$ we will have $$ \sum_{t=k}^{k+i} h(t)-(i+1)=\sum_{t=k}^{k+i} x(t) \geq \sum_{t=k}^{k+i} y(t)-1 \geq 0 $$ for all $i=0, \ldots, n-1$ and we are done. Solution 3. Choose a random permutation $c_{1}, \ldots, c_{n}$ of the integers $1,2, \ldots, n$. Let $b_{i}=a_{i}+f\left(c_{i}-a_{i}\right)$, where $f(x) \in\{0, \ldots, n-1\}$ denotes a remainder of $x$ modulo $n$. Observe, that for such defined sequence the first two conditions hold. The expected value of $B:=b_{1}+\ldots+b_{n}$ is easily seen to be equal to $a_{1}+\ldots+a_{n}+n(n-1) / 2$. Indeed, for each $i$ the random number $c_{i}-a_{i}$ has uniform distribution modulo $n$, thus the expected value of $f\left(c_{i}-a_{i}\right)$ is $(0+\ldots+(n-1)) / n=(n-1) / 2$. Therefore we may find such $c$ that $B \leq a_{1}+\ldots+a_{n}+n(n-1) / 2$. But $B-n(n-1) / 2$ is divisible by $n$ and therefore $B \leq n\left[\left(a_{1}+\ldots+a_{n}\right) / n\right]+n(n-1) / 2$ as needed. Solution 4. We will prove the required statement for all sequences of non-negative integers $a_{i}$ by induction on $n$. Case $n=1$ is obvious, just set $b_{1}=a_{1}$. Now suppose that the statement is true for some $n \geq 1$; we shall prove it for $n+1$. First note that, by subtracting a multiple of $n+1$ to each $a_{i}$ and possibly rearranging indices we can reduce the problem to the case where $0 \leq a_{1} \leq a_{2} \leq \cdots \leq a_{n} \leq a_{n+1}<$ $n+1$. Now, by the induction hypothesis there exists a sequence $d_{1}, d_{2}, \ldots, d_{n}$ which satisfies the properties required by the statement in relation to the numbers $a_{1}, \ldots, a_{n}$. Set $I=\{i \mid 1 \leq$ $i \leq n$ and $\left.d_{i} \bmod n \geq a_{i}\right\}$ and construct $b_{i}$, for $i=1, \ldots, n+1$, as follows: $$ b_{i}=\left\{\begin{array}{l} d_{i} \bmod n, \text { when } i \in I, \\ n+1+\left(d_{i} \bmod n\right), \text { when } i \in\{1, \ldots, n\} \backslash I, \\ n, \text { for } i=n+1 \end{array}\right. $$ Now, $a_{i} \leq d_{i} \bmod n \leq b_{i}$ for $i \in I$, while for $i \notin I$ we have $a_{i} \leq n \leq b_{i}$. Thus the sequence $\left(b_{i}\right)_{i=1}^{n+1}$ satisfies the first condition from the problem statement. By the induction hypothesis, the numbers $d_{i} \bmod n$ are distinct for $i \in\{1, \ldots, n\}$, so the values $b_{i} \bmod (n+1)$ are distinct elements of $\{0, \ldots, n-1\}$ for $i \in\{1, \ldots, n\}$. Since $b_{n+1}=n$, the second condition is also satisfied. Denote $k=|I|$. We have $$ \begin{gathered} \sum_{i=1}^{n+1} b_{i}=\sum_{i=1}^{n} b_{i}+n=\sum_{i=1}^{n} d_{i} \bmod n+(n-k)(n+1)+n= \\ \frac{n(n+1)}{2}+(n-k)(n+1) \end{gathered} $$ hence we need to show that $$ \frac{n(n+1)}{2}+(n-k)(n+1) \leq \frac{n(n+1)}{2}+(n+1)\left[\frac{\sum_{i=1}^{n+1} a_{i}}{n+1}\right] $$ equivalently, that $$ n-k \leq\left[\frac{\sum_{i=1}^{n+1} a_{i}}{n+1}\right] $$ Next, from the induction hypothesis we have $$ \begin{gathered} \frac{n(n-1)}{2}+n\left[\frac{\sum_{i=1}^{n} a_{i}}{n}\right] \geq \sum_{i=1}^{n} d_{i}=\sum_{i \in I} d_{i}+\sum_{i \notin I} d_{i} \geq \\ \sum_{i \in I} d_{i} \bmod n+\sum_{i \notin I}\left(n+d_{i} \bmod n\right)=\frac{n(n-1)}{2}+(n-k) n \end{gathered} $$ or $$ n-k \leq\left[\frac{\sum_{i=1}^{n} a_{i}}{n}\right] $$ Thus, it's enough to show that $$ \frac{\sum_{i=1}^{n} a_{i}}{n} \leq \frac{\sum_{i=1}^{n+1} a_{i}}{n+1} $$ because then $$ n-k \leq\left[\frac{\sum_{i=1}^{n} a_{i}}{n}\right] \leq\left[\frac{\sum_{i=1}^{n+1} a_{i}}{n+1}\right] $$ But the required inequality is equivalent to $\sum_{i=1}^{n} a_{i} \leq n a_{n+1}$, which is obvious. Solution 5. We can assume that all $a_{i} \in\{0,1, \ldots, n-1\}$, as we can deduct $n$ from both $a_{i}$ and $b_{i}$ for arbitrary $i$ without violating any of the three conditions from the problem statement. We shall also assume that $a_{1} \leq \ldots \leq a_{n}$. Now let us provide an algorithm for constructing $b_{1}, \ldots, b_{n}$. We start at step 1 by choosing $f(1)$ to be the maximum $i$ in $\{1, \ldots, n\}$ such that $a_{i} \leq n-1$, that is $f(1)=n$. We set $b_{f(1)}=n-1$. Having performed steps 1 through $j$, at step $j+1$ we set $f(j+1)$ to be the maximum $i$ in $\{1, \ldots, n\} \backslash\{f(1), \ldots, f(j)\}$ such that $a_{i} \leq n-j-1$, if such an index exists. If it does, we set $b_{f(j+1)}=n-j-1$. If there is no such index, then we define $T=j$ and assign to the terms $b_{i}$, where $i \notin f(\{1, \ldots, j\})$, the values $n, n+1 \ldots, 2 n-j-1$, in any order, thus concluding the run of our algorithm. Notice that the sequence $\left(b_{i}\right)_{i=1}^{n}$ satisfies the first and second required conditions by construction. We wish to show that it also satisfies the third. Notice that, since the values chosen for the $b_{i}$ 's are those from $n-T$ to $2 n-T-1$, we have $$ \sum_{i=1}^{n} b_{i}=\frac{n(n-1)}{2}+(n-T) n $$ It therefore suffices to show that $$ \left[\frac{a_{1}+\ldots+a_{n}}{n}\right] \geq n-T $$ or (since the RHS is obviously an integer) $a_{1}+\ldots+a_{n} \geq(n-T) n$. First, we show that there exists $1 \leq i \leq T$ such that $n-i=b_{f(i)}=a_{f(i)}$. Indeed, this is true if $a_{n}=n-1$, so we may suppose $a_{n}t$ and in fact one can show $T=t+f(t+1)$ by proceeding inductively and using the fact that $t$ is the last time for which $a_{f(t)}=b_{f(t)}$. Now we get that, since $a_{f(t+1)+1} \geq n-t$, then $\sum_{i} a_{i} \geq(n-t)(n-f(t+1))=(n-T+f(t+$ 1) $)(n-f(t+1))=n(n-T)+n f(t+1)-f(t+1)(n-T+f(t+1))=n(n-T)+t f(t+1) \geq$ $n(n-T)$. Greedy algorithm variant $\mathbf{1}$ (ISR). Consider the residues $0, \ldots, n-1$ modulo $n$ arranged in a circle clockwise, and place each $a_{i}$ on its corresponding residue; so that on each residue there is a stack of all $a_{i}$ s congruent to it modulo $n$, and the sum of the sizes of all stacks is exactly $n$. We iteratively flatten and spread the stacks forward, in such a way that the $a_{i}$ s are placed in the nearest available space on the circle clockwise (skipping over any already flattened residue or still standing stack). We may choose the order in which the stacks are flattened. Since the total amount of numbers equals the total number of spaces, there is always an available space and at the end all spaces are covered. The $b_{i} \mathrm{~s}$ are then defined by adding to each $a_{i}$ the number of places it was moved forward, which clearly satifies (i) and (ii), and we must prove that they satisfy (iii) as well. Suppose that we flatten a stack of $k$ numbers at a residue $i$, causing it to overtake a stack of $l$ numbers at residue $j \in(i, i+k)$ (we can allow $j$ to be larger than $n$ and identify it with its residue modulo $n$ ). Then in fact in fact in whichever order we would flatten the two stacks, the total number of forward steps would be the same, and the total sum of the corresponding $b_{t}$ (such that $a_{t} \bmod n \in\{i, j\}$ ) would be the same. Moreover, we can merge the stacks to a single stack of $k+l$ numbers at residue $i$, by replacing each $a_{t} \equiv j$ $(\bmod n)$ by $a_{t}^{\prime}=a_{t}-(j-i)$, and this stack would be flattened forward into the same positions as the separate stacks would have been, so applying our algorithm to the new stacks will yield the same total sum of $\sum b_{i}-$ but the $a_{i}$ s are strictly decreased, so $\sum a_{i}$ is decreased, so $\left\lfloor\frac{\sum a_{i}}{n}\right\rfloor$ is not increased - so by merging the stacks, we can only make the inequality we wish to prove tighter. Thus, as long as there is some stack that when flattened will overtake another stack, we may merge stacks and only make the inequality tighter. Since the amount of numbers equals the amount of places, the merging process terminates with stacks of sizes $k_{1}, \ldots, k_{m}$, such that the stack $j$, when flattened, will exactly cover the interval to the next stack. Clearly the numbers in each such stack were advanced by a total of $\sum_{t=1}^{k_{j}-1}=\frac{k_{j}\left(k_{j}-1\right)}{2}$, thus $\sum b_{i}=\sum a_{i}+\sum_{j} \frac{k_{j}\left(k_{j}-1\right)}{2}$. Writing $\sum a_{i}=n \cdot r+s$ with $0 \leq si$ (otherwise, the greedy choice would prefer $d_{j}$ to $d_{i}$ at stage $i$ ). We call this the greedy property. In particular, it follows that all $i$ such that $d_{i} \in\left[s, d_{t}\right)=\left[c_{t}, d_{t}\right)$ must satisfy $ir$ (since $r \notin\left\{d_{i}\right\}$ at all), so $n-m-1 \geq r$. It follows that there is a time $t^{\prime} \geq t$ for which $d_{t^{\prime}} \equiv n-m-1(\bmod n)$ : If $n-m-1=r$ then this is true for $t^{\prime}=t$ with $d_{t}=n+r=2 n-m-1$; whereas if $n-m-1 \in[r+1, n)$ then there is some $t^{\prime}$ for which $d_{t^{\prime}}=n-m-1$, and by the definition of $m$ it satisfies $t^{\prime}>t$. Therefore for all $i