P6067 [USACO05JAN] Moo Volume S

Description

There are $N$ cows on Farmer John’s farm ($1 \leq N \leq 10^5$). The position of the $i$-th cow is $x_i$ ($0 \leq x_i \leq 10^9$). The cows are very talkative. Each cow chats with the other $N-1$ cows. When the $i$-th cow chats with the $j$-th cow, the volume is $|x_i-x_j|$. Please compute the sum of the volumes of all cow conversations.

Input Format

The first line contains an integer $N$. The next $N$ lines each contain an integer $x_i$.

Output Format

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

Explanation/Hint

- Subtask 1 (original testdata, 1 point): $N \leq 10^4$. - Subtask 2 (99 points): no special constraints. Translated by ChatGPT 5