100 atcoder#ABC177C. [ABC177C] Sum of product of pairs

[ABC177C] Sum of product of pairs

Score : 300300 points

Problem Statement

Given are NN integers A1,,ANA_1,\ldots,A_N.

Find the sum of Ai×AjA_i \times A_j over all pairs (i,j)(i,j) such that 1i<jN1\leq i < j \leq N, modulo (109+7)(10^9+7).

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 0Ai1090 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Print i=1N1j=i+1NAiAj\sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (109+7)(10^9+7).

3
1 2 3
11

We have 1×2+1×3+2×3=111 \times 2 + 1 \times 3 + 2 \times 3 = 11.

4
141421356 17320508 22360679 244949
437235829