The Bank of Oslo produces coins made of aluminum (A) and bronze (B). Martin arranges $2 n$ coins, $n$ of each type, in a line in an arbitrary order. Then he fixes $k$ as an integer between 1 and $2 n$ and applies the following process: he identifies the longest sequence of consecutive coins of the same type that contains the $k$-th coin from the left, and moves all the coins in this sequence to the left of the line. For example, with $n=4, k=4$, we can have the sequence of operations

$$
A A B \underline{B} B A B A \rightarrow B B B \underline{A} A A B A \rightarrow A A A \underline{B} B B B A \rightarrow B B B \underline{B} A A A A \rightarrow \ldots
$$

Find all pairs $(n, k)$ with $1 \leqslant k \leqslant 2 n$ such that for any initial configuration, the $n$ coins on the left are of the same type after a finite number of steps.
Let's call a chain a maximal sequence of consecutive pieces of the same type. We notice that at each step of the process, if the chain moved is not at one end of the line of pieces, the two adjacent chains merge and the number of chains decreases by 1. This number is at least 2, and this minimum is reached in the case where the first $n$ pieces are of the same type. Therefore, there exists a configuration such that the $n$ pieces on the left are never all of the same type if and only if there exists a configuration such that the chain moved is always the one on the left or the one on the right.

If $1 \leq k \leq n-1$, the initial configuration formed by $n-1$ letters $A$, $n$ letters $B$, and one letter $A$ is such that the chain moved is always the one on the left. If $\left\lceil\frac{3 n}{2}\right\rceil < k \leq 2 n$, the initial configuration formed by $\left\lceil\frac{n}{2}\right\rceil$ letters $A$, as many letters $B$, then $\left\lfloor\frac{n}{2}\right\rfloor$ letters $A$ and as many $B$ is such that the chain moved is always the one on the right. In both cases, we have a cycle that repeats and we never reach the desired configuration.

Let's show that if $n \leq k \leq \left\lceil\frac{3 n}{2}\right\rceil$, we always reach the desired configuration, by showing that for any initial configuration, we eventually move a chain that is not at the edge, and thus reduce the total number of chains. If the configuration does not have the $n$ pieces on the left of the same type, we can never move the chain on the left. It is therefore sufficient to show that we cannot always move the chain on the right. By contradiction, if this were the case, all chains would have a length of at least $\left\lfloor\frac{n}{2}\right\rfloor + 1$ to be able to contain position $k$ when being the chain on the right, which is not possible because having two chains of a given type would result in more than $n$ pieces of that type.

Thus, the $(n, k)$ that work are those such that $n \leq k \leq \left\lceil\frac{3 n}{2}\right\rceil$. (Source: IMO 2022, P1)