9727: ABC194 —— C - Squared Error
[Creator : ]
Description
Given is a number sequence $A$ of length $N$.
Find the sum of squared differences of every pair of elements: $\displaystyle \sum_{i = 2}^{N} \sum_{j = 1}^{i - 1} (A_i - A_j)^2$.
Find the sum of squared differences of every pair of elements: $\displaystyle \sum_{i = 2}^{N} \sum_{j = 1}^{i - 1} (A_i - A_j)^2$.
Input
Input is given from Standard Input in the following format:
```
$N$
$A_1$ $A_2$ $A_3$ $\cdots$ $A_N$
```
```
$N$
$A_1$ $A_2$ $A_3$ $\cdots$ $A_N$
```
Output
Print the answer.
Constraints
- $2 \le N \le 3 \times 10^5$
- $|A_i| \le 200$
- All values in input are integers.
- $|A_i| \le 200$
- All values in input are integers.
Sample 1 Input
3
2 8 4
Sample 1 Output
56
We have $\sum_{i=2}^{N} {\sum_{j=1}^{i−1}{(A_i−A_j)^2}}=(8−2)^2+(4−2)^2+(4−8)^2=56$.
Sample 2 Input
5
-5 8 9 -4 -3
Sample 2 Output
950