Balancing Pact
All of these business ideas are too serious! Like the clown you are, you decide to open up a circus to entertain the people of Adelaide.
For your first act, you are expected to balance plates at once. Each plate has a weight
, and the "instability" of your act is defined as the sum of the absolute differences between the weights of all pairs of plates.
For example, if you had 4 plates weighing 5, 2, 3 and 5 units respectively, your instability would be:
Input
The first line contains a single integer
, the number of plates you are expected to balance.
The next line contains the weights of each of the plates, integers
.
Output
For each test case, output the instability of your balancing act.
Example
Input 1
4
10 9 8 7
Output 1
10
The instability is equal to
Input 2
2
1 2
Output 2
1
The instability is equal to .
Input 3
1
100
Output 3
0
There is no instability, as there are no pairs of plates.
Comments