This is LaTeX code:
[latex]
=3\sum\limits_{i=1}^{n}{i}-2n=3\frac{n\left(n+1\right)}{2}-2n=\frac{3n^2+3n-4n}{2}=\frac{n\left(3n-1\right)}{2}
[/latex]