#P6067. [USACO05JAN] Moo Volume S

[USACO05JAN] Moo Volume S

Description

There are NN cows on Farmer John’s farm (1N1051 \leq N \leq 10^5). The position of the ii-th cow is xix_i (0xi1090 \leq x_i \leq 10^9).

The cows are very talkative. Each cow chats with the other N1N-1 cows. When the ii-th cow chats with the jj-th cow, the volume is xixj|x_i-x_j|.

Please compute the sum of the volumes of all cow conversations.

Input Format

The first line contains an integer NN.

The next NN lines each contain an integer xix_i.

Output Format

Output the total volume.

It is guaranteed that the answer fits in the range of a 64-bit signed integer.

5
1
5
3
2
4
40

Hint

  • Subtask 1 (original testdata, 1 point): N104N \leq 10^4.
  • Subtask 2 (99 points): no special constraints.

Translated by ChatGPT 5