Let $a, k, p, r$ and $n$ be all members of $\mathbb{Z}$. $p$ is an arbitrary number such that $a+pr=n$
Why does the statement below hold true?
\begin{align} \sum_{k=0}^{p}(a+kr) &=a+(a+r)+(a+2r)+\cdots+\left(a+(p-2)r\right)+\left(a+(p-1)r\right)+(a+pr)\\ &=a+(a+r)+(a+2r)+\cdots+(n-2r)+(n-r)+n\\ &=\color{red}{\frac{(n+a)\cdot(n-a+r)}{2r}} \end{align}
I don't understand the highlighted transformation. I understand that $(n+a)$ should be a factor as it is the sum of two numbers, one from the lower and other from the higher end, e.g. $(n-r)+(a+r)=n+a$.
However, I was unable to keep up with the rest of the operation. Any help would be appreciated. Thanks.