Task 4. (20 points) In a sequence of natural numbers, each subsequent number, starting from the third, is equal to the absolute difference of the two preceding ones. Determine the maximum number of elements such a sequence can contain if the value of each of them does not exceed 2021.

#
# Solution.

To maximize the length of the sequence, the largest elements should be at the beginning of the sequence. Let's consider the options:

1) $n, n-1,1, n-1, n-2, n-3,1, n-4, n-5,1, \ldots, 2,1,1$;
2) $n, 1, n-1, n-2,1, n-3, n-4,1, \ldots, 2,1,1$.
3) $1, n, n-1,1, n-2,1, n-3, n-4,1, \ldots, 2,1,1$.
4) $n-1, n, 1, n-1, n-2,1, n-3, n-4,1, \ldots, 2,1,1$.

Thus, the length of the sequence that satisfies the condition of the problem will be the greatest if the largest member is the second, and the first is one less. Then this sequence will look like:

$$
n-1, n, 1, n-1, n-2,1, n-3, n-4,1, \ldots, 2,1,1
$$

For $1<n \leq 4$, the length of such a sequence can be determined by direct counting $\left(l_{2}=4, l_{3}=6, l_{4}=7\right)$, and for larger $n$, we will prove that $l_{n+2}=l_{n}+3$. Let's form a sequence with the largest member $n+2$:

$$
n+1, n+2,1, n+1, n, 1, n-1, n-2,1, n-3, n-4,1, \ldots, 2,1,1 .
$$

That is, the length of such a sequence will be:

$$
\begin{gathered}
l_{n}=\frac{3 n}{2}+1=\frac{3 n+2}{2} \text { for even } n, \\
l_{n}=\frac{3(n-1)}{2}+3=\frac{3 n+3}{2} \text { for odd } n .
\end{gathered}
$$

Then, for $n=2021$

$$
l_{2021}=\frac{3 \cdot 2021+3}{2}=3033
$$

Answer. 3033.