Game Of Strengths
Practice
4.5 (22 votes)
Approved
Easy
Math
Open
Sorting
Problem
50% Success 17089 Attempts 20 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Andrew is very fond of Maths.He has N boxes with him,in each box there is some value which represents the Strength of the Box.The ith box has strength A[i]. He wants to calculate the Overall Power of the all N Boxes.

Overall Power here means Sum of Absolute Difference of the strengths of the boxes(between each pair of boxes) multiplied by the Maximum strength among N boxes. Since the Overall Power could be a very large number,output the number modulus 10^9+7(1000000007).

Input

First line of the input contains the number of test cases T. It is followed by T test cases. Each test case has 2 lines. First line contains the number of boxes N. It is followed by a line containing N elements where ith element is the strength of Andrew's ith box.

Output

For each test case, output a single number, which is the Overall Power for that testcase.

Constraints

1<=T<= 10

2<=N<=10^5

0<=A[i]<=10^9

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
172 votes
Tags:
ApprovedEasySorting
Points:20
20 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyOpenSorting
Points:20
194 votes
Tags:
AlgorithmsApprovedEasyOpenReady