Let's denote a function 

$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$

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.


-----Input-----

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. 


-----Output-----

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


-----Examples-----
Input
5
1 2 3 1 3

Output
4

Input
4
6 6 5 5

Output
0

Input
4
6 6 4 4

Output
-8



-----Note-----

In the first example:

  d(a_1, a_2) = 0;  d(a_1, a_3) = 2;  d(a_1, a_4) = 0;  d(a_1, a_5) = 2;  d(a_2, a_3) = 0;  d(a_2, a_4) = 0;  d(a_2, a_5) = 0;  d(a_3, a_4) =  - 2;  d(a_3, a_5) = 0;  d(a_4, a_5) = 2.

Difficulty: HARD

Solutions:
n = int(input())
cnt = {}
res = 0
s = 0
a = list(map(int, input().split()))
for i in range(n):
	x = a[i]
	s += x
	cnt[x] = cnt.get(x, 0) + 1
	res += x * (i + 1 - (cnt.get(x, 0) + cnt.get(x - 1, 0) + cnt.get(x + 1, 0))) - (s - (x * cnt.get(x, 0) + (x - 1) * cnt.get(x - 1, 0) + (x + 1) * cnt.get(x + 1, 0)))
print(res)


from collections import Counter
mp = Counter()
n = int(input())
arr = list(map(int, input().split()))
(tot, cnt, ans) = (0, 0, 0)
for i in arr:
	ncnt = cnt - mp[i] - mp[i + 1] - mp[i - 1]
	ntot = tot - i * mp[i] - (i - 1) * mp[i - 1] - (i + 1) * mp[i + 1]
	nsum = ncnt * i - ntot
	ans += nsum
	mp[i] += 1
	cnt += 1
	tot += i
print(ans)


n = int(input())
d = dict()
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(n):
	ans = ans + i * a[i] - s
	if d.get(a[i] - 1):
		ans -= d[a[i] - 1]
	if d.get(a[i] + 1):
		ans += d[a[i] + 1]
	if d.get(a[i]):
		d[a[i]] += 1
	else:
		d[a[i]] = 1
	s += a[i]
print(ans)


n = int(input())
v = [0] + [int(x) for x in input().split(' ')]
ma = {}
st = 0
ris = 0
for p in range(n, 0, -1):
	val = v[p]
	v2 = val + 1
	c2 = ma.get(v2, 0)
	v1 = val
	c1 = ma.get(v1, 0)
	v0 = val - 1
	c0 = ma.get(v0, 0)
	cnt = n - p - c2 - c1 - c0
	sp = st - v2 * c2 - v1 * c1 - v0 * c0
	ris -= cnt * val
	ris += sp
	st += val
	ma[val] = ma.get(val, 0) + 1
print(ris)


n = int(input())
keys = list(map(int, input().split()))
dictionary = {}
ans = 0
sum = 0
for i in range(0, n):
	key = keys[i]
	a = dictionary.get(key - 1)
	b = dictionary.get(key)
	c = dictionary.get(key + 1)
	if a == None:
		a = 0
	if b == None:
		b = 0
	if c == None:
		c = 0
	ans += key * (i - a - b - c) - (sum - a * (key - 1) - b * key - c * (key + 1))
	sum += key
	if dictionary.get(key) == None:
		dictionary[key] = 1
	else:
		dictionary[key] += 1
print(ans)


n = int(input())
arr = [int(e) for e in input().split()]
m = {}
f = {}
for i in arr:
	m[i] = 0
	m[i - 1] = 0
	m[i + 1] = 0
	f[i] = 0
	f[i - 1] = 0
	f[i + 1] = 0
for i in arr:
	m[i] += 1
ans = 0
for i in range(n):
	tot = n
	left = i
	right = n - i - 1
	left -= f[arr[i]]
	left -= f[arr[i] - 1]
	left -= f[arr[i] + 1]
	f[arr[i]] += 1
	right -= m[arr[i]] - f[arr[i]]
	right -= m[arr[i] + 1] - f[arr[i] + 1]
	right -= m[arr[i] - 1] - f[arr[i] - 1]
	ans += left * arr[i] - right * arr[i]
print(ans)


def update(fenwick, idx, val, n):
	while idx < n:
		fenwick[idx] += val
		idx += idx & -idx

def get_sum(fenwick, idx):
	sum = 0
	while idx > 0:
		sum += fenwick[idx]
		idx -= idx & -idx
	return sum

def count_smaller_elements(arr):
	temp = arr.copy()
	temp.sort()
	curr_size = 1
	Hashed_Value = {}
	for item in temp:
		if item not in Hashed_Value:
			Hashed_Value[item] = curr_size
			curr_size += 1
	fenwick = [0] * curr_size
	for i in range(n):
		temp[i] = Hashed_Value[arr[i]]
	temp = temp[::-1]
	count_smaller = [0] * n
	for i in range(n):
		count_smaller[i] = get_sum(fenwick, temp[i] - 1)
		update(fenwick, temp[i], 1, curr_size)
	return count_smaller[::-1]
n = int(input())
l1 = list(map(int, input().split()))
d1 = {}
ans = 0
for i in range(-1, -n - 1, -1):
	if l1[i] not in d1:
		ans -= l1[i] * (abs(i) - 1)
	else:
		ans -= l1[i] * (abs(i) - 1 - d1[l1[i]])
	if l1[i] not in d1:
		d1[l1[i]] = 1
	else:
		d1[l1[i]] += 1
d1 = {}
for i in range(n):
	if l1[i] not in d1:
		ans += l1[i] * i
	else:
		ans += l1[i] * (i - d1[l1[i]])
	if l1[i] not in d1:
		d1[l1[i]] = 1
	else:
		d1[l1[i]] += 1
for item in l1:
	if item - 1 in d1:
		ans -= d1[item - 1]
	if item + 1 in d1:
		ans += d1[item + 1]
	if item not in d1:
		d1[item] = 1
	else:
		d1[item] += 1
print(ans)


n = int(input())
d = {}
a = list(map(int, input().split()))
tot = ans = 0
for i in range(n):
	ans += i * a[i] - tot
	tot += a[i]
	ans += d.get(a[i] + 1, 0) - d.get(a[i] - 1, 0)
	d.setdefault(a[i], 0)
	d[a[i]] += 1
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
pref = 0
d = {}
for i in range(n):
	ans += i * a[i] - pref
	pref += a[i]
	if a[i] - 1 in d:
		ans -= d[a[i] - 1]
	if a[i] + 1 in d:
		ans += d[a[i] + 1]
	if a[i] in d:
		d[a[i]] += 1
	else:
		d[a[i]] = 1
print(ans)


n = int(input())
dic = {}
sl = list(map(int, input().split()))
summ = [0 for i in range(n)]
summ[n - 1] = sl[n - 1]
for i in range(n - 2, -1, -1):
	summ[i] = summ[i + 1] + sl[i]
for i in sl:
	if i in dic:
		dic[i] = dic[i] + 1
	else:
		dic[i] = 1
fuckdiff = 0
for i in range(0, n - 1):
	fuckdiff += summ[i] - (n - i) * sl[i]
	if sl[i] + 1 in dic:
		fuckdiff -= dic[sl[i] + 1]
	if sl[i] - 1 in dic:
		fuckdiff += dic[sl[i] - 1]
	dic[sl[i]] -= 1
print(fuckdiff)


n = int(input())
a = input().split(' ')
ans = 0
kk = 0
kol = dict()
for i in range(n - 1, -1, -1):
	a[i] = int(a[i])
	kk += a[i]
	kol[a[i]] = 1 + kol.get(a[i], 0)
	plus = kk - (n - i) * a[i]
	plus += kol.get(a[i] - 1, 0)
	plus -= kol.get(a[i] + 1, 0)
	ans += plus
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(0, n):
	ans += a[i] * i - s
	s += a[i]
d = {}
for i in range(0, n):
	if a[i] + 1 in d:
		ans += d[a[i] + 1]
	if a[i] - 1 in d:
		ans -= d[a[i] - 1]
	if not a[i] in d:
		d[a[i]] = 0
	d[a[i]] += 1
print(ans)


n = int(input())
A = [int(i) for i in input().split()]
acc = 0
res = 0
for i in range(len(A)):
	acc -= A[i]
	res += acc + A[i] * (i + 1)
mp = dict()
for i in range(len(A)):
	mp[A[i]] = mp.get(A[i], 0) + 1
	res -= mp.get(A[i] - 1, 0) - mp.get(A[i] + 1, 0)
print(res)


n = int(input())
arr = list(map(int, input().split()))
arr_sum = sum(arr)
cnt = {}
for val in arr:
	try:
		cnt[val] += 1
	except:
		cnt[val] = 1
res = 0
for i in range(n - 1, -1, -1):
	arr_sum -= arr[i]
	cnt[arr[i]] -= 1
	res += i * arr[i] - arr_sum
	if arr[i] + 1 in cnt.keys():
		res += cnt[arr[i] + 1]
	if arr[i] - 1 in cnt.keys():
		res -= cnt[arr[i] - 1]
print(res)


from collections import defaultdict
n = int(input(''))
din = input('').split(' ')
ans = sum = 0
m = defaultdict(int)
for i in range(len(din)):
	x = int(din[i])
	tmp = sum - m[x - 1] * (x - 1) - m[x + 1] * (x + 1) - m[x] * x
	cnt = i - (m[x + 1] + m[x - 1] + m[x])
	ans += cnt * x - tmp
	m[x] += 1
	sum += x
print(ans)


n = int(input())
l = list(map(int, input().split()))
d = {}
ans = 0
curr = 0
for i in range(len(l) - 1, -1, -1):
	curr += l[i]
	z = 0
	z1 = 0
	if l[i] - 1 in d:
		z = d[l[i] - 1]
	else:
		z = 0
	if l[i] + 1 in d:
		z1 = d[l[i] + 1]
	else:
		z1 = 0
	ans += curr - (len(l) - i) * l[i] + z - z1
	if l[i] in d:
		d[l[i]] += 1
	else:
		d[l[i]] = 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
ps = [a[0]] * n
for i in range(1, n):
	ps[i] = a[i] + ps[i - 1]
cnt = dict()
ans = 0
cnt[a[0]] = 1
for i in range(1, n):
	ans += a[i] * i
	ans -= ps[i - 1]
	if a[i] - 1 not in cnt:
		cnt[a[i] - 1] = 0
	ans -= cnt[a[i] - 1]
	if a[i] + 1 not in cnt:
		cnt[a[i] + 1] = 0
	ans += cnt[a[i] + 1]
	if a[i] not in cnt:
		cnt[a[i]] = 0
	cnt[a[i]] = cnt[a[i]] + 1
print(ans)


n = int(input())
arr = input()
arr = arr.split()
for i in range(n):
	arr[i] = int(arr[i])
ans = 0
sm = arr[0]
m = {}
m[sm] = 1
for i in range(1, n):
	a = 0
	b = 0
	c = 0
	d = 0
	x = arr[i]
	if not x in m:
		m[x] = 0
	m[x] += 1
	if x - 1 in m:
		a = m[x - 1]
	if x + 1 in m:
		b = m[x + 1]
	ans = ans + x * (i - a - b) - (sm - a * (x - 1) - b * (x + 1))
	sm += x
print(ans)


from bisect import bisect
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
	cnt += a[i] * i
	cnt -= a[i] * (n - i - 1)
m = {}
for i in range(n):
	if a[i] not in m:
		m[a[i]] = []
	m[a[i]].append(i)
l = sorted([(i, m[i]) for i in m])
fix = 0
for i in range(len(l) - 1):
	if abs(l[i][0] - l[i + 1][0]) == 1:
		tmp = 0
		for i0 in l[i][1]:
			i1 = bisect(l[i + 1][1], i0)
			tmp = tmp + len(l[i + 1][1]) - 2 * i1
		if l[i][0] < l[i + 1][0]:
			fix = fix + tmp
		else:
			fix = fix - tmp
print(cnt - fix)


n = int(input())
a = list(map(int, input().split()))
sm = 0
dc = {}
res = 0
for i in range(n):
	res += a[i] * i - sm
	if a[i] + 1 in dc:
		res += dc[a[i] + 1]
	if a[i] - 1 in dc:
		res -= dc[a[i] - 1]
	sm += a[i]
	if a[i] in dc:
		dc[a[i]] += 1
	else:
		dc[a[i]] = 1
print(res)


n = int(input())
a = list(map(int, input().split()))
sm = 0
ans = 0
mp = {}
for i in range(n):
	ans += i * a[i] - sm
	ans -= mp.get(a[i] - 1, 0)
	ans += mp.get(a[i] + 1, 0)
	mp[a[i]] = mp.get(a[i], 0) + 1
	sm += a[i]
print(ans)


n = int(input())
a = input().split()
a = [int(x) for x in a]
cnt = {}
for i in range(n):
	cnt[a[i]] = 0
	cnt[a[i] + 1] = 0
	cnt[a[i] - 1] = 0
ans = 0
res = 0
for i in range(n):
	ans = ans + (i - cnt[a[i]] - cnt[a[i] + 1] - cnt[a[i] - 1]) * a[i]
	ans = ans - (res - cnt[a[i] - 1] * (a[i] - 1) - cnt[a[i]] * a[i] - cnt[a[i] + 1] * (a[i] + 1))
	cnt[a[i]] = cnt[a[i]] + 1
	res = res + a[i]
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
suf = [int(0) for i in range(n + 1)]
for i in range(n - 1, -1, -1):
	suf[i] = suf[i + 1] + arr[i]
mp = dict()
for x in arr:
	if x in mp:
		mp[x] += 1
	else:
		mp[x] = 1
ans = 0
for i in range(n):
	ans += suf[i] - (n - i) * arr[i]
	if arr[i] + 1 in mp:
		ans -= mp[arr[i] + 1]
	if arr[i] - 1 in mp:
		ans += mp[arr[i] - 1]
	mp[arr[i]] -= 1
print(ans)


numCnt = int(input())
nums = [int(i) for i in input().split(' ')]
cnt = dict()
curSum = 0
curCnt = 0
ans = 0
for a in nums:
	ans += curCnt * a - curSum
	ans += cnt.get(a + 1, 0)
	ans -= cnt.get(a - 1, 0)
	curSum += a
	curCnt += 1
	if not a in cnt:
		cnt[a] = 0
	cnt[a] += 1
print(ans)


n = int(input())
nums = [int(i) for i in input().split()]
map = {nums[0]: 1}
result = 0
partial = nums[0]
for a in range(1, n):
	if nums[a] in map.keys():
		map[nums[a]] += 1
	else:
		map.update({nums[a]: 1})
	result += a * nums[a] - partial
	partial += nums[a]
	new = 0
	if nums[a] - 1 in map.keys():
		new -= map[nums[a] - 1]
	if nums[a] + 1 in map.keys():
		new += map[nums[a] + 1]
	result += new
print(result)


n = int(input())
l = list(map(int, input().split()))
s = 0
for i in range(n):
	s += l[i] * i - l[i] * (n - i - 1)
d = {}
c = 0
for i in range(n):
	if l[i] not in d:
		d[l[i]] = 1
	else:
		d[l[i]] += 1
	if l[i] + 1 in d:
		c -= d[l[i] + 1]
	if l[i] - 1 in d:
		c += d[l[i] - 1]
print(s - c)


cnt = {}
n = int(input())
s = 0
an = 0
a = list(map(int, input().split()))
for i in range(n):
	if a[i] not in cnt.keys():
		cnt[a[i]] = 0
	if a[i] - 1 not in cnt.keys():
		cnt[a[i] - 1] = 0
	if a[i] + 1 not in cnt.keys():
		cnt[a[i] + 1] = 0
	s += a[i]
	cnt[a[i]] += 1
	num = i + 1 - cnt[a[i]] - cnt[a[i] - 1] - cnt[a[i] + 1]
	an += num * a[i] - (s - a[i] * cnt[a[i]] - (a[i] + 1) * cnt[a[i] + 1] - (a[i] - 1) * cnt[a[i] - 1])
print(an)


n = int(input())
m = {}
almost_sum = 0
s = list(map(int, input().split()))
sum_all = 0
for i in range(n):
	a = s[i]
	if a not in m:
		m[a] = 1
	else:
		m[a] += 1
	u = 0
	if a + 1 in m:
		u = m[a + 1]
	l = 0
	if a - 1 in m:
		l = m[a - 1]
	almost_sum += a * i - sum_all - l + u
	sum_all += a
print(almost_sum)


n = int(input())
a = [0] + list(map(int, input().split()))
s = [0] * len(a)
mp = {}
for i in range(1, n + 1):
	s[i] = s[i - 1] + a[i]
	if mp.get(a[i]):
		mp[a[i]] += 1
	else:
		mp[a[i]] = 1
