#abc353c. C - Sigma Problem

C - Sigma Problem

Score: 300300 points

问题陈述

对于正整数 xxyy,定义 f(x,y)f(x, y)(x+y)(x + y) 除以 10810^8 的余数。

给定一个长度为 NN 的正整数序列 A=(A1,,AN)A = (A_1, \ldots, A_N)。找出以下表达式的值:

$\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N f(A_i,A_j)$。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

For positive integers xx and yy, define f(x,y)f(x, y) as the remainder of (x+y)(x + y) divided by 10810^8.

You are given a sequence of positive integers A=(A1,,AN)A = (A_1, \ldots, A_N) of length NN. Find the value of the following expression:

$\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N f(A_i,A_j)$.

Constraints

  • 2N3×1052 \leq N \leq 3\times 10^5
  • 1Ai<1081 \leq A_i < 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Print the answer.

Sample Input 1

3
3 50000001 50000002

Sample Output 1

100000012
  • f(A1,A2)=50000004f(A_1,A_2)=50000004
  • f(A1,A3)=50000005f(A_1,A_3)=50000005
  • f(A2,A3)=3f(A_2,A_3)=3

Thus, the answer is f(A1,A2)+f(A1,A3)+f(A2,A3)=100000012f(A_1,A_2) + f(A_1,A_3) + f(A_2,A_3) = 100000012.

Note that you are not asked to compute the remainder of the sum divided by 10810^8.

Sample Input 2

5
1 3 99999999 99999994 1000000

Sample Output 2

303999988