In the book by Knuth, Graham, Patashnik : section 2.2: Sums and Recurrences it is given $$S_0 = a_0;$$ $$S_n = S_{n-1}+a_n,$$ General Form (2.7): $$R_0 = \alpha$$ $$R_n = R_{n-1} + \beta + \gamma n$$ In general the solution can be written in the form (2.8): $$R_n = A(n) \alpha + B(n) \beta + C(n) \gamma$$
Here is where I get confused:
Setting $R_n = n^2$ implies $\alpha=0,\beta=-1,\gamma=2$; hence: $$2C(n) - B(n) = n^2$$ and we have $C(n)=\frac{n^2+n}{2}$
I understand why $\alpha=0,\beta=-1,\gamma=2$ and why $2C(n) - B(n) = n^2$, but have trouble understanding how $C(n)=\frac{n^2+n}{2}$ is derived, which implies $B(n)=n$
\begin{align} &R_n =R_{n-1}+\beta+\gamma n \\ &R_{n-1}=R_{n-2}+\beta+\gamma (n-1) \\ &R_{n-2}=R_{n-3}+\beta+\gamma (n-2)\\ &\text{so on ..}\\&R_2=R_1+ \beta+2 \gamma\\ &R_1=\alpha +\beta+\gamma \end{align}
Now add all those equations, you can see that all $R_i$ are cancelled and we are left with -
$$R_n=n \beta +(1+2+3 \ldots n) \gamma=n \beta+\left(\frac{n^2+n}{2}\right) \gamma$$