ans = 0
for i in range(1, n + 1):
	ans += s[n] - s[i - 1]
	l = mp.get(a[i] - 1, 0)
	m = mp.get(a[i], 0)
	r = mp.get(a[i] + 1, 0)
	ans -= l * (a[i] - 1) + m * a[i] + r * (a[i] + 1)
	ans -= a[i] * (n - i + 1 - l - m - r)
	mp[a[i]] -= 1
	if mp[a[i]] == 0:
		mp.pop(a[i])
print(ans)


n = int(input())
a = list(map(int, input().split()))
p = [0] * (n + 1)
for i in range(n):
	p[i + 1] = p[i] + a[i]
mp = dict()
cnt = 0
for i in range(n):
	f1 = mp.setdefault(a[i])
	f2 = mp.setdefault(a[i] - 1)
	f3 = mp.setdefault(a[i] + 1)
	if f1 == None:
		f1 = 0
	if f2 == None:
		f2 = 0
	if f3 == None:
		f3 = 0
	mp[a[i]] = f1 + 1
	cnt += i * a[i] - p[i] + f3 - f2
print(cnt)


from sys import stdin, stdout
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
d = dict()
(ans, sm) = (0, 0)
for i in range(n):
	if a[i] not in d.keys():
		d[a[i]] = 0
	d[a[i]] += 1
	ans += i * a[i] - sm
	if a[i] + 1 in d.keys():
		ans += 1 * d[a[i] + 1]
	if a[i] - 1 in d.keys():
		ans -= 1 * d[a[i] - 1]
	sm += a[i]
stdout.write(str(ans))


n = int(input())
m = {}
ans = 0
a = input().split()
for i in range(n):
	a[i] = int(a[i])
	(m[a[i]], m[a[i] - 1], m[a[i] + 1]) = (0, 0, 0)
	ans += a[i] * (2 * i - n + 1)
for i in range(n):
	ans += m[a[i] + 1] - m[a[i] - 1]
	m[a[i]] += 1
print(ans)


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
m = {}
m = defaultdict(lambda : 0, m)
pre = []
pre.append(a[0])
m[a[0]] = m[a[0]] + 1
ans = 0
for i in range(1, n):
	ans = ans + i * a[i] - pre[i - 1]
	ans = ans - (m[a[i] - 1] - m[a[i] + 1])
	pre.append(pre[i - 1] + a[i])
	m[a[i]] = m[a[i]] + 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
s = a[n - 1]
ans = 0
D = dict()
D[a[n - 1]] = 1
for i in range(n - 2, -1, -1):
	x = a[i]
	c = 0
	d = 0
	if x - 1 in D:
		c = D[x - 1]
	if x + 1 in D:
		d = D[x + 1]
	ans += s - ((n - 1 - i) * x - c + d)
	s += x
	if x in D:
		D[x] += 1
	else:
		D[x] = 1
print(ans)


n = int(input())
l = input().split(' ')
for i in range(n):
	l[i] = int(l[i])
sum = 0
ans = 0
mp = dict()
for i in range(n):
	ans -= sum - i * l[i]
	ans -= mp.get(l[i] - 1, 0) - mp.get(l[i] + 1, 0)
	mp[l[i]] = mp.get(l[i], 0) + 1
	sum += l[i]
print(ans)


n = int(input())
M = {}
F = [0] * 200005
P = [0] * 200005
F = list(map(int, input().split()))
P[0] = F[0]
for i in range(n):
	val = M.get(F[i])
	if val == None:
		val = 0
	M[F[i]] = val + 1
	P[i] = P[i - 1] + F[i]
ans = 0
for i in range(n):
	val = M.get(F[i])
	M[F[i]] = val - 1
	ans += P[n - 1] - P[i] - (n - 1 - i) * F[i]
	val = M.get(F[i] + 1)
	if val == None:
		val = 0
	ans -= val
	val = M.get(F[i] - 1)
	if val == None:
		val = 0
	ans += val
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
memo = dict(((a[i], 0) for i in range(n)))
for i in range(n):
	ans += a[i] * (2 * i - n + 1)
	memo[a[i]] += 1
	ans -= memo.get(a[i] - 1, 0)
	ans += memo.get(a[i] + 1, 0)
print(ans)


n = int(input())
cnt = dict()
s = 0
ans = 0
a = list(map(int, input().split()))
for i in range(0, n):
	ans += a[i] * i - s
	ans -= cnt.get(a[i] - 1, 0)
	ans += cnt.get(a[i] + 1, 0)
	s += a[i]
	cnt[a[i]] = cnt.get(a[i], 0) + 1
print(ans)


n = int(input())
a = [0] + input().split()
s_i = 0
global mp
mp = {}
for i in range(1, n + 1):
	a[i] = int(a[i])
	if a[i] not in mp:
		mp[a[i]] = 1
	else:
		mp[a[i]] += 1
	s_i += a[i]
ans = 0
for i in range(n, 0, -1):
	s_in = mp.get(a[i] - 1, 0) * (a[i] - 1) + mp.get(a[i], 0) * a[i] + mp.get(a[i] + 1, 0) * (a[i] + 1)
	cnt_in = mp.get(a[i] - 1, 0) + mp.get(a[i], 0) + mp.get(a[i] + 1, 0)
	ans += a[i] * (i - cnt_in) - (s_i - s_in)
	mp[a[i]] -= 1
	s_i -= a[i]
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
s = 0
ss = 0
m = n
mp = {}
while n > 0:
	n -= 1
	ss += a[n]
	s += ss - (m - n) * a[n]
	mp.setdefault(a[n] - 1, 0)
	mp.setdefault(a[n] + 1, 0)
	mp.setdefault(a[n], 0)
	s += mp[a[n] - 1] - mp[a[n] + 1]
	mp[a[n]] += 1
print(s)


n = int(input())
d = {}
ans = 0
a = list(map(int, input().split()))
sumsofar = a[0]
for i in range(1, n):
	ans += i * a[i] - sumsofar
	sumsofar += a[i]
d[a[0]] = 1
for i in range(1, n):
	try:
		ans -= d[a[i] - 1]
	except:
		pass
	try:
		ans += d[a[i] + 1]
	except:
		pass
	try:
		d[a[i]] += 1
	except:
		d[a[i]] = 1
print(ans)


tmp = input()
ans = 0
arr = [int(x) for x in input().split(' ')]
n = len(arr)
m = {}
sum = 0
for i in range(0, n):
	m[arr[i]] = m.get(arr[i], 0) + 1
	sum += arr[i]
for i in range(0, n):
	m[arr[i]] = m.get(arr[i], 0) - 1
	sum -= arr[i]
	c1 = m.get(arr[i] - 1, 0)
	c2 = m.get(arr[i], 0)
	c3 = m.get(arr[i] + 1, 0)
	cur_sum = sum - (c1 * (arr[i] - 1) + c2 * arr[i] + c3 * (arr[i] + 1))
	cur_cnt = n - i - 1 - c1 - c2 - c3
	ans += cur_sum - cur_cnt * arr[i]
print(ans)


n = int(input())
xd = input().split()
a = [0]
for s in xd:
	a.append(int(s))
b = [0] * (n + 1)
for i in range(1, n + 1):
	b[i] = b[i - 1] + a[i]
sol = 0
mp = {}

def mpg(x):
	if x in mp:
		return mp[x]
	else:
		return 0
for i in range(1, n + 1):
	x = a[i]
	mp[x] = mpg(x) + 1
	sol += i * x - b[i]
	sol -= mpg(x - 1)
	sol += mpg(x + 1)
print(sol)


n = int(input())
arr = list(map(int, input().split()))
freq = dict()
res = 0
for i in range(n - 1, -1, -1):
	freq[arr[i]] = freq.get(arr[i], 0) + 1
	tp = -1 * (n - i - 1) * arr[i]
	tp += i * arr[i]
	tp -= freq.get(arr[i] + 1, 0)
	tp += freq.get(arr[i] - 1, 0)
	res += tp
print(res)


m = {}
n = int(input())
l = list(map(int, input().split()))
Sum = 0
ans = 0
for i in range(n):
	ans += i * l[i] - Sum
	if m.__contains__(l[i] - 1):
		ans -= m[l[i] - 1]
	if m.__contains__(l[i] + 1):
		ans += m[l[i] + 1]
	if m.__contains__(l[i]):
		m[l[i]] += 1
	else:
		m[l[i]] = 1
	Sum += l[i]
print(ans)


cnt = {}
n = int(input())
tot_sum = 0
tot_cnt = 0
res = 0
for y in input().split():
	y = int(y)
	tot_sum += y
	tot_cnt += 1
	if y in cnt:
		cnt[y] += 1
	else:
		cnt[y] = 1
	tmp_sum = tot_sum
	tmp_cnt = tot_cnt
	for d in range(-1, 2):
		x = y + d
		if x in cnt:
			tmp_sum -= x * cnt[x]
			tmp_cnt -= cnt[x]
	res += tmp_cnt * y - tmp_sum
print(res)


from collections import Counter
n = int(input())
arr = [int(i) for i in input().split()]
cnt = Counter()
for i in arr:
	cnt[i] += 1
cur = Counter()
s = sum(arr)
d = 0
i = 0
for val in arr:
	n1 = cnt[val - 1] - cur[val - 1]
	n2 = cnt[val + 1] - cur[val + 1]
	n3 = cnt[val] - cur[val]
	d += s - (n - i) * val
	d -= n1 * (val - 1)
	d += n1 * val
	d -= n2 * (val + 1)
	d += n2 * val
	d -= n3 * val
	d += n3 * val
	i += 1
	s -= val
	cur[val] += 1
print(d)


inp = []
d = {}
n = int(input())
tot = 0
ans = 0
temp = input()
temp = temp.split()
inp = [int(i) for i in temp]
for i in range(n):
	val = inp[i]
	tot = tot + val
	if val not in d:
		d[val] = 1
	else:
		d[val] += 1
for i in range(n - 1, 0, -1):
	prev = 0
	nxt = 0
	if inp[i] + 1 in d:
		nxt = d[inp[i] + 1]
	if inp[i] - 1 in d:
		prev = d[inp[i] - 1]
	ans += inp[i] * (i + 1 - d[inp[i]] - prev - nxt)
	ans -= tot - inp[i] * d[inp[i]] - (inp[i] + 1) * nxt - (inp[i] - 1) * prev
	d[inp[i]] -= 1
	tot -= inp[i]
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n - 2, -1, -1):
	b[i] = b[i + 1] + a[i + 1]
d = dict()
d[a[n - 1]] = 1
c = 0
for i in range(n - 2, -1, -1):
	if a[i] in d:
		d[a[i]] += 1
	else:
		d[a[i]] = 1
	t = b[i] - a[i] * (n - i - 1)
	if a[i] + 1 in d:
		t -= d[a[i] + 1]
	if a[i] - 1 in d:
		t += d[a[i] - 1]
	c += t
print(c)


n = int(input())
a = map(int, input().split())
mp = {}
s = 0
ans = 0
i = 0
for x in a:
	i += 1
	s += x
	if x not in mp:
		mp[x] = 0
	if x + 1 not in mp:
		mp[x + 1] = 0
	if x - 1 not in mp:
		mp[x - 1] = 0
	mp[x] += 1
	adj = mp[x] + mp[x + 1] + mp[x - 1]
	c = s
	c -= mp[x] * x
	c -= mp[x + 1] * (x + 1)
	c -= mp[x - 1] * (x - 1)
	valid = i - adj
	ans += valid * x - c
print(ans)


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
from collections import defaultdict
n = ii()
a = li()

def calc(a):
	d = defaultdict(int)
	s = 0
	for i in range(n):
		x = a[i]
		s += (i - d[x] - d[x - 1] - d[x + 1]) * x
		d[x] += 1
	return s
ans = calc(a) - calc(a[::-1])
print(ans)


n = int(input())
a = list(map(int, input().split()))
cnt = {}
pref = 0
ans = 0
for i in range(n):
	ans += i * a[i] - pref
	t = 0
	if a[i] - 1 in cnt:
		ans += cnt[a[i] - 1] * (a[i] - 1)
		t += cnt[a[i] - 1]
	if a[i] + 1 in cnt:
		ans += cnt[a[i] + 1] * (a[i] + 1)
		t += cnt[a[i] + 1]
	if a[i] in cnt:
		ans += cnt[a[i]] * a[i]
		t += cnt[a[i]]
	ans -= a[i] * t
	if a[i] in cnt:
		cnt[a[i]] += 1
	else:
		cnt[a[i]] = 1
	pref += a[i]
print(ans)


import sys
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
(left, right) = (Counter(), Counter(a))
ans = 0
for (l, r, x) in zip(range(n), range(n - 1, -1, -1), a):
	right[x] -= 1
	l_cnt = l - left[x + 1] - left[x] - left[x - 1]
	r_cnt = r - right[x + 1] - right[x] - right[x - 1]
	ans += x * (l_cnt - r_cnt)
	left[x] += 1
print(ans)


n = int(input())
sum = 0
res = 0
cnt = dict()
a = list(map(int, input().split()))
for i in range(n):
	sub = 0
	num = 0
	for j in range(-1, 2, 1):
		if a[i] + j in cnt:
			sub += (a[i] + j) * cnt[a[i] + j]
			num += cnt[a[i] + j]
	res += (i - num) * a[i] - (sum - sub)
	sum += a[i]
	cnt[a[i]] = cnt.get(a[i], 0) + 1
print(res)


import sys
mm = {}
sum = 0
ans = 0
line = sys.stdin.readline()
n = int(line)
line = sys.stdin.readline()
ls = line.split()
i = 0
for t in ls:
	t = int(ls[i])
	ans += t * i + sum
	sum -= t
	for j in range(-1, 2):
		if t + j in mm:
			ans += j * mm[t + j]
	if t in mm:
		mm[t] += 1
	else:
		mm[t] = 1
	i += 1
print(ans)


N = int(input())
arr = input()
arr = list(map(int, arr.split(' ')))
dict1 = {}
dict2 = {}
ans = 0
for i in range(0, N):
	ans += i * arr[i]
	ans -= (N - i - 1) * arr[i]
for i in range(0, N):
	op1 = 0
	if arr[i] - 1 in dict1:
		op1 = dict1[arr[i] - 1]
	op2 = 0
	if arr[i] + 1 in dict1:
		op2 = dict1[arr[i] + 1]
	op1 += op2
	ans -= op1 * arr[i]
	if arr[i] in dict1:
		dict1[arr[i]] += 1
	else:
		dict1[arr[i]] = 1
for i in range(N - 1, -1, -1):
	op1 = 0
	if arr[i] - 1 in dict2:
		op1 = dict2[arr[i] - 1]
	op2 = 0
	if arr[i] + 1 in dict2:
		op2 = dict2[arr[i] + 1]
	op1 += op2
	ans += op1 * arr[i]
	if arr[i] in dict2:
		dict2[arr[i]] += 1
	else:
		dict2[arr[i]] = 1
print(ans)


from collections import *
n = int(input())
ar = [int(x) for x in input().split()]
s = 0
cnt = Counter()
s = ar[n - 1]
cnt[ar[n - 1]] = 1
fi = 0
j = n - 2
while 1:
	fi = fi + (s - (n - j - 1) * int(ar[j]) + cnt[int(ar[j]) - 1] - cnt[int(ar[j]) + 1])
	s = s + int(ar[j])
	cnt[int(ar[j])] = cnt[int(ar[j])] + 1
	j = j - 1
	if j < 0:
		break
print(fi)


from collections import Counter
from itertools import accumulate as acc
read = lambda : list(map(int, input().split()))
n = int(input())
x = read()
s = 0
ans = 0
c = Counter()
for (num, i) in enumerate(x):
	ans += (num - c[i - 1] - c[i + 1]) * i - (s - c[i - 1] * (i - 1) - c[i + 1] * (i + 1))
	c[i] += 1
	s += i
print(ans)


n = int(input())
list1 = list(map(int, input().split()))
x = 0
ans = 0
dic = {}
list2 = []
for i in range(n):
	list2.append(x)
	x += list1[n - 1 - i]
	dic[list1[i]] = dic.get(list1[i], 0) + 1
list2.reverse()
for i in range(n):
	ans += list2[i] - (n - 1 - i) * list1[i]
	ans -= dic.get(list1[i] + 1, 0)
	ans += dic.get(list1[i] - 1, 0)
	dic[list1[i]] -= 1
print(ans)


def almostDifference(nums):
	ht = {}
	result = 0
	prefix_sum = 0
	for (i, n) in enumerate(nums):
		ht.setdefault(n, 0)
		ht.setdefault(n - 1, 0)
		ht.setdefault(n + 1, 0)
		result -= prefix_sum
		result += n * i
		result -= ht[n - 1] * 1
		result -= ht[n + 1] * -1
		ht[n] += 1
		prefix_sum += n
	return result
