5. On the table, there are 2018 playing cards (2018 stacks, each with one card). Petya wants to combine them into one deck of 2018 cards in 2017 operations. Each operation consists of merging two stacks. When Petya merges stacks of $a$ and $b$ cards, Vasily Ivanovich pays Petya $a \cdot b$ rubles. What is the maximum amount of money Petya can earn by performing all 2017 operations?
Answer: $\frac{2017 \cdot 2018}{2}=2035153$

Let's mentally connect the cards in one stack with invisible threads, each with each. Then the operation of combining two stacks with $a$ and $b$ cards adds exactly $a \cdot b$ threads. In the end, each card will be connected by a thread to each other, and the number of threads will not depend on the way the operations are performed and will be equal to $\frac{2017 \cdot 2018}{2}$. This is exactly how many rubles Petya will earn.

Another solution. Notice that when combining stacks of $a$ and $b$ cards, we earn exactly $\frac{1}{2}\left((a+b)^{2}-a^{2}-b^{2}\right)$ rubles; therefore, the final amount we will earn is exactly

$$
\frac{1}{2}(2018^{2} \underbrace{-1^{2}-1^{2}-\ldots-1^{2}}_{2018 \text { times }})=\frac{1}{2}\left(2018^{2}-2018\right)
$$

## Criteria

+ Correct solution - 7 points.

+. In a logically correct solution, the answer is presented as a sum with an ellipsis - at least 1 point is deducted. For example, an answer in the form of $1+2+\ldots+2017$ - 6 points.

$\pm$ It is proven that the answer does not depend on the way the operations are performed - at least 5 points.

-. Correct answer without justification or with incorrect reasoning - 1 point.

Example of incorrect reasoning: in the work, the sum is calculated for a specific way of acting, but it is not proven that the maximum sum is achieved precisely with this method (and it is not proven that the sum does not actually depend on the order of operations).

