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 long long ee = 1e10;
int n;
long long a[200005];
long long b[200005];
long long sum[200005];
map<int, int> mp;
vector<int> v[200005];
long long ans = 0, ans2 = 0, ch = 0;
int fan[200005];
int main() {
  scanf("%I64d", &n);
  int js = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++)
    if (mp[b[i]] == 0) {
      mp[b[i]] = ++js;
      fan[js] = b[i];
    }
  for (int i = n; i >= 1; i--) {
    sum[i] = sum[i + 1] + a[i];
  }
  for (int i = 1; i < n; i++) {
    long long kk = sum[i + 1] - a[i] * (n - i);
    if (kk > 0 && ch == 0) {
      long long kk2 = kk / ee;
      kk = kk % ee;
      ans += kk;
      ans2 += kk2;
      if (ans >= ee) {
        ans2 += (ans / ee);
        ans %= ee;
      }
    } else if (kk < 0 && ch == 1) {
      kk = -kk;
      long long kk2 = kk / ee;
      kk = kk % ee;
      ans += kk;
      ans2 += kk2;
      if (ans >= ee) {
        ans2 += (ans / ee);
        ans %= ee;
      }
    } else if (kk > 0 && ch == 1) {
      long long kk2 = kk / ee;
      kk = kk % ee;
      long long t1 = kk - ans;
      long long t2 = kk2 - ans2;
      if (t2 > 0) {
        ch = 0;
        ans2 = t2;
        ans = t1;
        if (t1 < 0) {
          ans2--;
          ans += ee;
        }
      } else {
        ans2 = -t2;
        ans = t1;
        if (ans > 0) {
          ans2--;
          ans = ee - t1;
        } else
          ans = -ans;
      }
    } else if (kk < 0 && ch == 0) {
      kk = -kk;
      long long kk2 = kk / ee;
      kk = kk % ee;
      long long t1 = ans - kk;
      long long t2 = ans2 - kk2;
      if (t2 >= 0) {
        ans2 = t2;
        ans = t1;
        if (t1 < 0) {
          ans2--;
          ans += ee;
        }
      } else {
        ch = 1;
        ans2 = -t2;
        ans = t1;
        if (t1 > 0) {
          ans2--;
          ans = ee - t1;
        } else {
          ans = -ans;
        }
      }
    }
    if (ans2 < 0) {
      ch ^= 1;
      ans2++;
      ans = ee - ans;
    }
  }
  for (int i = 1; i <= n; i++) {
    int k = mp[a[i]];
    v[k].push_back(i);
  }
  for (int i = 1; i < js; i++) {
    if (fan[i] + 1 < fan[i + 1]) continue;
    int x = v[i].size() - 1;
    int y = v[i + 1].size() - 1;
    long long tot = 0;
    while (x >= 0) {
      while (y >= 0) {
        if (v[i + 1][y] > v[i][x]) {
          y--;
          tot++;
        } else {
          break;
        }
      }
      long long kk = -tot;
      if (kk > 0 && ch == 0) {
        long long kk2 = kk / ee;
        kk = kk % ee;
        ans += kk;
        ans2 += kk2;
        if (ans >= ee) {
          ans2 += (ans / ee);
          ans %= ee;
        }
      } else if (kk < 0 && ch == 1) {
        kk = -kk;
        long long kk2 = kk / ee;
        kk = kk % ee;
        ans += kk;
        ans2 += kk2;
        if (ans >= ee) {
          ans2 += (ans / ee);
          ans %= ee;
        }
      } else if (kk > 0 && ch == 1) {
        long long kk2 = kk / ee;
        kk = kk % ee;
        long long t1 = kk - ans;
        long long t2 = kk2 - ans2;
        if (t2 > 0) {
          ch = 0;
          ans2 = t2;
          ans = t1;
          if (t1 < 0) {
            ans2--;
            ans += ee;
          }
        } else {
          ans2 = -t2;
          ans = t1;
          if (ans > 0) {
            ans2--;
            ans = ee - t1;
          } else
            ans = -ans;
        }
      } else if (kk < 0 && ch == 0) {
        kk = -kk;
        long long kk2 = kk / ee;
        kk = kk % ee;
        long long t1 = ans - kk;
        long long t2 = ans2 - kk2;
        if (t2 >= 0) {
          ans2 = t2;
          ans = t1;
          if (t1 < 0) {
            ans2--;
            ans += ee;
          }
        } else {
          ch = 1;
          ans2 = -t2;
          ans = t1;
          if (t1 > 0) {
            ans2--;
            ans = ee - t1;
          } else {
            ans = -ans;
          }
        }
      }
      if (ans2 < 0) {
        ch ^= 1;
        ans2++;
        ans = ee - ans;
      }
      x--;
    }
    x = v[i].size() - 1;
    y = v[i + 1].size() - 1;
    tot = 0;
    while (y >= 0) {
      while (x >= 0) {
        if (v[i][x] > v[i + 1][y]) {
          x--;
          tot++;
        } else {
          break;
        }
      }
      long long kk = tot;
      if (kk > 0 && ch == 0) {
        long long kk2 = kk / ee;
        kk = kk % ee;
        ans += kk;
        ans2 += kk2;
        if (ans >= ee) {
          ans2 += (ans / ee);
          ans %= ee;
        }
      } else if (kk < 0 && ch == 1) {
        kk = -kk;
        long long kk2 = kk / ee;
        kk = kk % ee;
        ans += kk;
        ans2 += kk2;
        if (ans >= ee) {
          ans2 += (ans / ee);
          ans %= ee;
        }
      } else if (kk > 0 && ch == 1) {
        long long kk2 = kk / ee;
        kk = kk % ee;
        long long t1 = kk - ans;
        long long t2 = kk2 - ans2;
        if (t2 > 0) {
          ch = 0;
          ans2 = t2;
          ans = t1;
          if (t1 < 0) {
            ans2--;
            ans += ee;
          }
        } else {
          ans2 = -t2;
          ans = t1;
          if (ans > 0) {
            ans2--;
            ans = ee - t1;
          } else
            ans = -ans;
        }
      } else if (kk < 0 && ch == 0) {
        kk = -kk;
        long long kk2 = kk / ee;
        kk = kk % ee;
        long long t1 = ans - kk;
        long long t2 = ans2 - kk2;
        if (t2 >= 0) {
          ans2 = t2;
          ans = t1;
          if (t1 < 0) {
            ans2--;
            ans += ee;
          }
        } else {
          ch = 1;
          ans2 = -t2;
          ans = t1;
          if (t1 > 0) {
            ans2--;
            ans = ee - t1;
          } else {
            ans = -ans;
          }
        }
      }
      if (ans2 < 0) {
        ch ^= 1;
        ans2++;
        ans = ee - ans;
      }
      y--;
    }
  }
  if (ans == 0 && ans2 == 0) {
    cout << "0" << endl;
    return 0;
  }
  if (ch == 1) cout << "-";
  if (ans2 != 0) {
    printf("%I64d", ans2);
    printf("%010I64d", ans);
  } else {
    printf("%I64d", ans);
  }
}