_ = int(input())
nums = [int(x) for x in input().split()]
print(almostDifference(nums))


n = int(input())
ssum = 0
fans = 0
mp = {0: 0}
a = list(map(int, input().strip().split()))[:n]

def find(x):
	if mp.get(x):
		return mp[x]
	else:
		return 0
for i in range(n):
	if not mp.get(a[i]):
		mp[a[i]] = 0
	mp[a[i]] += 1
	fans += i * a[i] - ssum + find(a[i] + 1) - find(a[i] - 1)
	ssum += a[i]
print(fans)


n = int(input())
nums = list(map(int, input().split()))
cnt = {}
answer = 0
summ = 0
for (i, item) in enumerate(nums):
	cnt[item] = cnt.get(item, 0) + 1
	summ += item
	answer += (i + 1) * item - summ
	if item + 1 in cnt:
		answer += cnt[item + 1]
	if item - 1 in cnt:
		answer -= cnt[item - 1]
print(answer)


from collections import defaultdict
n = int(input())
a = list(map(int, input().strip().split()))
total = sum(a)
acnt = defaultdict(lambda : 0)
for _a in a:
	acnt[_a] += 1
ans = 0
for (i, _a) in enumerate(a):
	total -= _a
	acnt[_a] -= 1
	ans += total - (n - i - 1) * _a
	ans -= acnt[_a + 1]
	ans += acnt[_a - 1]
print(ans)


n = int(input())
a = list(map(int, input().split()))
sum = ans = 0
d = {}
for i in range(n)[::-1]:
	sum += a[i]
	if a[i] in d.keys():
		d[a[i]] += 1
	else:
		d[a[i]] = 1
	for j in range(a[i] - 1, a[i] + 2):
		if j in d.keys():
			ans += (a[i] - j) * d[j]
	ans -= a[i] * (n - i)
	ans += sum
print(ans)


n = int(input())
a = list(map(int, input().split()))
occ = {}
for i in a:
	occ[i] = occ.get(i, 0) + 1
s = sum(a)
ans = 0
j = n
for i in a:
	val = s
	nb_cnt = j
	if i - 1 > 0:
		val -= (i - 1) * occ.get(i - 1, 0)
		nb_cnt -= occ.get(i - 1, 0)
	val -= i * occ.get(i, 0)
	nb_cnt -= occ.get(i, 0)
	val -= (i + 1) * occ.get(i + 1, 0)
	nb_cnt -= occ.get(i + 1, 0)
	ans += val - i * nb_cnt
	occ[i] = occ[i] - 1
	s -= i
	j -= 1
print(ans)


def f(a):
	if a not in ma:
		ma[a] = 0
		mb[a] = 0
n = int(input())
x = list(map(int, input().split()))
(ma, mb) = (dict(), dict())
ans = 0
for i in range(n):
	ans += x[i] * i
	ans -= x[i] * (n - 1 - i)
	f(x[i])
	f(x[i] - 1)
	ma[x[i]] += 1
for i in range(n):
	ans += ma[x[i] - 1] - mb[x[i] - 1]
	ans -= mb[x[i] - 1]
	mb[x[i]] += 1
print(ans)


