Let's denote a function 

<image>

You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) 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 a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array. 

Output

Print one integer — the sum of d(ai, aj) 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:

  1. d(a1, a2) = 0; 
  2. d(a1, a3) = 2; 
  3. d(a1, a4) = 0; 
  4. d(a1, a5) = 2; 
  5. d(a2, a3) = 0; 
  6. d(a2, a4) = 0; 
  7. d(a2, a5) = 0; 
  8. d(a3, a4) = - 2; 
  9. d(a3, a5) = 0; 
  10. d(a4, a5) = 2. 
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(3e5 + 11);
const int inf = (int)(1e9 + 7);
const int base = (int)(1e9 + 7);
const int mod = (int)(1e9 + 7);
int n;
pair<long long, int> a[maxn];
map<long long, int> l, r;
double pref[maxn], t[2][4 * maxn];
void update(int v, int l, int r, int pos, int k, long double x) {
  if (l == r) {
    t[k][v] += x;
    return;
  }
  int m = (l + r) / 2;
  if (m >= pos)
    update(2 * v, l, m, pos, k, x);
  else
    update(2 * v + 1, m + 1, r, pos, k, x);
  t[k][v] = t[k][2 * v] + t[k][2 * v + 1];
}
long double get(int v, int l, int r, int al, int ar, int k) {
  if (al > r || ar < l) return 0.;
  if (l >= al && r <= ar) return t[k][v];
  int m = (l + r) / 2;
  return get(2 * v, l, m, al, ar, k) + get(2 * v + 1, m + 1, r, al, ar, k);
}
long double ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
    pref[i] = pref[i - 1] + a[i].first;
  }
  for (int i = 1; i <= n; ++i)
    ans += pref[n] - pref[i] - a[i].first * 1. * (n - i);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (!l[a[i].first]) l[a[i].first] = i;
    r[a[i].first] = i;
  }
  for (int i = 1; i <= n; ++i) {
    update(1, 1, n, a[i].second, 0, a[i].first * 1.);
    update(1, 1, n, a[i].second, 1, 1.);
    if (a[i].first + 1 == a[i + 1].first) {
      int nl = i + 1, nr = r[a[i + 1].first];
      for (int j = nl; j <= nr; ++j) {
        ans -= get(1, 1, n, a[j].second + 1, n, 0) -
               a[j].first * get(1, 1, n, a[j].second + 1, n, 1);
      }
    }
    if (a[i].first != a[i + 1].first)
      for (int j = l[a[i].first]; j <= r[a[i].first]; ++j) {
        update(1, 1, n, a[j].second, 0, -a[j].first * 1.);
        update(1, 1, n, a[j].second, 1, -1.);
      }
  }
  for (int i = n; i >= 1; --i) {
    update(1, 1, n, a[i].second, 0, a[i].first * 1.);
    update(1, 1, n, a[i].second, 1, 1.);
    if (a[i].first - 1 == a[i - 1].first && a[i - 1].first) {
      int nr = i - 1, nl = l[a[i - 1].first];
      for (int j = nl; j <= nr; ++j) {
        ans -= get(1, 1, n, a[j].second + 1, n, 0) -
               a[j].first * get(1, 1, n, a[j].second + 1, n, 1);
      }
    }
    if (a[i].first != a[i - 1].first)
      for (int j = l[a[i].first]; j <= r[a[i].first]; ++j) {
        update(1, 1, n, a[j].second, 0, -a[j].first * 1.);
        update(1, 1, n, a[j].second, 1, -1.);
      }
  }
  string x = to_string(ans);
  int pos = x.find('.');
  x = x.substr(0, pos);
  for (int i = 0; i < x.size(); i++) {
    printf("%c", x[i]);
  }
  return 0;
}
