I am trying to understand summations by solving some example problems, but I could not understand how is the second to last line being expanded? I would really appreciate if you could explain me how is it being expanded.
\begin{align} &\sum_{i=1}^{n-1}\sum_{j=i+1}^{n}\sum_{k=1}^{j}1 =\\ &\sum_{i=1}^{n-1}\sum_{j=i+1}^{n}j =\\ &\sum_{i=1}^{n-1}\left(\sum_{j=1}^{n}j - \sum_{j=1}^{i}j\right) =\\ &\sum_{i=1}^{n-1}\left(\frac{n(n+1)}{2} - \frac{i(i+1)}{2}\right) =\\ &\frac{1}{2}\sum_{i=1}^{n-1}n^2+n-i^2-i =\\ &\frac{1}{2}\left((n-1)n^2 + (n-1)n - \left(\frac{n(n+1)(2n+1)}{6} - n^2\right) - \left(\frac{n(n+1)}{2} - n\right)\right) =\\ &f(n) = \frac{n(n(n+1))}{2} - \frac{n(n+1)(2n+1)}{12} - \frac{n(n+1)}{4} \end{align}