n = int(input())
v = list(map(int, input().split()))
mt = {}
sum = 0
ans = 0
for i in range(n - 1, -1, -1):
	if not v[i] in mt:
		mt[v[i]] = 0
	if not v[i] + 1 in mt:
		mt[v[i] + 1] = 0
	if not v[i] - 1 in mt:
		mt[v[i] - 1] = 0
	cnt = n - i - 1 - mt[v[i]] - mt[v[i] + 1] - mt[v[i] - 1]
	ans += sum - mt[v[i]] * v[i] - mt[v[i] + 1] * (v[i] + 1) - mt[v[i] - 1] * (v[i] - 1) - cnt * v[i]
	mt[v[i]] += 1
	sum += v[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
s = 0
mp = {}
for x in a:
	for i in range(-1, 2):
		mp[x + i] = 0
for i in range(1, n + 1):
	x = a[i - 1]
	s += x
	mp[x] += 1
	ans += i * x - s - (mp[x - 1] - mp[x + 1])
print(ans)


from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
mp = defaultdict(lambda : 0)
bp = defaultdict(lambda : 0)
b = [0 for i in range(n)]
for i in range(n):
	l = i - mp[v[i]] - mp[v[i] + 1] - mp[v[i] - 1]
	b[i] += l
	mp[v[i]] += 1
for i in range(n):
	l = i - bp[v[n - 1 - i]] - bp[v[n - 1 - i] - 1] - bp[v[n - 1 - i] + 1]
	b[n - 1 - i] -= l
	bp[v[n - 1 - i]] += 1
ans = 0
for i in range(n):
	ans += b[i] * v[i]
print(ans)


n = int(input())
tot = 0
ans = 0
cnt = {}
a = list(map(int, input().split()))
for i in range(1, n + 1):
	x = a[i - 1]
	ans += (i - 1) * x - tot
	if x - 1 in cnt:
		ans -= cnt[x - 1]
	if x + 1 in cnt:
		ans += cnt[x + 1]
	if x in cnt:
		cnt[x] += 1
	else:
		cnt[x] = 1
	tot += x
print(ans)


from collections import Counter
n = int(input())
l = list(map(int, input().split(' ')))
total = 0
presum = 0
for (count, value) in enumerate(l):
	total += value * count - presum
	presum += value
c = Counter(l)
for k in l:
	total += c[k - 1]
	total -= c[k + 1]
	c[k] -= 1
print(total)


a = int(input())
arr = list(map(int, input().split()))
d = dict()
summ = [0]
brr = arr
nd = dict()
mimpp = dict()
mimpn = dict()
for i in arr:
	summ.append(i + summ[len(summ) - 1])
	if i in d:
		d[i] = d[i] + 1
	else:
		d[i] = 1
for i in range(0, len(brr)):
	if brr[i] in nd:
		nd[brr[i]] = nd[brr[i]] + 1
	else:
		nd[brr[i]] = 1
	mimpn[i] = 0
	mimpp[i] = 0
	if brr[i] - 1 in d:
		mimpn[i] = mimpn[i] + d[brr[i] - 1]
	if brr[i] + 1 in d:
		mimpp[i] = mimpp[i] + d[brr[i] + 1]
	if brr[i] - 1 in nd:
		mimpn[i] = mimpn[i] - nd[brr[i] - 1]
	if brr[i] + 1 in nd:
		mimpp[i] = mimpp[i] - nd[brr[i] + 1]
ans = 0
ind = 0
su = sum(arr)
for i in range(0, len(arr)):
	ans = ans + su - summ[ind] - (a - ind) * arr[i]
	ans = ans + mimpn[i]
	ans = ans - mimpp[i]
	ind = ind + 1
print(ans)


n = int(input())
arr = [int(e) for e in input().split()]
m = {}
pref = 0
ans = 0
for i in arr:
	m[i] = 0
	m[i + 1] = 0
	m[i - 1] = 0
for i in range(len(arr)):
	ans += i * arr[i] - pref
	ans -= m[arr[i] - 1] - m[arr[i] + 1]
	pref += arr[i]
	m[arr[i]] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
ps = a[0]
ans = 0
h = {a[0]: 1}
hv = {a[0]: a[0]}

def gv(h, k):
	if k in h:
		return h[k]
	else:
		return 0
for i in range(1, n):
	c = i - gv(h, a[i]) - gv(h, a[i] - 1) - gv(h, a[i] + 1)
	cps = ps - gv(hv, a[i]) - gv(hv, a[i] - 1) - gv(hv, a[i] + 1)
	ans += a[i] * c - cps
	if a[i] not in h:
		h[a[i]] = 0
		hv[a[i]] = 0
	h[a[i]] += 1
	hv[a[i]] += a[i]
	ps += a[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
cnt = {}
ans = 0
sm = 0
i = n - 1
while i >= 0:
	if i != n - 1:
		ans = ans + sm - a[i] * (n - i - 1)
		if a[i] - 1 in cnt:
			ans = ans + cnt[a[i] - 1]
		if a[i] + 1 in cnt:
			ans = ans - cnt[a[i] + 1]
	sm = sm + a[i]
	if a[i] in cnt:
		cnt[a[i]] = cnt[a[i]] + 1
	else:
		cnt[a[i]] = 1
	i = i - 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
f = dict()
(s, val, ans) = (0, 0, 0)
for i in l:
	ans += i * (val - f.get(i - 1, 0) - f.get(i + 1, 0) - f.get(i, 0)) - (s - f.get(i - 1, 0) * (i - 1) - f.get(i + 1, 0) * (i + 1) - f.get(i, 0) * i)
	s += i
	val += 1
	f[i] = f.get(i, 0) + 1
print(ans)


import cProfile
import re
N = 200010
n = int(input())
a = [int(x) for x in input().split()]
s = 0
ans = 0
for (x, i) in zip(a, range(n)):
	ans += i * x - s
	s += x
m = dict()
for (x, i) in zip(a, range(n)):
	if x - 1 in m:
		ans -= m[x - 1]
	if x + 1 in m:
		ans += m[x + 1]
	if x in m:
		m[x] += 1
	else:
		m[x] = 1
print(ans)


import sys
from collections import defaultdict
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
summ = 0
ans = 0
cnt = defaultdict(int)
for i in range(n - 1, -1, -1):
	ans = ans + summ - (n - i - 1) * a[i] + cnt[a[i] - 1] - cnt[a[i] + 1]
	cnt[a[i]] += 1
	summ += a[i]
print(ans)


n = int(input())
vs = list(map(int, input().split()))
dc = {}
for x in vs:
	dc[x] = 0
for x in vs:
	dc[x] += 1
ans = 0
for i in range(n):
	ans += i * vs[i]
	ans -= (n - 1 - i) * vs[i]
for i in range(n):
	dc[vs[i]] -= 1
	try:
		ans -= dc[vs[i] + 1]
	except:
		pass
	try:
		ans += dc[vs[i] - 1]
	except:
		pass
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
d = {}
for i in range(n):
	ans += a[i] * i
	ans -= a[i] * (n - i - 1)
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
	if a[i] - 1 in d:
		ans -= d[a[i] - 1]
	if a[i] + 1 in d:
		ans += d[a[i] + 1]
print(ans)


import collections

def main():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	x = 0
	ct = collections.defaultdict(int)
	for i in range(n):
		x += a[i]
		ct[a[i]] += 1
		mul = i + 1
		sub = x
		for j in range(-1, 2):
			if a[i] + j in ct:
				num = ct[a[i] + j]
				mul -= num
				sub -= num * (a[i] + j)
		ans += a[i] * mul
		ans -= sub
	print(ans)
main()


from bisect import bisect

def main():
	n = int(input())
	an = [(i, int(s)) for (i, s) in enumerate(input().split())][:n]
	ans = sum((a * (-n + 1 + 2 * i) for (i, a) in an))
	group = {}
	for (i, a) in an:
		if a not in group:
			group[a] = []
		group[a].append(i)
	group = list(sorted(group.items(), key=lambda t: t[0]))
	for i in range(len(group) - 1):
		if group[i][0] + 1 == group[i + 1][0]:
			idx_s1 = group[i][1]
			idx_s2 = group[i + 1][1]
			for idx in idx_s1:
				smaller = bisect(idx_s2, idx)
				larger = len(idx_s2) - smaller
				ans = ans - larger + smaller
	print(ans)
main()


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
s = 0
m = {}
for i in range(n):
	if a[i] + 1 not in m:
		m[a[i] + 1] = 0
	if a[i] - 1 not in m:
		m[a[i] - 1] = 0
	ans += i * a[i] - s + m[a[i] + 1] - m[a[i] - 1]
	s += a[i]
	if a[i] not in m:
		m[a[i]] = 0
	m[a[i]] += 1
print(ans)


import sys
N = int(input())
a = []
b = {}
ans = 0
a = input().split()
for i in range(N):
	b[int(a[i])] = 0
	b[int(a[i]) - 1] = 0
	b[int(a[i]) + 1] = 0
for i in range(N):
	ans += int(a[i]) * (i - (N - 1 - i)) - (b[int(a[i]) - 1] - b[int(a[i]) + 1])
	b[int(a[i])] = b[int(a[i])] + 1
print(ans)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
(sum, ans, cnt) = (0, 0, defaultdict(int))
for i in range(n - 1, -1, -1):
	ans = ans + sum - (n - i - 1) * a[i] + cnt[a[i] - 1] - cnt[a[i] + 1]
	cnt[a[i]] += 1
	sum += a[i]
print(ans)


from itertools import accumulate

def cald(left, right):
	i = 0
	j = 0
	ans = 0
	l1 = len(left)
	l2 = len(right)
	while j < len(right):
		while i < l1 and left[i] < right[j]:
			i += 1
		ans += l1 - 2 * i
		j += 1
	return ans
n = int(input())
a = list(map(int, input().split()))
dict = {}
for i in range(n):
	if a[i] not in dict:
		dict[a[i]] = []
	dict[a[i]].append(i)
ks = list(dict.keys())
ans = 0
for x in ks:
	if x - 1 in dict:
		ans += cald(dict[x - 1], dict[x])
pre = list(accumulate(a))
for i in range(1, n):
	ans += i * a[i] - pre[i - 1]
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
sum1 = a[n - 1]
ans = 0
map1 = {}
map1[a[n - 1]] = 1
for i in range(n - 2, -1, -1):
	c1 = map1.get(a[i], 0)
	c2 = map1.get(a[i] + 1, 0)
	c3 = map1.get(a[i] - 1, 0)
	temp = sum1 - c1 * a[i] - c2 * (a[i] + 1) - c3 * (a[i] - 1)
	cnt2 = (n - 1 - i - c1 - c2 - c3) * a[i]
	ans += temp
	ans -= cnt2
	sum1 += a[i]
	if a[i] in map1:
		map1[a[i]] += 1
	else:
		map1[a[i]] = 1
print(ans)


pre = 0
ans = 0
n = int(input())
ain = input()
arr = ain.split(' ')
m = {}
for i in range(n):
	a = int(arr[i])
	ans += i * a - pre
	if a - 1 in m and m[a - 1] > 0:
		ans -= m[a - 1]
	if a + 1 in m and m[a + 1] > 0:
		ans -= m[a + 1] * -1
	pre += a
	if a in m:
		m[a] += 1
	else:
		m[a] = 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
(res, sum) = (0, a[0])
cnt = dict()
cnt[a[0]] = 1
for i in range(1, n):
	res += a[i] * i - sum
	sum += a[i]
	if a[i] - 1 in cnt:
		res -= cnt[a[i] - 1]
	if a[i] + 1 in cnt:
		res += cnt[a[i] + 1]
	if a[i] not in cnt:
		cnt[a[i]] = 1
	else:
		cnt[a[i]] += 1
print(res)


from sys import stdin, stdout
n = int(stdin.readline())
A = [int(x) for x in stdin.readline().split()]
Map = {}
s = 0
pres = 0
for (index, element) in enumerate(A):
	s += element * index - pres
	pres += element
	if element - 1 in Map:
		s -= Map[element - 1]
	if element + 1 in Map:
		s += Map[element + 1]
	if element in Map:
		Map[element] += 1
	else:
		Map[element] = 1
stdout.write('%d' % s)


n = int(input())
a = list(map(int, input().split()))
cnt = dict()

def get(x):
	global cnt
	if x in cnt:
		return cnt[x]
	return 0

def inc(x):
	global cnt
	if x in cnt:
		cnt[x] += 1
		return
	cnt[x] = 1
s = 0
ans = 0
for i in range(n):
	ans += i * a[i] - s - get(a[i] - 1) + get(a[i] + 1)
	s += a[i]
	inc(a[i])
print(ans)


def main():
	n = int(input())
	v = [int(x) for x in input().split()]
	ans = 0
	s = 0
	mp = {}
	for i in range(0, n):
		l = 0
		if v[i] - 1 in mp:
			l = mp[v[i] - 1]
		r = 0
		if v[i] + 1 in mp:
			r = mp[v[i] + 1]
		ans = ans + i * v[i] - s - l + r
		s = s + v[i]
		x = 0
		if v[i] in mp:
			x = mp[v[i]]
			del mp[v[i]]
		mp[v[i]] = x + 1
	print(ans)
main()


summ = 0
glob = 0
N = int(input())
a = {}
cnt = 0
huh = list(map(int, input().split()))
for i in huh:
	if i - 1 not in a:
		a[i - 1] = 0
	if i + 1 not in a:
		a[i + 1] = 0
	if i not in a:
		a[i] = 0
	glob += (cnt - a[i - 1] - a[i + 1]) * i - (summ - a[i - 1] * (i - 1) - a[i + 1] * (i + 1))
	a[i] += 1
	summ += i
	cnt += 1
print(glob)


n = input()
ar = list(map(int, input().split()))
sum = 0
pref = {}
for i in ar:
	pref[i] = 0
	pref[i - 1] = 0
	pref[i + 1] = 0
ans = 0
k = 0
for i in ar:
	ans += k * i - sum - pref[i - 1] + pref[i + 1]
	pref[i] += 1
	sum += i
	k += 1
print(ans)


tcase = int(input().strip())
li = list(map(lambda x: int(x), input().split()))
ans = 0
sum = li[0]
di = {}
di[sum] = 1
i = 1
for x in li[1:]:
	if x + 1 in di:
		df = di[x + 1]
	else:
		df = 0
	if x - 1 in di:
		da = di[x - 1]
	else:
		da = 0
	ans += i * x - sum + df - da
	sum += x
	i += 1
	if x in di:
		di[x] += 1
	else:
		di[x] = 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = dict()
s = 0
ans = 0
for i in a:
	m[i] = 0
	m[i - 1] = 0
	m[i + 1] = 0
for i in range(n - 1, -1, -1):
	ans += s - cnt * a[i]
	for j in range(-1, 2):
		ans -= m[a[i] + j] * (a[i] + j - a[i])
	s += a[i]
	m[a[i]] += 1
	cnt += 1
print(ans)


from collections import defaultdict
n = int(input())
a1 = list(map(int, input().split()))
p = [0 for _ in range(n + 1)]
a = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
	a[i] = a1[i - 1]
for i in range(1, n + 1):
	p[i] = p[i - 1] + a[i]
ans = 0
for i in range(1, n):
	ans = ans + p[n] - 2 * p[i]
c = 0
d = defaultdict(int)
d[a[n]] += 1
for i in range(n - 1, 0, -1):
	d[a[i]] += 1
	if d[a[i] + 1] > 0:
		ans -= d[a[i] + 1]
	if d[a[i] - 1] > 0:
		ans += d[a[i] - 1]
print(ans)


input()
a = 0
b = 0
c = 0
d = dict()
e = dict()
for i in list(map(int, input().split())):
	(x, y) = (0, 0)
	for j in range(i - 1, i + 2):
		if j in d:
			x += d[j]
			y += e[j]
	a += (c - y) * i - b + x
	b += i
	c += 1
	d[i] = i if i not in d else d[i] + i
	e[i] = 1 if i not in e else e[i] + 1
print(a)


n = int(input())
a = list(map(int, input().split()))
M = dict()
ans = 0
for i in range(n):
	M[a[i]] = M[a[i] - 1] = M[a[i] + 1] = 0
S = 0
for i in range(n - 1, -1, -1):
	y = a[i]
	c = n - i - 1 - M[y - 1] - M[y] - M[y + 1]
	ans += S - (y + 1) * M[y + 1] - (y - 1) * M[y - 1] - y * M[y] - c * y
	M[y] += 1
	S += y
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = dict()
s = 0
ans = 0
cnt = 0
for i in range(n):
	mp = m.get(a[i] + 1, 0)
	mm = m.get(a[i] - 1, 0)
	ans += cnt * a[i] - s + mp - mm
	m.update({a[i]: m.get(a[i], 0) + 1})
	s += a[i]
	cnt += 1
print(ans)


n = int(input())
s = input().split()
a = [int(i) for i in s]
m1 = {}
m2 = {}
sum = 0

def get(m, a):
	if a in m:
		return m[a]
	else:
		return 0
ans = 0
for i in range(n):
	ans += i * a[i] - sum + get(m1, a[i]) - get(m2, a[i])
	if not a[i] - 1 in m1:
		m1[a[i] - 1] = 0
	if not a[i] + 1 in m2:
		m2[a[i] + 1] = 0
	m1[a[i] - 1] += 1
	m2[a[i] + 1] += 1
	sum += a[i]
print(ans)


n = int(input())
sum = 0
res = 0
v = [int(x) for x in input().split()]
m = {}
for i in range(n - 1, -1, -1):
	sum += v[i]
	cur = n - i
	if m.get(v[i]):
		m[v[i]] += 1
	else:
		m[v[i]] = 1
	cursum = sum - m[v[i]] * v[i]
	cur -= m[v[i]]
	if m.get(v[i] - 1):
		cursum -= m[v[i] - 1] * (v[i] - 1)
		cur -= m[v[i] - 1]
	if m.get(v[i] + 1):
		cursum -= m[v[i] + 1] * (v[i] + 1)
		cur -= m[v[i] + 1]
	res += cursum - v[i] * cur
print(res)


n = int(input())
a = [int(x) for x in input().split()]
s = 0
total = 0
cnt = {}
for i in reversed(range(n)):
	s += a[i]
	if a[i] not in cnt:
		cnt[a[i]] = 0
	cnt[a[i]] += 1
	total += s - (n - i) * a[i]
	if a[i] + 1 in cnt:
		total -= cnt[a[i] + 1]
	if a[i] - 1 in cnt:
		total += cnt[a[i] - 1]
print(total)


n = int(input())
ar = list(map(int, input().split()))
rev = ar[::-1]
from collections import Counter

def d(ar):
	me = Counter()
	s = 0
	for i in range(n):
		s += i * ar[i]
		s -= me[ar[i]] + me[ar[i] + 1] * ar[i] + me[ar[i] - 1] * ar[i]
		me[ar[i]] += 1
	return s
print(d(ar) - d(rev))


def main():
	n = int(input())
	nums = list(map(int, input().split()))
	count = {}
	curr_sum = 0
	res = 0
	for i in range(n):
		res += i * nums[i] - curr_sum
		if nums[i] - 1 in count:
			res -= count[nums[i] - 1]
		if nums[i] + 1 in count:
			res += count[nums[i] + 1]
		curr_sum += nums[i]
		if nums[i] not in count:
			count[nums[i]] = 0
		count[nums[i]] += 1
	print(res)
main()


from collections import defaultdict
n = input()
a = list(map(int, input().split()))

def solve(a):
	sum = a[0]
	res = 0
	size = 1
	counter = defaultdict(int)
	counter[a[0]] += 1
	for el in a[1:]:
		counter[el] += 1
		res = res - sum + size * el
		res = res - counter[el - 1] + counter[el + 1]
		size += 1
		sum += el
	return res
print(solve(a))


n = int(input().strip())
arr = [int(i) for i in input().strip().split(' ')]
dic = {arr[0]: 1}
ic = [0 for i in range(n)]
isu = [0 for i in range(n)]
pre = [arr[0]]
for i in range(1, n):
	pre.append(pre[i - 1] + arr[i])
for i in range(1, n):
	(ici, isi) = (0, 0)
	if arr[i] in dic:
		ici += dic[arr[i]]
		isi += arr[i] * dic[arr[i]]
	if arr[i] - 1 in dic:
		ici += dic[arr[i] - 1]
		isi += (arr[i] - 1) * dic[arr[i] - 1]
	if arr[i] + 1 in dic:
		ici += dic[arr[i] + 1]
		isi += (arr[i] + 1) * dic[arr[i] + 1]
	(ic[i], isu[i]) = (ici, isi)
	if arr[i] in dic:
		dic[arr[i]] += 1
	else:
		dic[arr[i]] = 1
ans = 0
for i in range(1, n):
	ans += arr[i] * i - pre[i - 1] - ic[i] * arr[i] + isu[i]
print(ans)


n = int(input())
a = input().split(' ')
for i in range(n):
	a[i] = int(a[i])
ans = 0
sum = 0
m = dict()
for i in range(n):
	m[a[i]] = m.get(a[i], 0) + 1
	sum += a[i]
	ans += (i + 1) * a[i] - sum
	ans -= m.get(a[i] + 1, 0) * -1
	ans -= m.get(a[i] - 1, 0)
print(ans)


n = int(input())
res = 0
sum = 0
qua = 0
m = dict()
a = list(map(int, input().split()))
for i in range(0, n):
	if m.get(a[i] - 1) == None:
		m[a[i] - 1] = 0
	if m.get(a[i] + 1) == None:
		m[a[i] + 1] = 0
	if m.get(a[i]) == None:
		m[a[i]] = 0
	res += a[i] * (qua - m[a[i] - 1] - m[a[i]] - m[a[i] + 1]) - (sum - (a[i] - 1) * m[a[i] - 1] - a[i] * m[a[i]] - (a[i] + 1) * m[a[i] + 1])
	sum += a[i]
	qua += 1
	m[a[i]] += 1
print(res)


n = int(input())
s = input().split()
a = [int(x) for x in s]
p = [0 for i in range(len(a) + 1)]
m = {}

def get(ai):
	if ai in m:
		return m[ai]
	return 0
i = 0
for ai in a:
	p[i + 1] = p[i] + ai
	if ai in m:
		m[ai] += 1
	else:
		m[ai] = 1
	i += 1
i = n - 1
ans = 0
for ai in reversed(a):
	ans += i * ai - p[i] - get(ai - 1) + get(ai + 1)
	m[ai] -= 1
	i -= 1
print(ans)


n = input()
mp = list(map(int, input().split()))
sum = 0
ans = 0
cnt = 0
tt = dict()
for i in mp:
	sum += i
	cnt = cnt + 1
	ans += cnt * i - sum
	if i - 1 in tt:
		ans -= tt[i - 1]
	if i + 1 in tt:
		ans += tt[i + 1]
	if i not in tt:
		tt[i] = 0
	tt[i] = tt[i] + 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
count = {}
cum = 0
tot = 0
for i in range(0, n):
	tot = tot + i * a[i] - cum
	if a[i] - 1 in count:
		tot = tot - count[a[i] - 1]
	if a[i] + 1 in count:
		tot = tot + count[a[i] + 1]
	if a[i] in count:
		count[a[i]] = count[a[i]] + 1
	else:
		count[a[i]] = 1
	cum = cum + a[i]
print(tot)


from collections import Counter
n = int(input())
A = [int(x) for x in input().split()]
C = [0] + A[:]
for i in range(n):
	C[i + 1] += C[i]
M = Counter()
ans = 0
for i in range(n):
	ans += i * A[i] - C[i]
	ans -= M[A[i] - 1]
	ans += M[A[i] + 1]
	M[A[i]] += 1
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = map(int, input().split())
d = {}
ans = sum = num = 0
for x in a:
	t = x * num - sum
	if x - 1 not in d:
		d[x - 1] = 0
	if x + 1 not in d:
		d[x + 1] = 0
	if x not in d:
		d[x] = 0
	t -= d[x - 1]
	t += d[x + 1]
	d[x] += 1
	num += 1
	sum += x
	ans += t
print(ans)


n = int(input())
a = list(map(int, input().split()))
q1 = dict()
ans = 0
for i in range(n):
	if a[i] not in q1:
		q1[a[i]] = 1
	else:
		q1[a[i]] += 1
	cur = q1[a[i]]
	if a[i] + 1 in q1:
		cur += q1[a[i] + 1]
	if a[i] - 1 in q1:
		cur += q1[a[i] - 1]
	ans += a[i] * (i - cur + 1)
q2 = dict()
for j in range(n):
	i = n - j - 1
	if a[i] not in q2:
		q2[a[i]] = 1
	else:
		q2[a[i]] += 1
	cur = q2[a[i]]
	if a[i] + 1 in q2:
		cur += q2[a[i] + 1]
	if a[i] - 1 in q2:
		cur += q2[a[i] - 1]
	ans -= a[i] * (j - cur + 1)
print(ans)


def bnyk(x):
	if x in freq.keys():
		return freq[x]
	else:
		return 0
freq = {}
n = int(input())
list = input().split()
ans = 0
ttl = 0
for i in range(n):
	x = int(list[i])
	a = bnyk(x - 1)
	b = bnyk(x)
	c = bnyk(x + 1)
	ans += x * (i - a - b - c) - (ttl - (x - 1) * a - x * b - (x + 1) * c)
	ttl += x
	if x in freq.keys():
		freq[x] += 1
	else:
		freq[x] = 1
print('%d\n' % ans)


vcnt = {}
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(0, n):
	ans += a[i] * (i * 2 + 1 - n)
for i in range(0, n):
	v = a[i]
	if v - 1 in vcnt:
		ans -= vcnt[v - 1]
	if v + 1 in vcnt:
		ans += vcnt[v + 1]
	if not v in vcnt:
		vcnt[v] = 1
	else:
		vcnt[v] += 1
print(ans)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
cnt = defaultdict(int)
(res, pref) = (0, 0)
for i in range(n):
	(x, y, z) = (cnt[a[i] - 1], cnt[a[i]], cnt[a[i] + 1])
	res += a[i] * (i - (x + y + z)) - pref + (a[i] - 1) * x + a[i] * y + (a[i] + 1) * z
	pref += a[i]
	cnt[a[i]] += 1
print(res)


from copy import deepcopy
n = int(input())
a = list(map(int, input().split()))
sm = 0
k = n - 1
for i in a[:n - 1]:
	sm -= k * int(i)
	k -= 1
k = n - 1
for i in range(n - 1, 0, -1):
	sm += k * int(a[i])
	k -= 1
m = {}
for i in range(0, n):
	m[a[i]] = m.get(a[i], 0) + 1
for i in range(n - 1):
	m[a[i]] = m.get(a[i], 0) - 1
	sm -= m.get(a[i] + 1, 0)
	sm += m.get(a[i] - 1, 0)
print(sm)


n = int(input())
a = [int(x) for x in input().split(' ')]

def init_map():
	mp = {}
	for x in a:
		mp[x] = mp[x + 1] = mp[x - 1] = 0
	return mp
mp = init_map()
result = 0
for (m, v) in enumerate(a):
	result += v * (m - mp[v] - mp[v - 1] - mp[v + 1])
	mp[v] += 1
mp = init_map()
for (m, v) in enumerate(a[::-1]):
	result -= v * (m - mp[v] - mp[v - 1] - mp[v + 1])
	mp[v] += 1
print(result)


n = int(input())
arr = list(map(int, input().split()))
n -= 1
ans = 0
for num in arr:
	ans += n * num
	n -= 2
ans = -ans
dic = {num: 0 for num in arr}
for i in range(len(arr)):
	dic[arr[i]] += 1
	if arr[i] - 1 in dic:
		ans -= dic[arr[i] - 1]
	if arr[i] + 1 in dic:
		ans += dic[arr[i] + 1]
print(ans)


import bisect

def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
n = int(input())
a = list(map(int, input().split()))
h = dict()
tot = 0
mul = -(n - 1)
for i in range(n):
	tot += mul * a[i]
	mul += 2
for i in range(n):
	if a[i] in h:
		h[a[i]] += 1
	else:
		h[a[i]] = 1
	if a[i] - 1 in h:
		tot -= h[a[i] - 1]
	if a[i] + 1 in h:
		tot += h[a[i] + 1]
print(tot)


dic = {}
n = int(input())
arr = [int(x) for x in input().split()]
for x in arr:
	if x not in dic:
		dic[x] = 1
	else:
		dic[x] += 1
total = 0
su = 0
for x in arr:
	su += x
for x in range(len(arr)):
	su -= arr[x]
	hold = 0
	cnt = n - x - 1
	for y in range(-1, 2):
		num = arr[x] + y
		if num in dic:
			hold += dic[num] * num
			cnt -= dic[num]
	dic[arr[x]] -= 1
	hold -= arr[x]
	cnt += 1
	su -= hold
	total += su - arr[x] * cnt
	su += hold
print(total)


N = int(input())
A = [int(s) for s in input().split()]
D = {}
ans = 0
sm = 0
for i in range(N):
	a = A[i]
	x = i
	y = sm
	for b in (a - 1, a, a + 1):
		if b in D:
			x -= D[b]
			y -= b * D[b]
	ans += a * x
	ans -= y
	if a in D:
		D[a] += 1
	else:
		D[a] = 1
	sm += a
print(ans)


N = 2 * 10 ** 5 + 3
n = int(input())
(A, cnt) = (list(map(int, input().split(' '))), {})
(s, a) = (0, 0)
for i in range(n - 1, -1, -1):
	a += s
	if A[i] - 1 in cnt:
		a += cnt[A[i] - 1]
	if A[i] + 1 in cnt:
		a -= cnt[A[i] + 1]
	a -= (n - (i + 1)) * A[i]
	s += A[i]
	if A[i] not in cnt:
		cnt[A[i]] = 0
	cnt[A[i]] += 1
print(a)


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
ans = 0
s = a[0]
f = {a[0]: 1}
for i in range(1, n):
	if a[i] in f:
		f[a[i]] += 1
	else:
		f[a[i]] = 1
	ans += i * a[i] - s
	s += a[i]
	if a[i] + 1 in f:
		ans += f[a[i] + 1]
	if a[i] - 1 in f:
		ans -= f[a[i] - 1]
print(ans)


n = int(input())
v = [int(x) for x in input().split()]
mp = {}
s = sum(v)
ans = 0
cnt = n
for i in range(n):
	if v[i] in mp:
		mp[v[i]] += 1
	else:
		mp[v[i]] = 1
for i in range(n):
	c = v[i]
	s -= c
	cnt -= 1
	ans += s - cnt * c
	ans -= mp.get(c + 1, 0)
	ans += mp.get(c - 1, 0)
	mp[c] -= 1
print(ans)


from collections import *
input()
s = k = 0
d = defaultdict(int)
for (i, q) in enumerate(map(int, input().split())):
	k += i * q - s + d[q + 1] - d[q - 1]
	s += q
	d[q] += 1
print(k)


n = int(input())
lis = input().split()
a = list()
sum = [0]
dic = dict()
for i in range(n):
	a.append(int(lis[i]))
	sum.append(sum[i] + a[i])
	dic[a[i]] = 0
ans = 0
for i in range(n):
	ans = ans + (i * a[i] - sum[i])
	if a[i] - 1 in dic.keys():
		ans = ans - dic[a[i] - 1]
	if a[i] + 1 in dic.keys():
		ans = ans + dic[a[i] + 1]
	dic[a[i]] = dic[a[i]] + 1
print(ans)


n = int(input())
nums = list(map(int, input().split()))
pref = [0] * (n + 1)
for i in range(n):
	pref[i + 1] = pref[i] + nums[i]
counter = dict()
answer = 0
counter[nums[0]] = 1
for i in range(1, n):
	answer += nums[i] * i - pref[i]
	answer -= counter.get(nums[i] - 1, 0)
	answer += counter.get(nums[i] + 1, 0)
	counter[nums[i]] = counter.get(nums[i], 0) + 1
print(answer)


n = int(input())
l = list(map(int, input().split()))
d = dict()
su = 0
ans = 0
for i in range(n):
	if l[i] in d:
		d[l[i]] += 1
	else:
		d.update({l[i]: 1})
	c = 0
	c1 = 0
	j = l[i]
	if j + 1 in d:
		c = d[j + 1]
	if j - 1 in d:
		c1 = d[j - 1]
	ans += i * l[i] - su + c - c1
	su += l[i]
print(ans)


n = int(input())
ans = 0
s = {}
for (i, a) in enumerate(map(int, input().split())):
	ans += a * i - a * (n - 1 - i) + s.get(a + 1, 0) - s.get(a - 1, 0)
	s[a] = s.get(a, 0) + 1
print(ans)


n = int(input())
ct = {}
sm = 0
ans = 0
arr = list(map(int, input().split()))
for i in range(0, n):
	ans += arr[i] * i - sm
	ans -= ct.get(arr[i] - 1, 0)
	ans += ct.get(arr[i] + 1, 0)
	sm += arr[i]
	ct[arr[i]] = ct.get(arr[i], 0) + 1
print(ans)


from sys import *
n = int(stdin.readline())
a = list(map(int, stdin.read().split()))
freq = {}
ans = 0
psum = 0
for i in range(len(a)):
	psum += a[i]
	ans += (i + 1) * a[i] - psum
	if a[i] in freq:
		freq[a[i]] += 1
	else:
		freq[a[i]] = 1
	if a[i] + 1 in freq:
		ans -= (a[i] - (a[i] + 1)) * freq[a[i] + 1]
	if a[i] - 1 in freq:
		ans -= (a[i] - (a[i] - 1)) * freq[a[i] - 1]
print(ans)


def get_int_list(string):
	ls = []
	sum = ''
	for s in string:
		if s == ' ':
			ls.append(int(sum))
			sum = ''
		else:
			sum += s
	ls.append(int(sum))
	return ls

def extras(d, num):
	plus = minus = 0
	if num + 1 in d:
		plus = d[num + 1]
	if num - 1 in d:
		minus = d[num - 1]
	return plus - minus

def get_ans(ls, n):
	d = {}
	sum = 0
	k = 0
	for i in ls:
		k += 1
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
		sum += k * i - (n + 1 - k) * i + extras(d, i)
	return sum
n = int(input())
x = input()
ls = get_int_list(x)
print(get_ans(ls, n))


n = int(input())
a = [int(x) for x in input().split()]
l = {}
s = 0
for i in range(n):
	x = a[i]
	if l.get(x, 'none') == 'none':
		l[x] = 1
	else:
		l[x] = l[x] + 1
	s += i * x - (n - 1 - i) * x
	if l.get(x + 1, 'none') != 'none':
		s += l[x + 1]
	if l.get(x - 1, 'none') != 'none':
		s -= l[x - 1]
print(s)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
map = dict()
for i in range(0, n):
	ans += (i - map.get(a[i], 0) - map.get(a[i] - 1, 0) - map.get(a[i] + 1, 0)) * a[i]
	map[a[i]] = map.get(a[i], 0) + 1
map = dict()
for i in range(n - 1, -1, -1):
	ans -= (n - i - 1 - map.get(a[i], 0) - map.get(a[i] - 1, 0) - map.get(a[i] + 1, 0)) * a[i]
	map[a[i]] = map.get(a[i], 0) + 1
print(ans)


import sys
n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
cnt = {}
for i in range(n):
	m = i
	tmp = s
	for j in range(a[i] - 1, a[i] + 2):
		if j in cnt:
			m -= cnt[j]
			tmp -= cnt[j] * j
	ans += m * a[i] - tmp
	s += a[i]
	if a[i] in cnt:
		cnt[a[i]] += 1
	else:
		cnt[a[i]] = 1
print(ans)


dic = {}
n = int(input())
sum1 = 0
a = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
	try:
		dic[a[i]] += 1
	except:
		dic[a[i]] = 1
	sum1 += a[i] * (-n + 1 + 2 * i)
	try:
		sum1 -= dic[a[i] + 1]
	except:
		pass
	try:
		sum1 += dic[a[i] - 1]
	except:
		pass
print(sum1)


n = int(input())
nums = list(map(int, input().strip().split()))
count = {}
ans = 0
ssum = 0
for (i, num) in enumerate(nums[::-1]):
	ans += ssum - i * num
	if num + 1 in count:
		ans -= count[num + 1]
	if num - 1 in count:
		ans += count[num - 1]
	ssum += num
	if num in count:
		count[num] += 1
	else:
		count[num] = 1
print(ans)


cnt = {}
ans = 0
n = int(input())
inp = [int(i) for i in input().split()]
sum = 0
for i in range(n):
	x = inp[i]
	if x not in cnt.keys():
		cnt[x] = 0
	if x - 1 not in cnt.keys():
		cnt[x - 1] = 0
	if x + 1 not in cnt.keys():
		cnt[x + 1] = 0
	minus = cnt[x - 1] * (x - 1) + cnt[x + 1] * (x + 1) + cnt[x] * x
	cnt_x = i - cnt[x - 1] - cnt[x + 1] - cnt[x]
	ans += cnt_x * x - (sum - minus)
	cnt[x] += 1
	sum += x
print(ans)


from collections import Counter, defaultdict, deque, namedtuple
from math import gcd
import sys

def read_ints():
	return [int(token) for token in input().split()]

def read_tokens():
	return input().split()

def main():
	n = read_ints()[0]
	a = read_ints()
	(total, running, counts) = (0, 0, dict())
	for (i, y) in enumerate(a):
		total += i * y - running - counts.get(y - 1, 0)
		total += counts.get(y + 1, 0)
		running += y
		counts[y] = counts.get(y, 0) + 1
	print(total)
main()


n = input()
a = input()
n = int(n)
import collections
l = list(map(int, a.split(' ')))
for i in range(0, int(n) - 1):
	l[i] = int(l[i])
cnt = collections.Counter()
cnt[l[0]] += 1
b = list()
b.append(l[0])
ans = 0
for i in range(1, n):
	b.append(int(b[i - 1] + l[i]))
for i in range(1, n):
	v1 = cnt[l[i]]
	v2 = cnt[l[i] + 1]
	v3 = cnt[l[i] - 1]
	ans = ans + ((i - v1 - v2 - v3) * l[i] - (b[i - 1] - v1 * l[i] - v2 * (l[i] + 1) - v3 * (l[i] - 1)))
	cnt[l[i]] += 1
print(ans)


n = int(input())
num = list(map(int, input().split()))
cnt = {}
cursum = 0
ans = 0
for i in range(n):
	ans += num[i] * i - cursum
	if num[i] - 1 in cnt:
		ans -= cnt[num[i] - 1]
	if num[i] + 1 in cnt:
		ans += cnt[num[i] + 1]
	cursum += num[i]
	if num[i] not in cnt:
		cnt[num[i]] = 0
	cnt[num[i]] += 1
print(ans)


d = {}
n = int(input())
arr = list(map(int, input().split()))
prefix = [0 for i in range(n)]
prefix[0] = arr[0]
for i in range(1, n):
	prefix[i] = prefix[i - 1] + arr[i]
for i in range(1, n):
	try:
		d[arr[i]] += 1
	except:
		d[arr[i]] = 1
s = 0
for i in range(n - 1):
	cnt = 0
	minus = 0
	if arr[i] in d:
		cnt += d[arr[i]]
		minus = minus + d[arr[i]] * arr[i]
	if arr[i] + 1 in d:
		cnt += d[arr[i] + 1]
		minus = minus + d[arr[i] + 1] * (arr[i] + 1)
	if arr[i] - 1 in d:
		minus = minus + d[arr[i] - 1] * (arr[i] - 1)
		cnt += d[arr[i] - 1]
	s = s + prefix[n - 1] - prefix[i] - minus - (n - i - 1 - cnt) * arr[i]
	if arr[i + 1] in d:
		if d[arr[i + 1]] == 1:
			d.pop(arr[i + 1])
		else:
			d[arr[i + 1]] -= 1
print(s)


n = int(input())
a = list(map(int, input().split()))
s = 0
mx = a[0]
dic = dict()
for i in range(n):
	dic[a[i]] = 0
for i in range(n):
	s = s - a[i] * (n - i - 1) + a[i] * i
	if a[i] - 1 in dic:
		s = s + dic[a[i] - 1] * (a[i] - 1 - a[i])
	if a[i] + 1 in dic:
		s = s + dic[a[i] + 1] * (a[i] + 1 - a[i])
	d = dic[a[i]] + 1
	t = {a[i]: d}
	dic.update(t)
print(s)


n = int(input())
a = list(map(int, input().split()))
s = 0
ret = 0
mp = {}
for i in range(len(a)):
	ret += a[i] * i - s
	if a[i] - 1 in mp:
		ret -= mp[a[i] - 1]
	if a[i] + 1 in mp:
		ret += mp[a[i] + 1]
	if a[i] in mp:
		mp[a[i]] += 1
	else:
		mp[a[i]] = 1
	s += a[i]
print(ret)


n = int(input())
a = list(map(int, input().split(' ')))
x = 0
for i in range(int(n / 2)):
	j = n - 1 - i
	x += (a[j] - a[i]) * (j - i)
m = {}
for i in range(n):
	if a[i] in m:
		m[a[i]] += 1
	else:
		m[a[i]] = 1
	if a[i] + 1 in m:
		x += m[a[i] + 1]
	if a[i] - 1 in m:
		x -= m[a[i] - 1]
print(x)


n = int(input())
a = list(map(int, input().split(' ')))
b = {}
ans = 0
for i in range(0, n):
	if a[i] - 1 in b:
		ans -= b[a[i] - 1]
	if a[i] + 1 in b:
		ans += b[a[i] + 1]
	if a[i] in b.keys():
		b[a[i]] += 1
	else:
		b[a[i]] = 1
k = n - 1
for i in range(0, int(n / 2)):
	ans += k * (a[n - 1 - i] - a[i])
	k -= 2
print(ans)


n = int(input())
v = list(map(int, input().split()))
m = {}
res = 0
for i in v:
	if not i in m:
		m[i] = 0
	m[i] += 1
k = v.copy()
for i in range(n - 1, 0, -1):
	k[i - 1] = k[i] + k[i - 1]
for i in range(0, n - 1):
	res += -(n - i - 1) * v[i] + k[i + 1]
	m[v[i]] -= 1
	if v[i] + 1 in m:
		res -= m[v[i] + 1]
	if v[i] - 1 in m:
		res += m[v[i] - 1]
print(res)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split(' ')))
S1 = defaultdict(int)
S2 = defaultdict(int)
for i in range(1, N):
	S2[A[i]] += 1
