4. At Andrei's birthday, Yana, who arrived last, gave him a ball, and Eduard, who arrived second to last, gave him a calculator. Testing the calculator, Andrei noticed that the product of the total number of his gifts and the number of gifts he had before Eduard arrived is exactly 16 more than the product of his age and the number of gifts he had before Yana arrived. How many gifts does Andrei have?
Answer: 18. Solution. If $n$ is the number of gifts, and $a$ is Andrei's age, then $n(n-2)=a(n-1)$. From this, $a=\frac{n^{2}-2 n-16}{n-1}=n-1-\frac{17}{n-1}$. Therefore, $n-1=17, a=16$.