5. Fyodor starts writing pairs of natural numbers $(a, b)$ on the board, where $a<b$ and each does not exceed 2018. Moreover, if a pair of numbers $(a, b)$ is already written on the board, he cannot write any pair of the form $(c, a)$ or $(b, d)$. What is the maximum number of pairs of numbers he can write on the board.

Trunov K.V.
Answer: $1009^{2}=1018081$.

Solution: Let A be the set of all the first numbers in the pairs, and B be the set of all the second numbers in the pairs. Then, from the condition of the problem, it follows that
$\mathrm{A} \cap \mathrm{B}=\varnothing$. Suppose there are $n$ elements in set A and $k$ elements in set B. Then $n+k \leq 2018$. In any pair of numbers, the smaller number can appear no more than $k$ times, and the larger number no more than $n$ times. Therefore, the number of numbers written on the board does not exceed

$n k \leq n(2018-n) \leq \frac{(n+2018-n)^{2}}{4}=\frac{2018^{2}}{4}=1009^{2}$.

Example: (1,1010), (2,1010), ...,(1009,1010), (1,1011), (2,1011),..., $(1009,1011), \ldots,(1,2018),(2,2018), \ldots,(1009,2018)$.

## Recommendations for checking.

Example -3 points.

Estimate only -4 points.