res = 0
for i in range(N):
	res += i * A[i]
	res -= (N - i - 1) * A[i]
	res -= (S1[A[i] - 1] + S1[A[i]] + S1[A[i] + 1]) * A[i]
	res += (S2[A[i] - 1] + S2[A[i]] + S2[A[i] + 1]) * A[i]
	S1[A[i]] += 1
	if i < N - 1:
		S2[A[i + 1]] -= 1
print(res)


n = int(input())
x = n
L = [int(i) for i in input().strip().split(' ')]
d = {}
for u in L:
	d[str(u)] = 0
	d[str(u + 1)] = 0
	d[str(u - 1)] = 0
CS = 0
Al = 0
i = 0
for j in L:
	d[str(j)] = d[str(j)] + 1
	(x, y) = (j - 1, j + 1)
	L = d[str(x)]
	A = d[str(y)]
	CS += j * i - Al - L + A
	Al += j
	i += 1
print(CS)


from collections import defaultdict
input()
(m, s, ans) = (defaultdict(int), 0, 0)
for (i, a) in enumerate(map(int, input().split())):
	ans += a * i - s - m[a - 1] + m[a + 1]
	s += a
	m[a] += 1
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
n = int(input())
mp = {}
F = [0] * 200009
F = list(map(int, input().split()))
ans = 0
see = -(n - 1)
for i in range(n):
	ans = ans + see * F[i]
	see = see + 2
for i in range(n):
	j = n - i - 1
	gN = mp.get(F[j] + 1)
	if gN == None:
		gN = 0
	lN = mp.get(F[j] - 1)
	if lN == None:
		lN = 0
	ans = ans + lN - gN
	val = mp.get(F[j])
	if val == None:
		val = 0
	val = val + 1
	mp[F[j]] = val
print(ans)


cnt = {}
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
for i in range(0, n):
	x = a[i]
	sum += x
	if not x in cnt:
		cnt[x] = 0
	if not x + 1 in cnt:
		cnt[x + 1] = 0
	if not x - 1 in cnt:
		cnt[x - 1] = 0
	cnt[x] += 1
	ans += (i + 1 - cnt[x] - cnt[x - 1] - cnt[x + 1]) * x - (sum - cnt[x] * x - cnt[x + 1] * (x + 1) - cnt[x - 1] * (x - 1))
print(ans)


def almost_difference():
	n = int(input())
	if n == 1:
		return 0
	dict_equal = dict()
	array = [int(el) for el in input().split()]
	ad_sum = 0
	prev_sum = 0
	for i in range(n):
		if not array[i] in dict_equal.keys():
			dict_equal[array[i]] = 0
		if not array[i] - 1 in dict_equal.keys():
			dict_equal[array[i] - 1] = 0
		if not array[i] + 1 in dict_equal.keys():
			dict_equal[array[i] + 1] = 0
		ad_sum = ad_sum + i * array[i] - prev_sum + dict_equal[array[i] + 1] - dict_equal[array[i] - 1]
		dict_equal[array[i]] += 1
		prev_sum += array[i]
	return ad_sum
print(almost_difference())


d = {}
n = int(input())
arr = list(map(int, input().split()))
res = 0
summ = 0
for i in range(0, n):
	if arr[i] in d:
		d[arr[i]] = d[arr[i]] + 1
	else:
		d[arr[i]] = 1
	res += i * arr[i] - summ
	if arr[i] + 1 in d:
		res += d[arr[i] + 1]
	if arr[i] - 1 in d:
		res -= d[arr[i] - 1]
	summ += arr[i]
print(res)


import sys

def main():
	N = int(input())
	A = list(map(int, input().split()))
	cnt = dict()
	pref = 0
	ans = 0
	for i in range(N):
		v = A[i]
		cnt[v - 1] = cnt.get(v - 1, 0)
		cnt[v] = cnt.get(v, 0)
		cnt[v + 1] = cnt.get(v + 1, 0)
		add = pref - (v - 1) * cnt[v - 1] - v * cnt[v] - (v + 1) * cnt[v + 1]
		num_pairs = i - cnt[v - 1] - cnt[v] - cnt[v + 1]
		add -= v * num_pairs
		ans -= add
		pref += v
		cnt[v] += 1
	print(ans)
main()


import sys
from collections import defaultdict
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().strip().split()))
psum = 0
counter = defaultdict(int)
result = 0
for i in range(n):
	counter[a[i]] += 1
	psum += a[i]
	result += (i + 1) * a[i] - psum
	result -= counter[a[i] - 1] - counter[a[i] + 1]
