#K15736. Magic Score Calculation
Magic Score Calculation
Magic Score Calculation
You are given an array of integers. The task is to compute its magic score, which is defined as:
$$\text{MagicScore} = \sum_{i=0}^{n-2} \sum_{j=i+1}^{n-1} a_i \times a_j \; (\bmod\; 1000000007)$$
In other words, for each pair of distinct indices i < j
, multiply a[i]
and a[j]
and then take the summation of all these products modulo 1000000007
.
Your job is to output the magic score for each test case.
inputFormat
The input begins with a single integer T
(the number of test cases). Each test case consists of two lines:
- The first line contains an integer
N
— the number of elements in the array. - The second line contains
N
space-separated integers — the elements of the array.
outputFormat
For each test case, output a single line containing the computed magic score.
## sample3
3
1 2 3
4
2 4 6 8
5
-1 -2 -3 -4 -5
11
140
85
</p>