Problem 5. The numbers from 1 to 2021 are written on a board. Denis wants to choose 1010 of them such that the sum of any two does not equal 2021 or 2022. How many ways are there to do this?
Solution. Answer: $\frac{1011 \cdot 1012}{2}=511566$.

Let's write our numbers in the following order: $2021,1,2020,2,2019,3, \ldots, 1012,1010,1011$. Notice that if two numbers sum to 2021 or 2022, they stand next to each other in this sequence. Our task is reduced to the following: 2021 objects (for convenience, let's consider them as 2021 balls) are lined up, and we need to count the number of ways to choose 1010 of them, such that no two chosen balls are adjacent.

Let's paint the unchosen balls red and the chosen ones blue. Place all 1011 red balls in a row. We need to place 1010 blue balls in the gaps between them (or at the ends) such that no two blue balls are adjacent. There are exactly 1012 such gaps: 1010 gaps between two red balls, and 2 gaps at the ends; in each of these gaps, we can place no more than one blue ball. Therefore, we need to count the number of ways to choose 1010 gaps out of 1012 available. As is known, this value is $C_{1012}^{1010}=C_{1012}^{2}=\frac{1012 \cdot 1011}{2}=511566$.

Another solution.

We will divide the numbers from 1 to 2021 into 1011 groups - 1010 non-overlapping groups of pairs of numbers that sum to 2022 (specifically: $(1,2021),(2,2020), \ldots,(1009,1013)$, $(1010,1012))$ and a group consisting of the remaining number 1011.

In each group, by the condition, we can choose no more than one number. Therefore, to choose 1010 numbers, we need to choose a group from which no numbers will be taken, and from all other groups, we need to choose exactly one number each.

Suppose we do not take any number from the group $(a, 2022-a)$ (here and below we will assume that in such notation $a \leqslant 2022-a$). From all other groups, we need to choose exactly one number each, in particular, we need to take 1011 (if $a=1011$, then this step is skipped). Then we cannot choose 1010 (otherwise $1011+1010=2021$), but then we must choose 1012 (otherwise nothing is chosen from the last pair). Then we cannot choose 1009 (otherwise $1012+1009=2021$), but then we must choose 1013 (otherwise nothing is chosen from the second-to-last pair). Continuing this way, we get that from the pair $(a+1,2022-(a+1))$ we take the number $2022-(a+1)$. Thus, in all pairs where the smallest number is greater than $a$, the chosen numbers are uniquely determined (specifically, the largest numbers in these pairs must be chosen).

Now consider all pairs where the smallest number is less than $a$. Consider among them the pair $(b, 2022-b)$ in which the largest number, i.e., $2022-b$, is chosen (the case where such pairs do not exist will be considered separately), and if there are several such pairs, consider the one where $b$ is maximal. From all pairs from $(b+1,2022-(b+1))$ to $(a-1,2022-(a-1))$, the smallest number was always chosen (due to the maximality of $b$). In the pair $(b-1,2022-(b-1))$, the number $2022-(b-1)$ was chosen (otherwise $(b-1)+(2022-b)=2021$). Similarly, in the pair $(b-2,2022-(b-2))$, the number $2022-(b-2)$ was chosen, and so on, in the pair $(1,2021)$, the number 2021 was chosen.

Now let's understand how the set of numbers satisfying the condition is determined. First, a group $(a, 2022-a)$ (i.e., a number $1 \leqslant a \leqslant 1011$) is chosen, in which no number is chosen. Then, in all groups where the smallest number is greater than $a$, the choice is uniquely determined (from the group, the largest number is chosen). Second, a pair $(b, 2022-b)$ (i.e., a number $1 \leqslant b \leqslant a-1$) is chosen, and in all other pairs, the choice is uniquely determined (in pairs with the smallest number from $b+1$ to $a-1$, the smallest number is chosen, and in pairs where it is less than $b$, the largest number is chosen).

It remains to count the number of options. Fix some $a$, then the number of ways to choose $b$ will be exactly $a-1$, plus one more option, where in all pairs with the smallest number less than $a$, the smallest number was chosen (i.e., the number $b$ simply does not exist). In total, there are $a$ options for the number $b$. Summing over all $a \leqslant 1011$, we get $1+2+3+\ldots+1010+1011=\frac{1011 \cdot 1012}{2}=511566$ options for our set. Clearly, all these options are distinct and satisfy the condition (the set is uniquely determined by the chosen numbers $a$ and $b$).

## Criteria

The highest appropriate criterion is used:

7 points. Any complete solution to the problem.

7 points. Any complete solution to the problem, but the answer is given in the form of a formula or expression (e.g., $\frac{1011 \cdot 1012}{2}$ or $C_{1012}^{2}$).

6 points. Any complete solution to the problem, but the answer is given in the form of a formula with an ellipsis (e.g., $1+2+3+\ldots+1010+1011$).

2 points. The numbers are divided into pairs, but there is no further progress.

16. The correct answer is given.