29.2.9 Find all positive integers $n$ such that there exists a permutation $a_{1}$, $a_{2}, \cdots, a_{n}$ of $1,2, \cdots, n$ for which $\left|a_{i}-i\right|(i=1,2, \cdots, n)$ are all distinct.
Since the parity of $\sum_{i=1}^{n}\left|a_{i}-i\right|$ is the same as that of $\sum_{i=1}^{n}\left(a_{i}-i\right)$, and $\sum_{i=1}^{n}\left(a_{i}-i\right)=0$, it follows that $\sum_{i=1}^{n}\left|a_{i}-i\right|$ is even.

Furthermore, since $\left|a_{i}-i\right|(i=1,2, \cdots, n)$ are all distinct, they can only take the values $0,1,2, \cdots, n-1$ each exactly once, i.e., $0+1+2+\cdots+n-1=\frac{(n-1) n}{2}$ is even, so $n \equiv 0$ or $1(\bmod 1)$.
For $n=4 m$, the following arrangement satisfies the requirement:
$$
i: 1,2, \cdots, m-1, m, m+1, \cdots, 2 m-1,2 m, 2 m+1,2 m+2, \cdots, 3 m-1 \text {, }
$$
$3 m, 3 m+1,3 m+2, \cdots, 4 n$
$a_{i}: 4 m-1,4 m-2, \cdots, 3 m+1,3 m-1,3 m-2, \cdots, 2 m, 4 m, 2 m-1$, $2 m-2, \cdots, m+1,3 m-m, m-1, \cdots, 1$
For $n=4 m+1$, the following arrangement satisfies the requirement:
$$
i: 1,2, \cdots, m-1, m, m+1, \cdots, 2 m-1,2 m, 2 m+1,2 m+2, \cdots, 3 m \text {, }
$$
$$
\begin{array}{l}
3 m+1,3 m+2,3 m+3, \cdots, 4 m+1 \\
\quad a_{i}: 4 m, 4 m-1, \cdots, 3 m+2,3 m, 3 m-1, \cdots, 2 m+1,4 m+1,2 m, 2 m-1, \cdots \\
m+1,3 m+1, m, m-1, \cdots, 1
\end{array}
$$

In summary: $n=4 k+4$ or $4 k+1(k \in \mathbf{N})$.