Problem: The student council is preparing for the relay race at the sports festival.
The council consists of members. They will run one after the other in the race, the speed of member is . The discrepancy of the -th stage is the difference between the maximum and the minimum running speed among the first members who ran. Formally, if denotes the speed of the -th member who participated in the race, then .
You want to minimize the sum of the discrepancies . To do this, you are allowed to change the order in which the members run. What is the minimum possible sum that can be achieved?
Input Format: The first line contains a single integer () — the number of members of the student council.
The second line contains integers () – the running speeds of the members.
Output Format: Print a single integer — the minimum possible value of after choosing the order of the members.
Note: In the first test case, we may choose to make the third member run first, followed by the first member, and finally the second. Thus , , and . We have:
- .
- .
- .
The resulting sum is . It can be shown that it is impossible to achieve a smaller value.
In the second test case, the only possible rearrangement gives , so the minimum possible result is .