2. For an integer $n>1$, the numbers $1,2,3, \ldots, n$ are written in order on a blackboard. The following moves are possible.
(i) Take three adjacent numbers $x, y, z$ whose sum is a multiple of 3 and replace them with $y, z, x$.
(ii) Take two adjacent numbers $x, y$ whose difference is a multiple of 3 and replace them with $y, x$.
For example we could take: $1,2,3,4 \xrightarrow{(i)} 2,3,1,4 \xrightarrow{(i i)} 2,3,4,1$
Find all $n$ such that the initial list can be transformed into $n, 1,2, \ldots, n-1$ after a finite number of moves.
SolUTION
For $n \geq 3$ it is straightforward to check by induction that $n$ works if $n \equiv 0$ or 1 modulo 3 .
For $n \equiv 2$ modulo 3 we can multiply each number by its position and sum these products. This total, $T$ is invariant modulo 3. We claim that the desired permutation changes $T$ if $n=3 k+2$. Indeed moving 1 to 2,2 to $3, \ldots n-1$ to $n$ increases $T$ by $\frac{n(n-1)}{2}$ while moving $n$ to 1 decreases $T$ by $n^{2}-n$ so overall $T$ decreases by $\frac{n(n-1)}{2} \equiv 1 \quad$ (3).