传统题 1000ms 256MiB

C - Squared Error

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

C - Squared Error

Score : $300$ points

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:

NN

A1A_1 A2A_2 A3A_3 \cdots ANA_N

Output

Print the answer.


3
2 8 4
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$.


5
-5 8 9 -4 -3
950

2024春季入门组刷题营(八)

未参加
状态
已结束
规则
IOI
题目
8
开始于
2024-5-5 13:00
结束于
2024-5-5 15:00
持续时间
2 小时
主持人
参赛人数
11