4.13. (Jury, USSR, 82). Find all values of $n \in \mathbf{N}$ for each of which there exists a string of $2 n$ numbers with the following property: for any value $k=1, \ldots, n$ there are 2 numbers in the string equal to $k$, between which there are exactly $k$ numbers.
4.13. Suppose that for some value of $n$ there exists a string of $2 n$ numbers with the required property. Let $m_{k}$ be the position of the first (leftmost) of the two numbers equal to $k$. Then the second of these numbers has the position $m_{k}+k+1$, and the sum of the positions of all $2 n$ numbers in the string is

$$
\sum_{k=1}^{n}\left(m_{k}+\left(m_{k}+k+1\right)\right)=2 \sum_{k=1}^{n} m_{k}+n(n+3) / 2
$$

On the other hand, the sum of the same $2 n$ positions is

$$
\sum_{i=1}^{2 n} i=n(2 n+1)
$$

Therefore,

$$
2 \sum_{k=1}^{n} m_{k}=n(2 n+1)-n(n+3) / 2=n(3 n-1) / 2
$$

hence, the number $n(3 n-1) / 4$ is an integer. Since only one of the numbers $n$ and $3 n-1$ can be even, it must also be divisible by 4, and thus there are only two cases: either $n=4 l$, or $3 n-1=4 l^{\prime}$, i.e.,

$$
n=4 \frac{l^{\prime}+1}{3}-1=4 l-1, \quad \text { where } \quad l, l^{\prime} \in \mathrm{N}
$$

We will prove that any number $n$ of the specified form satisfies the condition of the problem. For $n=4 l, l \geqslant 2$, the required property is possessed, for example, by the string

$$
\begin{aligned}
& (4 l-4 ; \ldots ; 2 l ; 4 l-2 ; 2 l-3 ; \ldots ; 1 ; 4 l-1 ; 1 ; \ldots ; 2 l-3 ; \\
& 2 l ; \ldots ; 4 l-4 ; 4 l ; 4 l-3 ; \ldots ; 2 l+1 ; 4 l-2 ; 2 l-2 ; \ldots ; 2 ; \\
& \quad 2 l-1 ; 4 l-1 ; 2 ; \ldots ; 2 l-2 ; 2 l+1 ; \ldots ; 4 l-3 ; 2 l-1 ; 4 l) \text { ) }
\end{aligned}
$$

in which each ellipsis represents an arithmetic progression with a difference of 2 or -2, starting with the number before the ellipsis and ending with the number after it. Similarly, for $n=4 l-1, l \geqslant 2$, the string

$$
\begin{array}{r}
(4 l-4 ; \ldots ; 2 l ; 4 l-2 ; 2 l-3 ; \ldots ; 1 ; 4 l-1 ; 1 ; \ldots ; 2 l-3 ; \\
2 l ; \ldots ; 4 l-4 ; 2 l-1 ; 4 l-3 ; \ldots ; 2 l+1 ; 4 l-2 ; 2 l-2 ; \ldots, 2 ; \\
2 l-1 ; 4 l-1 ; 2 ; \ldots ; 2 l-2 ; 2 l+1 ; \ldots ; 4 l-3) .
\end{array}
$$

Finally, for $n=4$ and $n=3$ we have the strings ( $2,3,4,2,1,3,1,4$ ) and ( $2,3,1,2,1,3$ ) respectively. Thus, the numbers of the form $n=4 l, n=4 l-1(l \in \mathbb{N})$ and only they satisfy the condition of the problem.