E - Easy Computations


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Board

Amin has given an array of nn distinct numbers, a1,a2,,ana_1, a_2, \dots, a_n to Niloufar. She came and calculated the value max(ai,aj)×aiaj\max(a_i, a_j) \times |a_i - a_j| for each two-element subset {ai,aj}\{ 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 tt, representing the number of test cases. 1t1001 \leq t \leq 100

In the first line of each test case, there is an integer nn indicating the number of elements in the array. 2n5×1042 \leq n \leq 5 \times 10^4

The second line of each test case contains nn positive integers, representing the elements of the array. 1ai5×1041 \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
Plain text

خروجی نمونه ۱🔗

1955782
35
5891525
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.