$$\sum_{i=0}^p(i+1)\,a_i\,r^{i+1}+\sum_{i=0}^pa_i\,r^i+\sum_{i=0}^p(i+2)\,a_i\,r^{i-1}=0$$
For each term, make the power equal to $k$ to get the required $i$.
So, for the first term, $i+1=k\implies i=k-1$, for the second $i=k$ and for the third, $i-1=k\implies i=k+1$.
Rewriting $$ka_{k-1}+a_k+(k+3)a_{k+1}=0$$
**Edit**
I made a mistake assuming that the summations are going to $\infty$. Since, from comments, this is not the case, we must be more careful.
The terms will be $$\frac{2a_0} x+(a_0+3a_1)+\sum_{k=1}^{p-1}\big(ka_{k-1}+a_k+(k+3)a_{k+1}\big)x^k+(pa_{p-1}+a_p)x^{p}+(p+1)a_p x^{p+1}$$ But this then implies $a_p=a_{p-1}=0$ as well as $a_0=a_1=0$. Then, this reduces the problem of $$\sum_{i=1}^{p-2}(i+1)\,a_i\,r^{i+1}+\sum_{i=1}^{p-2} a_i\,r^i+\sum_{i=1}^{p-2}(i+2)\,a_i\,r^{i-1}=0$$ to which apply $$ka_{k-1}+a_k+(k+3)a_{k+1}=0$$