## Task B-1.5.

A sequence of $n$ white and $n$ black tiles is arranged such that black and white tiles alternate, starting with a white tile. The goal is to rearrange the tiles so that all black tiles are together at the beginning of the sequence, and all white tiles are at the end. The only allowed move is to swap adjacent tiles. What is the minimum number of such swaps needed to achieve the goal?
## Solution.

The first move is to swap the first two tiles. The sequence $B C B C B C \ldots$ transitions to $C B B C B C \ldots$ This is one swap.

After that, to bring the new black tile to the second position in the sequence, at least the following 2 swaps are needed: The sequence $C B B C B C \ldots$ first transitions to $C B C B B C \ldots$, and then to $C C B B B C \ldots$

Similarly, to bring the third black tile to the third position, at least 3 swaps are needed: $C C B B C B \ldots \rightarrow C C B C B B \ldots \rightarrow C C C B B B \ldots$ We conclude: to bring the $n$-th black tile to the $n$-th position, at least $n$ swaps are needed.

The smallest total number of swaps is then $N=1+2+3+4+5+\cdots+n$.

Let's write the sum $N$ again in reverse order of the addends, and then add both equations as follows:

$$
\begin{gathered}
N=1+2+3+4+5+\cdots+(n-1)+n \\
N=n+(n-1)+\cdots+5+4+3+2+1 \\
\Longrightarrow 2 N=(1+n)+(2+n-1)+\cdots+(n-1+2)+(n+1)=n(n+1)
\end{gathered}
$$

From this, we have $N=\frac{n(n+1)}{2}$.

Note: It is not enough for the student to just write that the total number of swaps is equal to $1+2+3+\cdots+n$; they must justify this in some way, with a sketch of the tile sequence or in words. If there is no justification, 3 points should be deducted—only 1 point is given for the sum.

The sum $N$ calculated correctly in any way, including knowing the formula, is worth 2 points.