print(result)


import bisect
src = input()
n = int(src)

def consum(x):
	data = x[:]
	for i in range(1, len(data)):
		data[i] += data[i - 1]
	return data
src = input()
a = list([0])
a.extend(list(map(int, src.split())))
pro = consum(a)
res = 0
ma = {}
for i in range(1, n + 1):
	if ma.get(a[i]):
		ma[a[i]] += 1
	else:
		ma[a[i]] = 1
	res += (i - 1) * a[i] - pro[i - 1]
	if ma.get(a[i] - 1):
		res -= ma[a[i] - 1]
	if ma.get(a[i] + 1):
		res += ma[a[i] + 1]
print(res)


n = int(input())
nums = list(map(int, input().split()))
pref_sums = []
helper = []
all_numbers = {i: 0 for i in nums}
for i in nums:
	all_numbers[i] += 1
cur = {}
for i in range(n):
	c = nums[i]
	if c not in cur.keys():
		cur[c] = 1
	else:
		cur[c] += 1
	lesser_all = 0
	lesser_cur = 0
	bigger_all = 0
	bigger_cur = 0
	if c - 1 in all_numbers.keys():
		lesser_all = all_numbers[c - 1]
	if c - 1 in cur.keys():
		lesser_cur = cur[c - 1]
	if c + 1 in all_numbers.keys():
		bigger_all = all_numbers[c + 1]
	if c + 1 in cur.keys():
		bigger_cur = cur[c + 1]
	helper.append((lesser_all - lesser_cur, bigger_all - bigger_cur))
	if len(pref_sums) == 0:
		pref_sums.append(c)
	else:
		pref_sums.append(c + pref_sums[-1])
answer = 0
for i in range(n):
	k = helper[i][1]
	l = helper[i][0]
	mul = n - i - 1
	s = pref_sums[n - 1] - pref_sums[i]
	answer += s - mul * nums[i] - k + l
print(answer)


n = int(input())
t = input().split()
x = {int(i): 0 for i in t}
result = 0
for i in range(1, n + 1):
	a = int(t[i - 1])
	x[a] += 1
	result += a * (2 * i - n - 1)
	if a + 1 in x:
		result += x[a + 1]
	if a - 1 in x:
		result -= x[a - 1]
print(result)


n = int(input())
a = [int(i) for i in input().split()]
from collections import defaultdict
d = defaultdict(lambda : 0)
ans = 0
s = 0
for i in range(n):
	e = a[i]
	prev = i - d[e] - d[e - 1] - d[e + 1]
	ans += e * prev - s + d[e] * e + d[e - 1] * (e - 1) + d[e + 1] * (e + 1)
	d[e] += 1
	s += e
print(ans)


(n, a, ft) = (0, [(0, 0)], [0])

def query(k):
	res = 0
	while k > 0:
		res += ft[k]
		k -= k & -k
	return res

def adjust(k, v):
	while k <= n:
		ft[k] += v
		k += k & -k

def rquery(l, r):
	if l > r:
		return 0
	return query(r) - (0 if l == 1 else query(l - 1))
(n, ans) = (int(input()), 0)
tmp = [int(x) for x in input().split()]
for i in range(1, n + 1):
	a.append((tmp[i - 1], i))
ft = [0 for i in range(n + 1)]
ans = sum([x * (2 * i - n - 1) for (x, i) in a])
a.sort(key=lambda x: x[0])
(L, R, cur, i) = ([], [], 0, 1)
while i <= n:
	(v, k) = a[i]
	if v == cur:
		ans -= rquery(1, k - 1) - rquery(k + 1, n)
		R.append(k)
		i += 1
	else:
		for j in L:
			adjust(j, -1)
		L = []
		if v - cur == 1:
			for j in R:
				L.append(j)
				adjust(j, 1)
		(R, cur) = ([], v)
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
d = 0
for i in range(n):
	d += -1 * a[i] * (n - i - 1)
	d += a[i] * i
di = {}
for i in range(n):
	if a[i] not in di:
		di[a[i]] = 0
	if a[i] - 1 in di:
		d -= di[a[i] - 1]
	if a[i] + 1 in di:
		d += di[a[i] + 1]
	di[a[i]] += 1
print(d)


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().strip().split(' ')]
ans = 0
cnt = defaultdict(lambda : 0)
for i in range(n):
	c = i - (cnt[a[i]] + cnt[a[i] + 1] + cnt[a[i] - 1])
	ans += c * a[i]
	cnt[a[i]] += 1
cnt = defaultdict(lambda : 0)
for i in reversed(range(n)):
	c = n - i - 1 - (cnt[a[i]] + cnt[a[i] + 1] + cnt[a[i] - 1])
	ans -= c * a[i]
	cnt[a[i]] += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
sum = 0
mp = {}
for i in range(n):
	x = arr[i]
	ans += x * i - sum
	ans -= mp.get(x - 1, 0)
	ans += mp.get(x + 1, 0)
	mp[x] = mp.get(x, 0) + 1
	sum += x
print(ans)


n = int(input())
a = {}
ans = 0
sum = 0
i = 0
for t in map(int, input().split()):
	sum += t
	a[t] = a.get(t, 0) + 1
	ans += (i - a.get(t, 0) - a.get(t - 1, 0) - a.get(t + 1, 0) + 1) * t - (sum - a.get(t, 0) * t - a.get(t - 1, 0) * (t - 1) - a.get(t + 1, 0) * (t + 1))
	i += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
total = 0
for i in range(n - 1, -1, -1):
	total = total + i * l[i]
for i in range(0, n):
	total = total - (n - i - 1) * l[i]
d = {}
for i in range(len(l)):
	d[l[i]] = 0
	d[l[i] + 1] = 0
	d[l[i] - 1] = 0
for i in range(0, n):
	if i == 0:
		d[l[i]] = d[l[i]] + 1
	else:
		temp1 = l[i] - 1
		temp2 = l[i] + 1
		total = total - d[temp1] * l[i] + d[temp1] * temp1
		total = total - d[temp2] * l[i] + d[temp2] * temp2
		d[l[i]] = d[l[i]] + 1
print(total)


n = int(input())
ls = [int(i) for i in input().split()]
fullsum = sum((ls[i] * (-n + 1 + 2 * i) for i in range(n)))
numdict = dict()
for num in ls:
	if num - 1 in numdict:
		fullsum -= numdict[num - 1]
	if num + 1 in numdict:
		fullsum += numdict[num + 1]
	if num in numdict:
		numdict[num] += 1
	else:
		numdict[num] = 1
print(fullsum)


n = int(input())
v = []
mp = {}
for i in input().split():
	v.append(int(i))
	mp[int(i)] = 0
	mp[int(i) - 1] = 0
	mp[int(i) + 1] = 0
sum = 0
ele = 0
ans = 0
for i in v[::-1]:
	ans = ans + (sum - ele * i)
	a = (i + 1) * mp[i + 1] - mp[i + 1] * i
	b = (i - 1) * mp[i - 1] - mp[i - 1] * i
	ans = ans - (a + b)
	mp[i] = mp[i] + 1
	sum = sum + i
	ele = ele + 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
summ = sum(arr)
ans = 0
for i in range(n - 1):
	ans += summ - arr[i] - (n - i - 1) * arr[i]
	summ -= arr[i]
d = {}
for i in range(n):
	if arr[i] in d.keys():
		d[arr[i]] += 1
	else:
		d[arr[i]] = 1
for i in range(n):
	if arr[i] - 1 in d.keys():
		ans += d[arr[i] - 1]
	if arr[i] + 1 in d.keys():
		ans -= d[arr[i] + 1]
	d[arr[i]] -= 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
t = sum(((i + 1) * ai for (i, ai) in enumerate(a)))
p = 2 * t - (n + 1) * s
q = 0
r = 0
freqs = {}
for y in a:
	q += freqs.get(y - 1, 0)
	r += freqs.get(y + 1, 0)
	freqs[y] = 1 + freqs.get(y, 0)
print(p - q + r)


n = int(input())
t = [int(x) for x in input().split()]
ans = 0
d = {}
for i in range(n):
	ans += (-(n - 1) + 2 * i) * t[i]
for i in range(n):
	ans -= d.get(t[i] - 1, 0)
	ans += d.get(t[i] + 1, 0)
	d[t[i]] = d.get(t[i], 0) + 1
print(ans)


n = int(input())
arr = list(map(int, input().split(' ')))
mp = {}
cum = arr[0]
res = 0
mp[arr[0]] = 1
for i in range(1, n):
	res += arr[i] * i - cum
	if arr[i] + 1 in mp:
		res += mp[arr[i] + 1]
	if arr[i] - 1 in mp:
		res -= mp[arr[i] - 1]
	cum += arr[i]
	if arr[i] not in mp:
		mp[arr[i]] = 0
	mp[arr[i]] += 1
print(res)


n = int(input())
a = list(map(int, input().split()))
mm = dict()
S = [0] * 200001
for i in range(n):
	if i > 0:
		S[i] = S[i - 1] + a[i]
	if a[i] not in mm:
		mm[a[i]] = 1
	else:
		mm[a[i]] += 1
ans = 0
for i in range(n):
	if i > 0:
		ans += -a[i] * (n - 1 - i) + S[n - 1] - S[i]
	else:
		ans += -a[i] * (n - 1 - i) + S[n - 1]
for i in range(n):
	if a[i] + 1 in mm:
		ans -= mm[a[i] + 1]
	if a[i] - 1 in mm:
		ans += mm[a[i] - 1]
	mm[a[i]] -= 1
print(ans)


from collections import defaultdict
n = int(input())
a = map(int, input().split())
(f, s, res) = (defaultdict(int), 0, 0)
for (cnt, x) in enumerate(a, start=1):
	f[x] += 1
	s += x
	res += x * cnt - s - f[x - 1] + f[x + 1]
print(res)


n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 0
s = 0
for z in range(n):
	i = a[z]
	if i not in d:
		d[i] = 0
	d[i] += 1
	count = d[i] + (d[i - 1] if i - 1 in d else 0) + (d[i + 1] if i + 1 in d else 0)
	tot = d[i] * i + (d[i - 1] if i - 1 in d else 0) * (i - 1) + (d[i + 1] if i + 1 in d else 0) * (i + 1)
	s += i
	ans += i * (z - count + 1) - (s - tot)
print(ans)


trash = int(input())
numbers = input().split(' ', trash)
for i in range(trash):
	numbers[i] = int(numbers[i])
dict = {}
for i in range(trash):
	dict[numbers[i]] = 0
	dict[numbers[i] - 1] = 0
	dict[numbers[i] + 1] = 0
res = 0
fncount = numbers[0]
dict[numbers[0]] = 1
for i in range(1, trash):
	dict[numbers[i]] = dict[numbers[i]] + 1
	res = res + numbers[i] * i - fncount - dict[numbers[i] - 1] + dict[numbers[i] + 1]
	fncount = fncount + numbers[i]
print(res)


n = int(input())
soujanya = {}
sum = 0
k = input().split()
a = {}
for j in range(n):
	i = j + 1
	a[i] = int(k[j])
	sum += a[i]
	if a[i] in soujanya.keys():
		soujanya[a[i]] += 1
	else:
		soujanya[a[i]] = 1
counter = n
ans = 0
for j in range(n):
	i = j + 1
	temp = counter
	if a[i] - 1 in soujanya.keys():
		k1 = soujanya[a[i] - 1]
	else:
		k1 = 0
	if a[i] in soujanya.keys():
		k2 = soujanya[a[i]]
	else:
		k2 = 0
	if a[i] + 1 in soujanya.keys():
		k3 = soujanya[a[i] + 1]
	else:
		k3 = 0
	temp -= k1 + k2 + k3
	k = sum - (k1 * (a[i] - 1) + k2 * a[i] + k3 * (a[i] + 1))
	ans += k - temp * a[i]
	counter = counter - 1
	sum -= a[i]
	soujanya[a[i]] -= 1
print(ans)


n = int(input())
t = [int(x) for x in input().split()]
ans = 0
d = {}
for i in range(n):
	ans += (-(n - 1) + 2 * i) * t[i]
for i in range(n):
	if t[i] - 1 in d:
		ans -= d[t[i] - 1]
	if t[i] + 1 in d:
		ans += d[t[i] + 1]
	if t[i] in d:
		d[t[i]] += 1
	else:
		d[t[i]] = 1
print(ans)


n = int(input())
t = list(map(int, input().split()))
c = {}
u = {}
a = [0 for _ in range(n)]
for i in range(n):
	a[i] = t[i] * i - t[i] * (n - 1 - i)
	if t[i] not in u:
		u[t[i]] = [i]
	else:
		u[t[i]].append(i)
l = []
for x in u:
	l.append(x)
l.sort()
p = len(l)
res = 0
for i in range(p - 1):
	if l[i] + 1 in u:
		l1 = len(u[l[i]])
		l2 = len(u[l[i] + 1])
		j1 = 0
		j2 = 0
		t1 = 0
		t2 = 0
		for j in range(l1 + l2):
			if j1 == l1:
				t2 += 1
				j2 += 1
				res -= t1
			elif j2 == l2:
				t1 += 1
				j1 += 1
				res += t2
			elif u[l[i]][j1] < u[l[i] + 1][j2]:
				t1 += 1
				j1 += 1
				res += t2
			else:
				t2 += 1
				j2 += 1
				res -= t1
for i in range(n):
	res += a[i]
print(res)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = int(input())
a = list(map(int, input().split(' ')))
dic = defaultdict(lambda : 0)
cursum = 0
ans = 0
for i in range(n):
	ele = a[i]
	if ele - 1 in dic.keys() and ele + 1 in dic.keys():
		ans += ele * (i - dic[ele - 1] - dic[ele + 1]) - (cursum - (dic[ele - 1] * (ele - 1) + dic[ele + 1] * (ele + 1)))
	elif ele - 1 in dic.keys():
		ans += ele * (i - dic[ele - 1]) - (cursum - dic[ele - 1] * (ele - 1))
	elif ele + 1 in dic.keys():
		ans += ele * (i - dic[ele + 1]) - (cursum - dic[ele + 1] * (ele + 1))
	else:
		ans += ele * i - cursum
	dic[ele] += 1
	cursum += ele
print(ans)


mp = dict()
n = int(input())
ans = 0
sum1 = 0
l = list(map(int, input().split()))
for i in range(0, n):
	t = l[i]
	if t - 1 not in mp:
		mp[t - 1] = 0
	if t + 1 not in mp:
		mp[t + 1] = 0
	if t not in mp:
		mp[t] = 0
	ans += i * t - sum1
	ans -= mp[t - 1]
	ans += mp[t + 1]
	sum1 += t
	mp[t] += 1
print(ans)


t = int(input())
a = input().split(' ')
sum = []
curr = 0
dic = {}
sum.append(0)
for i in a:
	curr = curr + int(i)
	sum.append(curr)
	if i in dic:
		p = dic[i]
		p = p + 1
		dic[i] = p
	else:
		dic[i] = 1
ans = 0
for i in range(1, t + 1):
	ans = ans + sum[t] - sum[i] - int(t - int(i)) * int(a[i - 1])
	p1 = str(int(a[i - 1]) + 1)
	p2 = str(int(a[i - 1]) - 1)
	if str(p1) in dic:
		ans = ans - int(dic[str(int(a[i - 1]) + 1)])
	if str(p2) in dic:
		ans = ans + int(dic[str(int(a[i - 1]) - 1)])
	p = dic[a[i - 1]]
	p = p - 1
	dic[a[i - 1]] = p
print(ans)


import sys
mp = {}
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
ans = 0
ele = 0
sel = 0
for x in A:
	ans = ans + ele * x - sel
	if x - 1 in mp:
		ans = ans - mp[x - 1]
	if x + 1 in mp:
		ans = ans + mp[x + 1]
	if x in mp:
		mp[x] += 1
	else:
		mp[x] = 1
	sel += x
	ele += 1
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
s = 0
mp = {}
ans = 0
cnt = 0
for i in a:
	if mp.get(i - 1) == None:
		mp[i - 1] = 0
	if mp.get(i + 1) == None:
		mp[i + 1] = 0
	if mp.get(i) == None:
		mp[i] = 0
	mp[i] += 1
	cnt += 1
	s += i
	ans += s - (i - 1) * mp[i - 1] - (i + 1) * mp[i + 1] - i * (cnt - mp[i - 1] - mp[i + 1])
print(-ans)


