Time limit
1s
Memory limit
128 MB
There are n points on a number line. Given the x-coordinate of each point, compute the sum of the distances between the two points for every ordered pair (i, j).
In other words, for every i and j such that 1 <= i <= n and 1 <= j <= n, compute the sum of |x_i - x_j|.
The first line contains the number of points n. (1 <= n <= 10,000)
The second line contains x_1, x_2, ..., x_n, separated by spaces. Each coordinate is an integer between 0 and 1,000,000,000, inclusive.
Print the sum of distances over all ordered pairs on the first line.