[Nested Sum] Can you help me with this problem?

Revision en4, by brownfox2k6, 2023-05-17 15:06:58

Problem source

104168D2 - Nested Sum (Hard Version)

Statement

Given an array of $$$n$$$ positive integers $$$a_{1}, a_{2},...,a_{n}$$$, find the value of $$$\sum_{i=1}^{n}\sum_{j=i+1}^{n}\sum_{k=j+1}^{n}a_{i}a_{j}a_{k}$$$ modulo $$$10^{9}+7$$$

Input

The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$).

The first line of each test case contains an integer $$$n$$$ ($$$1 \le t \le 10^{5}$$$), the size of the array.

The second line of each test case contains $$$n$$$ integers $$$a_{1}, a_{2},...,a_{n}$$$ ($$$1 \le t \le 10^{9}$$$), the elements of the array.

The sum of n over all test cases doesn't exceed $$$5\cdot 10^{5}$$$.

Output

For each test case output one line containing one integer, the sum described in the problem modulo $$$10^{9}+7$$$

Example

Input
Output

What I've done

I have tried to solve this problem for an hour but when I submit it, many testcase is WA:

My verdict

I don't know why my code failed, can you find out my mistake? This is my code.

My code

Thank you in advance ❤️

Tags math, implementation

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English brownfox2k6 2023-05-17 15:06:58 160 Tiny change: 'y="Input">\n~~~~~\n3\n' -> 'y="Input"> ~~~~~\n3\n'
en3 English brownfox2k6 2023-03-31 06:43:12 13
en2 English brownfox2k6 2023-03-28 19:40:41 1 Tiny change: 'blem for a hour but ' -> 'blem for an hour but '
en1 English brownfox2k6 2023-03-28 19:35:58 4648 Initial revision (published)