def solve():
	n = get(int)
	ar = get([int])
	counts = defaultdict(int)
	runsum = 0
	ans = 0
	for (i, v) in enumerate(ar):
		c = counts[v] + counts[v - 1] + counts[v + 1]
		ans += v * (i - c) - runsum + counts[v] * v + counts[v - 1] * (v - 1) + counts[v + 1] * (v + 1)
		runsum += v
		counts[v] += 1
	return ans
_testcases = '\n5\n1 2 3 1 3\n\n4\n\n\n\n4\n6 6 5 5\n\n0\n\n\n\n\n4\n6 6 4 4\n\n-8\n'.strip()
from bisect import bisect_left, bisect_right
from functools import lru_cache
from heapq import heapify, heappop, heappush
from operator import itemgetter, attrgetter
from collections import defaultdict
import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import re
import string
import sys
inf = float('inf')
cache = lru_cache(None)
sys.setrecursionlimit(10000)

def tree():
	return collections.defaultdict(tree)

def equal(x, y, epsilon=1e-06):
	if -epsilon <= x - y <= epsilon:
		return True
	if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon:
		return False
	return -epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon

def get(_type):
	if type(_type) == list:
		if len(_type) == 1:
			_type = _type[0]
			return list(map(_type, input().strip().split()))
		else:
			return [_type[i](inp) for (i, inp) in enumerate(input().strip().split())]
	else:
		return _type(input().strip())
printRecursionTree = timeit = lambda x: x
(_p, print) = (print, lambda *a, **b: None)
_p(solve())


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(lambda : 0)
(s, ans) = (0, 0)
for i in range(n):
	ans += a[i] * i - s - (d[a[i] - 1] - d[a[i] + 1])
	d[a[i]] += 1
	s += a[i]
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
cc = Counter(c)
ans = 0
aa = a[::-1]
while a:
	x = a.pop()
	c[x] -= 1
	ans += x * (len(a) - (c[x] + c[x + 1] + c[x - 1]))
while aa:
	x = aa.pop()
	cc[x] -= 1
	ans -= x * (len(aa) - (cc[x] + cc[x + 1] + cc[x - 1]))
print(ans)


n = int(input())
f = dict()
s = 0
ret = 0
a = list(map(int, input().split()))
for i in range(0, n):
	ret += a[i] * i - s
	ret -= f.get(a[i] - 1, 0)
	ret += f.get(a[i] + 1, 0)
	s += a[i]
	f[a[i]] = f.get(a[i], 0) + 1
print(ret)


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split(' ')))
ans = 0
s = 0
mp = defaultdict(int)
for i in range(0, n):
	v = arr[i]
	ans += i * v - s
	s += v
	if v - 1 in mp:
		ans -= mp[v - 1]
	if v + 1 in mp:
		ans += mp[v + 1]
	mp[v] += 1
print(ans)


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
res1 = 0
res2 = 0
res3 = 0
tmp = -(n - 1)
for i in range(n):
	res1 += a[i] * tmp
	tmp += 2
cnt = defaultdict(int)
for i in range(n):
	cnt[a[i]] += 1
for i in range(n):
	cnt[a[i]] -= 1
	res2 += cnt[a[i] + 1]
	res3 += cnt[a[i] - 1]
print(res1 - res2 + res3)


n = int(input())
a = [int(i) for i in input().split()]
finish = {}
for i in range(n):
	finish[a[i]] = 0
result = 0
for i in range(n - 1, -1, -1):
	result += (i * 2 + 1 - n) * a[i]
	if a[i] - 1 in finish.keys():
		result += finish[a[i] - 1]
	if a[i] + 1 in finish.keys():
		result -= finish[a[i] + 1]
	finish[a[i]] += 1
print(result)


n = int(input())
a = list(map(int, input().split(' ')))
summ = 0
diff = 0
d = {}
for i in range(0, n):
	diff += i * a[i] - summ
	summ += a[i]
	d[a[i]] = 0
	d[a[i] - 1] = 0
	d[a[i] + 1] = 0
for i in range(0, n):
	diff -= d[a[i] - 1] - d[a[i] + 1]
	d[a[i]] += 1
print(diff)


n = int(input())
all = list(input().split(' '))
qtd = 0
cur = 0
ans = 0
cnt = dict()
for num in all:
	x = int(num)
	qtd = qtd + 1
	ans = ans + (qtd - 1) * x - cur
	if x - 1 in cnt:
		ans = ans - cnt[x - 1]
	if x + 1 in cnt:
		ans = ans + cnt[x + 1]
	cur = cur + x
	if x in cnt:
		cnt[x] = cnt[x] + 1
	else:
		cnt[x] = 1
print(ans)


n = int(input())
arr = [int(k) for k in input().split()]
res = 0
tot = 0
um = {-100: -100}
for i in range(0, n):
	if arr[i] in um:
		um[arr[i]] += 1
	else:
		um[arr[i]] = 1
	res += i * arr[i] - tot
	if arr[i] + 1 in um:
		res += um[arr[i] + 1]
	if arr[i] - 1 in um:
		res -= um[arr[i] - 1]
	tot += arr[i]
print(res)


n = int(input())
a = [int(m) for m in input().split()]
mp = dict()
pre = 0
ans = 0
for i in range(0, n):
	ans += a[i] * i - pre + mp.get(a[i] + 1, 0) - mp.get(a[i] - 1, 0)
	pre += a[i]
	mp[a[i]] = mp.get(a[i], 0) + 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(0, n):
	dic[a[i]] = 0
	dic[a[i] - 1] = 0
	dic[a[i] + 1] = 0
ans = 0
summ = 0
for i in range(0, n):
	ans += i * a[i] - summ
	ans -= dic[a[i] - 1]
	ans += dic[a[i] + 1]
	summ += a[i]
	dic[a[i]] += 1
print(ans)


def main():
	n = int(input())
	array = list(map(int, input().split()))
	counts = dict()
	for elem in array:
		(counts[elem - 1], counts[elem], counts[elem + 1]) = (0, 0, 0)
	(answer, l, r) = (0, 0, n - 1)
	for elem in array:
		counts[elem] += 1
		answer += (l - r) * elem
		l += 1
		r -= 1
	for elem in array:
		counts[elem] -= 1
		answer += counts[elem - 1] - counts[elem + 1]
	print(answer)
main()


import math
import collections

def solve():
	total = int(input())
	nums = [int(x) for x in input().split()]
	freq = collections.defaultdict(int)
	acc = 0
	ans = 0
	for (i, n) in enumerate(nums):
		ans += i * n - acc + freq[n + 1] - freq[n - 1]
		freq[n] += 1
		acc += n
	print(ans)
solve()


n = int(input())
s = 0
ans = 0
l = input().split(' ')
mp = {}
for i in range(0, n):
	l[i] = int(l[i])
	f = i * l[i]
	f += mp.get(l[i] + 1, 0)
	f -= mp.get(l[i] - 1, 0)
	ans += f - s
	s += l[i]
	temp = mp.get(l[i], 0)
	mp[l[i]] = temp + 1
print(ans)


from collections import Counter

def lInt(d=None):
	return map(int, input().split(d))
acc = 0
pre = 0
freq = Counter()
(n, *_) = lInt()
for (i, v) in enumerate(lInt()):
	m = i - freq[v - 1] - freq[v] - freq[v + 1]
	a = pre + (v - 1) * freq[v - 1] + v * freq[v] + (v + 1) * freq[v + 1]
	acc += a + m * v
	pre -= v
	freq[v] += 1
print(acc)


from collections import defaultdict
n = int(input())
a = map(int, input().split())
(aa, s, res) = (defaultdict(int), 0, 0)
for (x, v) in enumerate(a, start=1):
	aa[v] += 1
	s += v
	res += v * x - s - aa[v - 1] + aa[v + 1]
print(res)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
ans = 0
s = 0
for (i, a) in enumerate(l):
	ans += a * i - s
	s += a
c = Counter()
for a in l:
	ans -= c[a - 1]
	ans += c[a + 1]
	c[a] += 1
print(ans)


n = int(input())
a = input().split()
an = 0
sum = int(a[n - 1])
cnt = {}
for x in range(n):
	cnt[int(a[x])] = 0
	cnt[int(a[x]) + 1] = 0
	cnt[int(a[x]) - 1] = 0
cnt[int(a[n - 1])] = 1
x = n - 2
while x >= 0:
	rsum = sum - (cnt[int(a[x])] * int(a[x]) + cnt[int(a[x]) + 1] * (int(a[x]) + 1) + cnt[int(a[x]) - 1] * (int(a[x]) - 1))
	an += rsum - int(a[x]) * (n - (x + 1) - cnt[int(a[x])] - cnt[int(a[x]) + 1] - cnt[int(a[x]) - 1])
	cnt[int(a[x])] += 1
	sum += int(a[x])
	x = x - 1
print(an)


n = int(input())
arr = list(map(int, input().split()))
celm = {}
for i in arr:
	celm[i] = 0
	celm[i - 1] = 0
	celm[i + 1] = 0
ans = 0
qs = 0
for i in range(n):
	ans += arr[i] * i
	ans -= qs
	ans -= celm[arr[i] - 1]
	ans += celm[arr[i] + 1]
	qs += arr[i]
	celm[arr[i]] += 1
print(ans)


n = int(input())
ans = 0
sum = 0
mp = {}
c = []
c = list(map(int, input().split()))
for i in range(0, n):
	tmp = c[i]
	z1 = 0
	z2 = 0
	if tmp - 1 in mp:
		z1 = mp[tmp - 1]
	if tmp + 1 in mp:
		z2 = mp[tmp + 1]
	ans += tmp * i - sum - z1 + z2
	if tmp in mp:
		mp[tmp] += 1
	else:
		mp[tmp] = 1
	sum += tmp
print(ans)


from collections import Counter

def lInt(d=None):
	return map(int, input().split(d))
t = 0
p = 0
f = Counter()
(n, *_) = lInt()
for (i, v) in enumerate(lInt()):
	x = f[v - 1]
	y = f[v]
	z = f[v + 1]
	m = i - x - y - z
	a = p + (v - 1) * x + v * y + (v + 1) * z
	t += a + m * v
	p -= v
	f[v] += 1
print(t)


n = int(input())
a = list(map(int, input().split()))
d = dict()
s = 0
ans = 0
for elem in a:
	if d.get(elem) == None:
		d[elem] = 0
	d[elem] += 1
	s += elem
for i in range(n):
	cur = a[i]
	d[cur] -= 1
	s -= cur
	cnt = n - i - 1
	if d.get(cur - 1) == None:
		cnt1 = 0
	else:
		cnt1 = d[cur - 1]
	if d.get(cur) == None:
		cnt2 = 0
	else:
		cnt2 = d[cur]
	if d.get(cur + 1) == None:
		cnt3 = 0
	else:
		cnt3 = d[cur + 1]
	ans += s - cnt1 * (cur - 1) - cnt2 * cur - cnt3 * (cur + 1) - (cnt - cnt1 - cnt2 - cnt3) * cur
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
sm = sum(arr)
d = {}
for i in arr:
	d[i] = d.get(i, 0) + 1
ans = 0
cnt = n
for i in range(n):
	temp = sm
	temp -= d.get(arr[i], 0) * arr[i]
	temp -= d.get(arr[i] - 1, 0) * (arr[i] - 1)
	temp -= d.get(arr[i] + 1, 0) * (arr[i] + 1)
	val = temp - (cnt - d.get(arr[i], 0) - d.get(arr[i] + 1, 0) - d.get(arr[i] - 1, 0)) * arr[i]
	ans += val
	d[arr[i]] -= 1
	sm -= arr[i]
	cnt -= 1
print(ans)


n = int(input())
line = list(map(int, input().split()))
m = dict()
ans = 0
for i in range(n):
	if line[i] not in m:
		m[line[i]] = 1
	else:
		m[line[i]] += 1
	var = m[line[i]]
	if line[i] - 1 in m:
		var += m[line[i] - 1]
	if line[i] + 1 in m:
		var += m[line[i] + 1]
	ans += (i + 1 - var) * line[i]
x = dict()
for j in range(n):
	i = n - j - 1
	if line[i] not in x:
		x[line[i]] = 1
	else:
		x[line[i]] += 1
	var = x[line[i]]
	if line[i] - 1 in x:
		var += x[line[i] - 1]
	if line[i] + 1 in x:
		var += x[line[i] + 1]
	ans -= (j + 1 - var) * line[i]
print(ans)


def query(l, r):
	return s[r] - s[l - 1]
n = int(input())
a = [0] + [int(i) for i in input().split()]
s = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	s[i] = s[i - 1] + a[i]
ans = 0
m = {}
for i in range(n, 0, -1):
	ans += query(i + 1, n) - (n - i) * a[i]
	if a[i] + 1 in m:
		ans -= m[a[i] + 1]
	if a[i] - 1 in m:
		ans += m[a[i] - 1]
	if a[i] in m:
		m[a[i]] += 1
	else:
		m[a[i]] = 1
print(ans)


line = input()
n = int(line)
line = input().rstrip().split(' ')
a = []
for i in range(0, n):
	a.append(int(line[i]))
mpa = {}
ans = 0
sum_a = 0
for i in range(0, n):
	ans = ans + (a[i] * i - sum_a + (mpa.get(a[i] + 1, 0) - mpa.get(a[i] - 1, 0)))
	sum_a = sum_a + a[i]
	mpa[a[i]] = mpa.get(a[i], 0) + 1
print(str(ans))


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for x in range(n):
	ans += a[x] * x - a[x] * (n - x - 1)
s = {}
for x in range(n):
	if a[x] not in s:
		s[a[x]] = 1
	else:
		s[a[x]] += 1
	if a[x] - 1 in s:
		ans -= s[a[x] - 1]
	if a[x] + 1 in s:
		ans += s[a[x] + 1]
print(ans)


n = int(input())
numbers = list(map(int, input().split()))
count = {}
pre_sum = 0
ans = 0
for i in range(len(numbers)):
	cnt = 0
	sum = 0
	for j in range(-1, 2):
		cnt += count[numbers[i] + j] if numbers[i] + j in count else 0
		sum += (numbers[i] + j) * count[numbers[i] + j] if numbers[i] + j in count else 0
	ans += numbers[i] * (i - cnt) - (pre_sum - sum)
	pre_sum += numbers[i]
	if numbers[i] not in count:
		count[numbers[i]] = 0
	count[numbers[i]] += 1
print(ans)


from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split(' ')]
ans = 0
s = 0
cnt = defaultdict(int)
for i in range(n):
	ans += a[i] * (i - cnt[a[i]] - cnt[a[i] - 1] - cnt[a[i] + 1])
	cnt[a[i]] += 1
a = a[::-1]
cnt = defaultdict(int)
for i in range(n):
	ans -= a[i] * (i - cnt[a[i]] - cnt[a[i] - 1] - cnt[a[i] + 1])
	cnt[a[i]] += 1
print(str(ans))


input()
ans = 0
sum = 0
i = 0
d = dict()
arr = list(map(int, input().split()))
for cur in arr:
	d[cur] = 0
	d[cur - 1] = 0
	d[cur + 1] = 0
for cur in arr:
	ans += i * cur - sum + d[cur + 1] - d[cur - 1]
	d[cur] += 1
	i += 1
	sum += cur
print(ans)


n = int(input())
arr = input().split()
b = []
for x in arr:
	b.append(int(x))
cnt = {}
ans = 0
for i in range(n):
	ans += b[i] * i + -b[i] * (n - i - 1)
for i in range(n):
	if b[i] - 1 in cnt.keys():
		ans -= cnt[b[i] - 1]
	if b[i] + 1 in cnt.keys():
		ans += cnt[b[i] + 1]
	if b[i] in cnt.keys():
		cnt[b[i]] += 1
	else:
		cnt[b[i]] = 1
print(ans)


import sys
d = {}
n = int(input())
a = [int(i) for i in input().split()]
for i in a:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
ss = sum(a)
ans = 0
for i in range(n):
	ss -= a[i]
	s = ss
	d[a[i]] -= 1
	k = n - i - 1
	if a[i] - 1 in d:
		k -= d[a[i] - 1]
		s -= d[a[i] - 1] * (a[i] - 1)
	if a[i] + 1 in d:
		k -= d[a[i] + 1]
		s -= d[a[i] + 1] * (a[i] + 1)
	if a[i] in d:
		k -= d[a[i]]
		s -= d[a[i]] * a[i]
	ans += s - k * a[i]
print(ans)


from collections import defaultdict
n = int(input())
mp = defaultdict(int)
ans = 0
sm = 0
i = 0
for a in map(int, input().split()):
	dcnt = 0
	decr = 0
	for b in range(a - 1, a + 2):
		if b in mp:
			dcnt += mp[b]
			decr += b * mp[b]
	ans += (i - dcnt) * a - (sm - decr)
	sm += a
	mp[a] += 1
	i += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
mp = {}
dict = {}
for i in range(0, n):
	mp[arr[i]] = 0
