5. [5] Several natural numbers are written in a row with a sum of 2019. No number and no sum of several consecutive numbers equals 40. What is the maximum number of numbers that could have been written?

A. Shapovalov
Answer: 1019 numbers.

Lemma. The sum of any forty consecutive numbers is not less than 80.

Proof. Let the numbers $a_{1}, \ldots, a_{40}$ be written consecutively. Among the numbers $b_{0}=0, b_{1}=a_{1}$, $b_{2}=a_{1}+a_{2}, \ldots, b_{40}=a_{1}+a_{2}+\ldots+a_{40}$, there will be two $b_{i}$ and $b_{j}(i1019$ numbers. By the lemma, the sum of the first $1000=25 \cdot 40$ of them is not less than $25 \cdot 80=2000$. The sum of the remaining numbers (at least 20) is not less than 20. Therefore, the total sum is not less than 2020. Contradiction.

Example. 25 groups 1, $, ., 1,41$ (in each group 39 ones and the number 41) and then 19 ones.