<s>[INST] Sum of arithmetic progressions There is this sum: 
$$\sum_{i=0}^{n-1}\left(\sum_{j=i+1}^{n-1}(n-j-1)\right)=\frac{1}{6}(n-2)(n-1)n$$
I don't understand how the formula is derived. What I do currently understand is this: For each i, starting with 0 and ending with n-1 we have a sum like this: 
$$(n-j_{i+1}-1) + (n-j_{i+2}-1)+...+(n-j_{n-1}-1)$$
All these small sums are of course added in a grand total. For a simple case like n = 5 we have these sums:
Sums computed for n = 5
I think the grand total could be expressed like this:
$$\frac{(n-2)(n-1)}{2} + \frac{(n-3)(n-2)}{2}+...+1$$
but I have no clue how to get from this expression to the formula of the sum. I need a step by step proof of how this formula is derived. I don't have a formal training in math.
 [/INST] You can sum vertically instead of horizontally!
Refer to the table:
$$\begin{array}{c|c|c}
i/j&1&2&3&\cdots &n-3&n-2&n-1\\
\hline
0&n-2&n-3&n-4&\cdots&2&1&0\\
1&&n-3&n-4&\cdots&2&1&0\\
2&&&n-4&\cdots&2&1&0\\
\vdots&\cdots\\
n-3&&&&\cdots&\cdots&1&0\\
n-2&&&&\cdots&\cdots&\cdots&0\\
n-1&&&&\cdots&\cdots&\cdots&\cdots&
\end{array}\\
\sum_{i=0}^{n-1}\left(\sum_{j=i+1}^{n-1}(n-j-1)\right)=\sum_{i=0}^{n-3}(i+1)(n-i-2)=\\
\sum_{i=1}^{n-2}i(n-i-1)=(n-1)\sum_{i=1}^{n-2}i-\sum_{i=1}^{n-2}i^2=\\
\frac{(n-1)(1+n-2)}{2}\cdot (n-2)-\frac{(n-2)(n-1)(2(n-2)+1)}{6}=\\
\frac{(n-2)(n-1)[3(n-1)-(2n-3)]}{6}=\frac{1}{6}(n-2)(n-1)n\\$$
Note:
$$\sum_{i=1}^n i=\frac{1+n}{2}\cdot n; \ \ \sum_{i=1}^n i^2=\frac{n(n+1)(2n+1)}{6}.$$
</s>