for i in range(0, n):
	x = arr[i]
	ans = ans + i * x - (n - i - 1) * x
	if x + 1 in mp:
		ans = ans + mp[x + 1]
	if x - 1 in mp:
		ans = ans - mp[x - 1]
	mp[x] = mp[x] + 1
print(ans)


def set(x):
	if x not in m:
		m[x] = 0
n = int(input())
a = list(map(int, input().split()))
m = {}
(ans, total) = (0, 0)
for i in range(0, n):
	x = a[i]
	(set(x), set(x - 1), set(x + 1))
	ans = ans + (i - m[x] - m[x - 1] - m[x + 1]) * x
	ans = ans - (total - m[x] * x - m[x - 1] * (x - 1) - m[x + 1] * (x + 1))
	(m[x], total) = (m[x] + 1, total + x)
print(ans)


n = int(input())
a = list(map(int, input().split()))
sum0 = 0
ans = 0
sum1 = 0
m = {}
for i in range(0, n):
	m[a[i]] = 0
	m[a[i] + 1] = 0
	m[a[i] - 1] = 0
	sum0 += a[i]
for i in range(0, n):
	m[a[i]] += 1
for i in range(n - 1, -1, -1):
	sum1 = sum0 - a[i] - m[a[i] - 1] * (a[i] - 1) - m[a[i] + 1] * (a[i] + 1)
	x = (n - m[a[i] - 1] - m[a[i] + 1] - 1) * a[i]
	m[a[i]] -= 1
	n -= 1
	sum0 -= a[i]
	ans += x - sum1
print(ans)


n = int(input())
inp = [int(x) for x in input().split()]
l = {}
ans = 0
for i in range(n):
	x = inp[i]
	ans += x * (2 * i - n + 1)
	if x - 1 in l:
		ans -= l[x - 1]
	if x + 1 in l:
		ans += l[x + 1]
	l[x] = l[x] + 1 if x in l else 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
res = 0
cur = 0
d = {}
for (j, i) in enumerate(a):
	if i - 1 in d:
		res -= d[i - 1]
	if i + 1 in d:
		res += d[i + 1]
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
	res += i * j - cur
	cur += i
print(res)


sequence_dict = {}
sum = 0
number_of_elements = int(input())
sequence = list(map(int, input().split()))
for (index, element) in enumerate(sequence):
	sum += index * element - (number_of_elements - 1 - index) * element - sequence_dict.get(element - 1, 0) + sequence_dict.get(element + 1, 0)
	sequence_dict[element] = sequence_dict.get(element, 0) + 1
print(sum)


map = dict()
sum = 0
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for (i, a) in enumerate(a):
	ans += i * a
	ans -= sum
	if a - 1 in map:
		ans -= map[a - 1]
	if a + 1 in map:
		ans += map[a + 1]
	sum += a
	if a in map:
		map[a] += 1
	else:
		map[a] = 1
print(ans)


class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * (n + 1)

	def _sum(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s

	def add(self, i, val):
		i = i + 1
		while i <= self.n:
			self.bit[i] += val
			i += i & -i

	def get_sum(self, l, r):
		return self._sum(r) - self._sum(l)

def add1(ind_li, val):
	for i in ind_li:
		st.add(i, val)

def cnt1(ind_li):
	for i in ind_li:
		cnt.add(i, 1)

def calc(ind_li, val):
	res = 0
	for i in ind_li:
		res1 = st.get_sum(0, i) - val * cnt.get_sum(0, i)
		res2 = st.get_sum(i + 1, n) - val * cnt.get_sum(i + 1, n)
		res += res2 - res1
	return res
n = int(input())
a = list(map(int, input().split()))
st = BIT(n)
cnt = BIT(n)
b = sorted(zip(a, range(len(a))))
b = b + [(b[-1][0] + 1, b[-1][1])]
prev = 0
now = b[0][0]
tmp_now = []
tmp_prev = []
ans = 0
for i in range(n + 1):
	if now == b[i][0]:
		tmp_now.append(b[i][1])
		continue
	if prev + 1 == now:
		ans += calc(tmp_now, now)
		add1(tmp_prev, prev)
		cnt1(tmp_prev)
	else:
		add1(tmp_prev, prev)
		cnt1(tmp_prev)
		ans += calc(tmp_now, now)
	prev = now
	tmp_prev = tmp_now[0:]
	tmp_now = [b[i][1]]
	now = b[i][0]
print(ans)


from random import randint
n = int(input())
l = list(map(int, input().split()))
d = {}
sm = sum(l)
for i in l:
	try:
		d[i] += 1
	except:
		d[i] = 1
ans = 0
for i in l:
	ans += sm - i * n
	try:
		ans -= d[i + 1]
	except:
		pass
	try:
		ans += d[i - 1]
	except:
		pass
	sm -= i
	d[i] -= 1
	n -= 1
print(ans)


n = int(input())
v = list(map(int, input().split()))
cnt = {}
ans = s = 0
for i in range(0, n):
	ans += i * v[i] - s
	s += v[i]
	if v[i] + 1 in cnt:
		ans += cnt[v[i] + 1]
	if v[i] - 1 in cnt:
		ans -= cnt[v[i] - 1]
	if v[i] in cnt:
		cnt[v[i]] += 1
	else:
		cnt[v[i]] = 1
print(ans)


n = int(input())
a = list(map(int, input().strip().split()))
mapp = {}
for i in a:
	mapp[i] = 0
	mapp[i + 1] = 0
	mapp[i - 1] = 0
s = sum(a)
ans = 0
for i in range(n):
	mapp[a[i]] += 1
	ans += s - a[i] * (n - i)
	s -= a[i]
	ans += mapp[a[i] + 1]
	ans -= mapp[a[i] - 1]
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
m = {}
total = 0
ans = 0
for i in range(n):
	ans += a[i] * i - total
	if a[i] + 1 in m:
		ans += m[a[i] + 1]
	if a[i] - 1 in m:
		ans -= m[a[i] - 1]
	if a[i] in m:
		m[a[i]] += 1
	else:
		m[a[i]] = 1
	total += a[i]
print(ans)


maxN = 2 * 10 ** 5
n = int(input())
bad = 0
ghabl = 0
a = list(map(int, input().split()))
for i in range(n):
	if i:
		bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
	bad -= a[i] - a[i - 1]
	bad -= (n - 1 - i) * (a[i] - a[i - 1])
	Sum += bad
maP = dict()
maP['pedram'] = 1
for i in range(n):
	if a[i] in maP:
		maP[a[i]] += 1
	else:
		maP[a[i]] = 1
	if a[i] - 1 in maP:
		Sum -= maP[a[i] - 1]
	if a[i] + 1 in maP:
		Sum += maP[a[i] + 1]
print(Sum)


n = int(input())
a = input().split()
dic = {}
ans = 0
sum = 0
for i in range(0, n):
	x = int(a[i])
	sum += x
	ans += (i + 1) * x - sum
	if x in dic:
		dic[x] += 1
	else:
		dic[x] = 1
	if x + 1 in dic:
		ans += dic[x + 1]
	if x - 1 in dic:
		ans -= dic[x - 1]
print(ans)


n = int(input())
l = input().split()
l = [int(i) for i in l]
cnt = {}
for i in l:
	cnt[i - 1] = 0
	cnt[i + 1] = 0
	cnt[i] = 0
ans = 0
pre = 0
for i in range(0, n):
	ans += l[i] * i - pre
	pre += l[i]
	ans -= cnt[l[i] - 1]
	ans += cnt[l[i] + 1]
	cnt[l[i]] += 1
print(ans)


N = int(input())
s = list(map(int, input().split()))
M = {}
ans = 0
j = 1 - N
for i in s:
	M[i] = M.get(i, 0) + 1
	ans += j * i
	j += 2
for i in s:
	ans += M.get(i - 1, 0)
	ans -= M.get(i + 1, 0)
	M[i] = M.get(i, 0) - 1
print(ans)


def get_s_in(i):
	global mp
	res = 0
	if a[i] - 1 in mp:
		res += mp[a[i] - 1] * (a[i] - 1)
	if a[i] in mp:
		res += mp[a[i]] * a[i]
	if a[i] + 1 in mp:
		res += mp[a[i] + 1] * (a[i] + 1)
	return res

def get_cnt_in(i):
	global mp
	res = 0
	if a[i] - 1 in mp:
		res += mp[a[i] - 1]
	if a[i] in mp:
		res += mp[a[i]]
	if a[i] + 1 in mp:
		res += mp[a[i] + 1]
	return res
n = int(input())
a = [0] + input().split()
s = [0] * (n + 1)
global mp
mp = {}
for i in range(1, n + 1):
	a[i] = int(a[i])
	if a[i] not in mp:
		mp[a[i]] = 1
	else:
		mp[a[i]] += 1
	s[i] = s[i - 1] + a[i]
ans = 0
for i in range(n, 0, -1):
	s_in = get_s_in(i)
	cnt_in = get_cnt_in(i)
	ans += a[i] * (i - cnt_in) - (s[i] - s_in)
	mp[a[i]] -= 1
print(ans)


n = int(input())
dic = {}
ans = s = 0
k = input().split()
for i in range(n):
	a = int(k[i])
	if a - 1 in dic:
		b = dic[a - 1]
	else:
		b = 0
	if a in dic:
		c = dic[a]
	else:
		c = 0
		dic.update({a: 0})
	if a + 1 in dic:
		d = dic[a + 1]
	else:
		d = 0
	ans += a * (i - b - c - d) - s + b * (a - 1) + c * a + d * (a + 1)
	dic[a] += 1
	s += a
print(ans)


n = int(input())
lst = input().split()
lst = [int(x) for x in lst]
ans = 0
cnt = {}
for (i, e) in enumerate(lst):
	ans += (2 * i + 1 - n) * e
	cnt[e] = 0
for e in lst:
	if e - 1 in cnt.keys():
		ans -= cnt[e - 1]
	if e + 1 in cnt.keys():
		ans += cnt[e + 1]
	cnt[e] += 1
print(ans)


import sys
n = int(input())
a = list(map(int, input().split()))
cnt = dict()
ans = 0
for i in range(n):
	ans += i * a[i]
	ans -= (n - 1 - i) * a[i]
	cnt[a[i]] = 0
for i in range(n):
	if a[i] - 1 in cnt:
		ans -= cnt[a[i] - 1]
	if a[i] + 1 in cnt:
		ans += cnt[a[i] + 1]
	cnt[a[i]] += 1
print(ans)


n = int(input())
x = input().split()
s = 0
ans = 0
mp = {}
for i in range(0, n):
	s = s + int(x[n - i - 1])
	ans += s - (i + 1) * int(x[n - i - 1])
	if int(x[n - i - 1]) + 1 in mp:
		ans -= mp[int(x[n - i - 1]) + 1]
	if int(x[n - i - 1]) - 1 in mp:
		ans += mp[int(x[n - i - 1]) - 1]
	if int(x[n - i - 1]) in mp:
		mp[int(x[n - i - 1])] += 1
	else:
		mp[int(x[n - i - 1])] = 1
print(ans)


def list_input():
	return list(map(int, input().split()))

def map_input():
	return map(int, input().split())

def map_string():
	return input().split()
ans = 0
d = {}
cnt = 0
n = int(input())
a = list_input()
for i in range(n):
	tot = i
	cur = cnt
	if a[i] in d:
		tot -= d[a[i]]
		cur -= a[i] * d[a[i]]
	if a[i] - 1 in d:
		tot -= d[a[i] - 1]
		cur -= d[a[i] - 1] * (a[i] - 1)
	if a[i] + 1 in d:
		tot -= d[a[i] + 1]
		cur -= d[a[i] + 1] * (a[i] + 1)
	ans += tot * a[i] - cur
	cnt += a[i]
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
print(ans)


from sys import stdin
from collections import Counter
n = int(stdin.readline())
v = list(map(int, stdin.readline().split()))
cnt = Counter()
sum = 0
for i in range(n):
	sum += v[i]
	cnt[v[i]] += 1
ans = 0
for i in range(n):
	tmp = sum - v[i] * cnt[v[i]] - (v[i] - 1) * cnt[v[i] - 1] - (v[i] + 1) * cnt[v[i] + 1]
	t = n - i - cnt[v[i]] - cnt[v[i] - 1] - cnt[v[i] + 1]
	ans += tmp - t * v[i]
	cnt[v[i]] -= 1
	sum -= v[i]
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
summ = 0
mp = {}
for i in range(0, n):
	l = 0
	if a[i] - 1 in mp:
		l = mp[a[i] - 1]
	r = 0
	if a[i] + 1 in mp:
		r = mp[a[i] + 1]
	ans = ans + i * a[i] - summ - (l - r)
	summ = summ + a[i]
	x = 0
	if a[i] in mp:
		x = mp[a[i]]
		del mp[a[i]]
	mp[a[i]] = x + 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = {}
s = 0
for i in range(0, len(a)):
	if a[i] in m:
		m[a[i]] = m[a[i]] + 1
	else:
		m[a[i]] = 1
	if a[i] + 1 in m:
		s += m[a[i] + 1] * 1
	if a[i] - 1 in m:
		s += m[a[i] - 1] * -1
	t = 2 * i - n + 1
	s += t * a[i]
print(s)


from collections import defaultdict
int(input())
(mp, sum, res) = (defaultdict(int), 0, 0)
for (i, x) in enumerate(map(int, input().split()), start=1):
	mp[x] += 1
	sum += x
	res += x * i - sum - mp[x - 1] + mp[x + 1]
print(res)


n = int(input())
ans = 0
a = [int(i) for i in input().split(' ')]
c = dict()
for i in a:
	c[i] = c[i - 1] = c[i + 1] = 0
for i in range(n):
	x = a[i]
	c[x] = c[x] + 1
	ans = ans + c[x + 1] - c[x - 1] + x * (i + 1 - n + i)
print(ans)


n = int(input())
arr = [int(lol) for lol in input().split()]
count = {}
ans = 0
s = 0
i = 0
for lol in arr:
	if lol not in count.keys():
		count[lol] = 1
	else:
		count[lol] += 1
	ans += i * lol
	ans -= s
	if lol - 1 in count.keys():
		ans -= count[lol - 1]
	if lol + 1 in count.keys():
		ans += count[lol + 1]
	s += lol
	i += 1
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
b = []
c = {}
s = 0
for i in range(n):
	if i == 0:
		b.append(a[i])
	else:
		b.append(b[-1] + a[i])
		try:
			lower = c[a[i] - 1]
		except KeyError:
			lower = 0
		try:
			this = c[a[i]]
		except KeyError:
			this = 0
		try:
			upper = c[a[i] + 1]
		except KeyError:
			upper = 0
		tokeep = i - lower - this - upper
		s += tokeep * a[i] - b[i - 1] + lower * (a[i] - 1) + this * a[i] + upper * (a[i] + 1)
	try:
		c[a[i]] += 1
	except KeyError:
		c[a[i]] = 1
print(s)


n = int(input())
a = []
a = [int(n) for n in input().split(' ')]
mapper = {}
summer = 0
ans = 0
for i in range(n):
	ans = ans + a[i] * i - summer
	if a[i] + 1 in mapper:
		ans = ans + mapper[a[i] + 1]
	if a[i] - 1 in mapper:
		ans = ans - mapper[a[i] - 1]
	if a[i] in mapper:
		mapper[a[i]] = mapper[a[i]] + 1
	else:
		mapper[a[i]] = 1
	summer = summer + a[i]
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
cnt = {}
for i in a:
	cnt[i] = 0
	cnt[i - 1] = 0
	cnt[i + 1] = 0
c = -(n - 1)
ans = 0
for i in range(n):
	ans += c * a[i]
	c += 2
	cnt[a[i]] += 1
	ans += cnt[a[i] + 1] - cnt[a[i] - 1]
print(ans)


n = int(input())
C = dict()
Sum = 0
ans = 0
a = list(map(int, input().split()))
for i in range(0, n):
	ans = ans + a[i] * i - Sum - C.get(a[i] - 1, 0) + C.get(a[i] + 1, 0)
	Sum = Sum + a[i]
	C[a[i]] = C.get(a[i], 0) + 1
print(ans)


n = input()
arr = list(map(int, input().split()))
mp = {}
ans = 0
sums = 0
count = 0
for i in range(int(n) - 1, -1, -1):
	sums += arr[i]
	if arr[i] in mp:
		mp[arr[i]] += 1
	else:
		mp[arr[i]] = 1
	count = count + 1
	ans1 = 0
	ans2 = 0
	if arr[i] + 1 in mp:
		ans1 = mp[arr[i] + 1]
	if arr[i] - 1 in mp:
		ans2 = mp[arr[i] - 1]
	ans += sums + ans2 - ans1 - arr[i] * count
print(ans)