12 lines
273 B
Python
12 lines
273 B
Python
|
for i in range(int(input())):
|
||
|
n = int(input())
|
||
|
dists = sorted([int(i) for i in input().split()])
|
||
|
|
||
|
weights = 0
|
||
|
prev = 0
|
||
|
for i, w in enumerate(dists):
|
||
|
weights += w - prev
|
||
|
weights -= (i*(n-i))*(w - prev)
|
||
|
prev = w
|
||
|
|
||
|
print(weights)
|