I would like to know why the closed form expression of
$$\sum_{i=1}^{n}\sum_{j=i+1}^{n} (a_i + a_j)^2 + (b_i + b_j)^2$$
evalutes to
$$ (n-2) \cdot \sum_{i=1}^{n} (a_i^2 + b_i^2) + (\sum_{i=1}^{n} a_i)^2 + (\sum_{i=1}^{n} b_i)^2$$.
The problem poster offered us to use the substitution $s = \sum_{i=1}^{n} a_i$.
I am assuming that when $i=n$, the lower bound is larger than the higher bound, and the sum has a value $0$ so can be neglected (thus upper bound of the outer sum is actually up to $i = n-1$, but I left it in original form in case I am wrong).
I tried to expand the inner sum over $j$ into $\sum_{j=1}^{n}(\cdot) - \sum_{j=1}^{i}(\cdot)$ but it did not seem to help simplify terms.
Source: Codeforces global round 19 problem D. You can see his explanation under question 1637D https://codeforces.com/blog/entry/99883