#C8215. Half Sum of Pairwise Absolute Differences

    ID: 52173 Type: Default 1000ms 256MiB

Half Sum of Pairwise Absolute Differences

Half Sum of Pairwise Absolute Differences

You are given a list of n integers. Your task is to compute the half of the sum of the absolute differences between every pair of integers.

More formally, let the given integers be \(A_1, A_2, \dots, A_n\). You are required to compute:

\(\text{result} = \frac{1}{2} \sum_{1 \le i < j \le n} |A_i - A_j|\)

Note that the division is integer division. It is guaranteed that the input will have at least two integers.

inputFormat

The input is read from stdin and consists of two lines.

  • The first line contains a single integer n (\(n \ge 2\)).
  • The second line contains n space-separated integers representing the array \(A\).

outputFormat

Output the computed result to stdout — the half of the sum of all pairwise absolute differences, using integer division.

## sample
3
1 3 7
6