Balancing Pact


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

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 n plates at once. Each plate has a weight w_i, 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:

I = |5-2| + |5-3| + |5-5| + |2-3| + |2-5| + |3-5| = 3 + 2 + 0 + 1 + 3 + 2 = 11

Input

The first line contains a single integer n (1 \leq n \leq 10^5), the number of plates you are expected to balance.

The next line contains the weights of each of the plates, integers w_1, \dots, w_n (1 \leq w_i \leq 100).

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 |10-9| + |10-8| + |10-7| + |9-8| + |9-7| + |8-7| = 1 + 2 + 3 + 1 + 2 + 1 = 10

Input 2
2
1 2
Output 2
1

The instability is equal to |1-2| = 1.

Input 3
1
100
Output 3
0

There is no instability, as there are no pairs of plates.


Comments

There are no comments at the moment.