EPS/18-03-24/b.py
2024-03-25 15:27:12 +01:00

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)