パナソニックプログラミングコンテスト(AtCoder Beginner Contest 186)
翻译中…
Problem Statement
翻译中…
Given are $N$ integers $A_1,\ldots,A_N$.
翻译中…
Find the sum of $|A_i-A_j|$ over all pairs $i,j$ such that $1\leq i < j \leq N$.
翻译中…
In other words, find $\displaystyle{\sum_{i=1}^{N-1}\sum_{j=i+1}^{N} |A_i-A_j|}$.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 2 \times 10^5$$|A_i|\leq 10^8$$A_i$is an integer.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
A_1 \ldots A_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
3
5 1 2
Output #1
8
We have $|5-1|+|5-2|+|1-2|=8$.
Input #2
5
31 41 59 26 53
Output #2
176
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。