题库练习 Almost Difference
← 上一题 下一题 →

A11562 | Almost Difference

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Let's denote a function

![](/uploads/acgo/image/2c5e8f5454df037f_604d3fc1c2c5.jpeg)

You are given an array $a$ consisting of $n$ integers. You have to calculate the sum of $d(a_{i},a_{j})$ over all pairs $(i,j)$ such that $1<=i<=j<=n$ .

输入格式

The first line contains one integer $n$ ( $1<=n<=200000$ ) — the number of elements in $a$ .

The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — elements of the array.

输出格式

Print one integer — the sum of $d(a_{i},a_{j})$ over all pairs $(i,j)$ such that $1<=i<=j<=n$ .

输入输出样例

输入 #1
5
1 2 3 1 3
输出 #1
4
输入 #2
4
6 6 5 5
输出 #2
0
输入 #3
4
6 6 4 4
输出 #3
-8
C++ 编辑器
输入
输出