AtCoder Beginner Contest 194
C
Squared Error
AtCoder
⌀ 386
原题
← BD →
翻译中…

Problem Statement

翻译中…

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$.

翻译中…

Constraints

翻译中…
  • $2 \le N \le 3 \times 10^5$
  • $|A_i| \le 200$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 A_3 \cdots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3
2 8 4
Output #1
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$.
Input #2
5
-5 8 9 -4 -3
Output #2
950
题目信息
题号
abc194_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。