- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Amin has given an array of $n$ distinct numbers, $a_1, a_2, \dots, a_n$ to Niloufar. She came and calculated the value $\max(a_i, a_j) \times |a_i - a_j|$ for each two-element subset ${ a_i, a_j }$ and wrote it on the board. Now Amin wants to calculate the sum of the numbers written on the board. Help him perform this calculation.
ورودی
The first line of input contains a positive integer $t$, representing the number of test cases. $$1 \leq t \leq 100$$
In the first line of each test case, there is an integer $n$ indicating the number of elements in the array. $$2 \leq n \leq 5 \times 10^4$$
The second line of each test case contains $n$ positive integers, representing the elements of the array. $$1 \leq a_i \leq 5 \times 10^4$$
Note that the input array is not necessarily sorted.
خروجی
For each test case, print a single integer representing the sum of the numbers written on the board.
مثالها
ورودی نمونه ۱
3
2
1403 9
4
2 1 4 3
7
10 20 3 15 1000 60 16
خروجی نمونه ۱
1955782
35
5891525
ارسال پاسخ برای این سؤال