Under construction

Still being built. Things may change

Sequence (Easy)

Interview

Time limit1sMemory limit512 MB

Summary
Given a sequence of positive integers, sum A_i times A_j over every pair i < j and print the result modulo 1,000,000,007.
Level

Easy3 of 10

Topics
Math, Prefix sum, Array, Combinatorics
Solved
No attempts yet

Problem

A sequence A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N of length NN is given, and every element is a positive integer. Find the remainder when the sum of Ai×AjA_i \times A_j over all integer pairs (i,j)(i, j) with 1≤i<j≤N1 \le i < j \le N is divided by 1 000 000 0071\,000\,000\,007.

Input

The first line gives the length NN of the sequence AA.

The second line gives the sequence A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N, separated by spaces.

Output

Print the remainder when the sum of Ai×AjA_i \times A_j over all integer pairs (i,j)(i, j) with 1≤i<j≤N1 \le i < j \le N is divided by 1 000 000 0071\,000\,000\,007.

Constraints

  • 2≤N≤500 0002 \le N \le 500\,000
  • 1≤Ai≤500 0001 \le A_i \le 500\,000 (1≤i≤N1 \le i \le N)

Examples1

  1. Example 1

    Input
    3
    1 2 3
    
    Expected output
    11