Maria invited nine boys and eight girls to her birthday party. She prepared T-shirts with numbers from 1 to 18, kept the one with number 1 for herself, and distributed the rest to her guests. During a dance, she noticed that the sum of the numbers of each couple was a perfect square. Which pairs were dancing?
First, observe that the largest possible sum for a pair is $18+17=35<6^{2}$, from which we obtain the pairs $\{18,7\},\{17,8\}$, and $\{16,9\}$. Now consider two cases:

- The pair for 15 is 10.

It follows that the pair for 6 is 3, and there is no choice for the pair for 1.

- The pair for 15 is 1.

It follows that the pair for 10 is 6, the pair for 2 is 14, the pair for 3 is 13, the pair for 12 is 4, and the pair for 5 is 11. Therefore, there is only one solution:

$$
\{1,15\},\{2,14\},\{3,13\},\{4,12\},\{5,11\},\{6,10\},\{7,18\},\{8,17\},\{9,16\}
$$

Suggestion: To maximize the number of boys, we need to minimize the number of apples each one receives.
Suggestion: Determine the largest perfect square that is the sum of two of the numbers mentioned.
Suggestion: Start by comparing the cards of $A$ and $B$.