5. Sabine has a very large shell collection. She decides to give part of her shells to her little sister. On the first day, she lays all her shells in a long row and then gives every shell that is in a square position in the row (so the first, the fourth, the ninth, the sixteenth, and so on) to her little sister. On the second day, she makes a long row again with the remaining shells and once again gives every shell that is in a square position to her little sister. She repeats this process every day.

It turns out that for the first time on the 27th day, she has fewer than 1000 shells left, and on the 28th day, it is the tenth time that the number of shells she has left is exactly a square number.

What are the possible numbers of shells with which Sabine could have started?
5. Suppose that on a certain day Sabine has $n^{2}$ shells left, with $n>1$. Then the next day she gives away $n$ shells and has $n^{2}-n$ shells left. This is more than $(n-1)^{2}$, because

$$
(n-1)^{2}=n^{2}-2 n+1=\left(n^{2}-n\right)-(n-1)1$. The day after that, she gives away $n-1$ shells and has $n^{2}-n-(n-1)=(n-1)^{2}$ shells left, which is exactly a square again. The number of shells Sabine has left thus alternates between being a square and not being a square.

Let $d$ be the first day on which Sabine has a square number of shells left, say $n^{2}$. Then the days $d+2, d+4, \ldots, d+18$ are the second through tenth days she has a square number of shells left (namely $(n-1)^{2},(n-2)^{2}, \ldots,(n-9)^{2}$ shells). We conclude that $d+18=28$ and thus $d=10$.

On day 26, she has at least 1000 shells left, but on days 27 and 28, she has fewer than 1000 shells left. We see that $(n-9)^{2}x-n$ or $x+1-(n+1)=x-n$ shells are left.

Now we look at the number of shells Sabine has left on day 8. Let this number be $x$. The obvious possibility $x=41^{2}=1681$ is ruled out because $x$ cannot be a square. We therefore try $x=41^{2}-2, x=41^{2}-1$ and $x=41^{2}+1$. The table gives the number of shells left on days 8, 9, and 10.

| day 8 | day 9 | day 10 |
| :---: | :---: | :---: |
| $41^{2}-2=1679$ | $1679-40=1639$ | $1639-40=1599$ |
| $41^{2}-1=1680$ | $1680-40=1640$ | $1640-40=1600$ |
| $41^{2}+1=1682$ | $1682-41=1641$ | $1641-40=1601$ |

We see that the option $x=1679$ is ruled out because then on day 10 there would be fewer than $40^{2}=1600$ shells left. This also rules out $x=1682$ due to the above observation. Sabine must therefore have exactly $41^{2}-1$ shells left on day 8.

To trace this pattern, we look at the situation where the number of shells is slightly less than a square. Suppose that on a certain day Sabine has $n^{2}-a$ shells left, where $1 \leqslant a < n$. The next day she has $n^{2}-a-n$ shells left. The day after that, she has $n^{2}-a-n-(n-1)=(n-1)^{2}-(a-1)$ shells left.

If Sabine starts with $45^{2}-5$ shells, then on days 2, 4, 6, and 8 she has $44^{2}-4, 43^{2}-3, 42^{2}-2$, and $41^{2}-1$ shells left, respectively. This gives a solution.

If Sabine starts with $45^{2}-4$ shells, then on day 8 she has too many shells left, namely $41^{2}-0$. Sabine could not have started with $45^{2}-4$ or more shells.

If Sabine starts with $45^{2}-6$ shells, then on day 8 she has only $41^{2}-2$ shells left. This is too few, so Sabine could not have started with $45^{2}-6$ or fewer shells.

We conclude that the only possibility is that Sabine started with $45^{2}-5=2020$ shells.