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
What I've done
I have tried to solve this problem for an hour but when I submit it, many testcase is WA:
I don't know why my code failed, can you find out my mistake? This is my code.
Thank you in advance ❤️