eolymp
bolt
Try our new interface for solving problems
Problems

Huseyn's Friends

Huseyn's Friends

The student of ADA University Huseyn Hajiyev is moving to Seul to study at Chung-Ang University. He has many friends there, all of them living on Heukseok-ro street. Since he will visit all his friends very often, he is trying to find a house close to them. Huseyn wants to minimize the total distance to all of his friends. \InputFile The first line contains the number of test cases. For each test case, you are given the integer number of friends $n\:(0 < n \le 5000)$ and the house numbers $s_1, s_2, ..., s_i, ..., s_n\:(0 < s_i < 30000)$ where they live. Note that several friends could live in the same house. \OutputFile For each test case, print the minimal sum of distances from the optimal Huseyn’s house to each one of his friends. The distance between two house numbers $s_i$ and $s_j$ is $d_{ij} = |s_i − s_j|$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
3
2 2 4 
3 2 4 6
3 3 1 7
Output example #1
2
4
6