For what positive integers $A$ is the sequence eventually constant? 
For each integer $n \ge 0$ let $S(n)=n-m^2$, where $m$ is the greatest integer such that $m^2\le n$. Define $(a_k)_{k=0}^\infty$ as $a_0=A$ and $a_{k+1}=a_k+S(a_k)$ for $k \ge0$. For what positive integers $A$ is the sequence eventually constant?

I'm trying to investigate this sequence to find some pattern, but I don't find any... If $A=1$, then $$\begin{align*} a_0 &=1 \\ a_1&= a_0+S(a_0)= 1+(1-m^2) = 1+(1-1)=1 \\ a_2&= a_1+S(a_1)= 1+S(1)=1+(1-1)=1\end{align*}$$ so it would seem that for $A=1$ the sequence is always constant.
For $A=2$ $$\begin{align*} a_0 &=2 \\ a_1&=2+S(2)=2+(2-m^2)=2+(2-1)=3 \\ a_2 &=3+S(3)=3+(3-m^2)=3+(3-1)=5 \\ a_3&=5+S(5)=5+(5-m^2)=5+(5-4)=6 \\ a_4&=6+S(6)=6+(6-m^2)=6+(6-4)=8 \\a_5&=8+S(8)=8+(8-m^2)=8+(8-4)=12 \\ a_6&=12+S(12)= 12+(12-m^2)=12+(12-9)=15\end{align*}$$
so the sequence would seem to be just increasing If $A=3$, then $$\begin{align*} a_0 &=3 \\ a_1&=3+S(3)=5 \\a_2&=5+S(5)=6 \\ a_3&=6+S(6)=8 \end{align*}$$ and this will just be the same as when $A=2$ except were skipping the first term.
Now if $A=4$, then $$\begin{align*} a_0 &=4 \\ a_1&=4+S(4)=4+(4-m^²)=4+(4-2)=6 \\a_2&= 6+S(6)=8 \\a_3&= 8+S(8)=12 \\ a_4&=12+S(12)=15 \\ a_5&=15+S(15)=15+(15-9)=21 \\ a_6&=21+S(21) = 21+(21-16) = 26\end{align*}$$
but this also seems to be increasing? What is the pattern here?

Suppose $a_k=n=m^2+e$ is a nonsquare term, where $m$ is the largest integer such that $m^2\le n$. Then $1\le e\le 2m$ since the next square is $(m+1)^2=m^2+2m+1$, and $S(n)=e$ so $a_{k+1}=m^2+2e$. We have
$$m^2<m^2+2e\le m^2+4m<m^2+4m+4=(m+2)^2$$
and $m^2+2e\ne(m+1)^2$ since the parities of both sides differ (subtract $m^2$). Thus $a_{k+1}$ is also a nonsquare, and since $e\ge1$ at every step the sequence increases forever after $a_k$.
This reasoning applies at $a_0=A$ as well, so the sequence is eventually constant iff $A$ is a perfect square itself.
