1. Given an array A of n integers, find the sum of f(a[i], a[j]) of all pairs (i, j) such that (1 <= i < j <= n).
f(a[i], a[j]):
If | a[j]-a[i] | > 1
f(a[i], a[j]) = a[j] - a[i]
Else if | a[j]-a[i] | <= 1
f(a[i], a[j]) = 0
Input Format
First line contains integer n denoting the size of the array A Next line contains n space separated integers denoting the element of array A.
Output Format
Return an integer.
Constraints
1<=n<=10000
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
5 1 2 3 1 3
Output
4