2. Let $S$ be a subset of $\{1,2, \ldots, 9\}$ such that the sums of any two elements of $S$ are distinct. For example, the set $\{1,2,3,5\}$ has this property, but the set $\{1,2,3,4,5\}$ does not, because $\{2,3\}$ and $\{1,4\}$ both sum to 5. What is the maximum number of elements that $S$ can contain?
Solution. It is easily verified that $\{1,2,3,5,8\}$ satisfies the condition of the problem.

We will prove that $S$ cannot contain more than 5 elements.

Suppose $S$ contains at least six elements. Then the smallest possible sum of pairs is 3, and the largest $8+9=17$, i.e., the possible sums are

$$
3,4,5, \ldots, 17
$$

and there are 15 of them. On the other hand, we have at least $5+4+3+2+1=15$
different pairs. Thus, all sums from (*) appear exactly once. This means that 1, 2 and 8, 9 must be in $S$. But then $1+9=2+8$, which contradicts the condition.

Therefore, the maximum number of elements that $S$ can contain is 5.