How is the summation being expanded?

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{array}{rl}& \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}(\sum _{j=1}^{n}j-\sum _{j=1}^{i}j)=\\ & \sum _{i=1}^{n-1}(\frac{n(n+1)}{2}-\frac{i(i+1)}{2})=\\ & \frac{1}{2}\sum _{i=1}^{n-1}{n}^{2}+n-{i}^{2}-i=\\ & \frac{1}{2}((n-1){n}^{2}+(n-1)n-(\frac{n(n+1)(2n+1)}{6}-{n}^{2})-(\frac{n(n+1)}{2}-n))=\\ & f(n)=\frac{n(n(n+1))}{2}-\frac{n(n+1)(2n+1)}{12}-\frac{n(n+1)}{4}\end{array}$

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{array}{rl}& \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}(\sum _{j=1}^{n}j-\sum _{j=1}^{i}j)=\\ & \sum _{i=1}^{n-1}(\frac{n(n+1)}{2}-\frac{i(i+1)}{2})=\\ & \frac{1}{2}\sum _{i=1}^{n-1}{n}^{2}+n-{i}^{2}-i=\\ & \frac{1}{2}((n-1){n}^{2}+(n-1)n-(\frac{n(n+1)(2n+1)}{6}-{n}^{2})-(\frac{n(n+1)}{2}-n))=\\ & f(n)=\frac{n(n(n+1))}{2}-\frac{n(n+1)(2n+1)}{12}-\frac{n(n+1)}{4}\end{array}$