#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long double eps = 1e-22;
pair<int, int> v[maxn];
int n, cnt[maxn];
long double answer, aib[maxn];
inline void update(int val, int pos) {
  for (; pos <= n; pos += (pos & (-pos))) aib[pos] = aib[pos] + val, cnt[pos]++;
}
inline long double countAib(int pos) {
  long double ans = 0;
  for (; pos > 0; pos -= (pos & (-pos))) ans += cnt[pos];
  return ans;
}
inline long double sumAib(int pos) {
  long double ans = 0;
  for (; pos > 0; pos -= (pos & (-pos))) ans += aib[pos];
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int idx;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(v + 1, v + n + 1);
  idx = 1;
  for (int i = 1; i <= n; i++) {
    while (v[idx].first + 1 < v[i].first) {
      update(v[idx].first, v[idx].second);
      idx++;
    }
    answer += v[i].first * countAib(v[i].second) - sumAib(v[i].second);
  }
  memset(aib, 0, sizeof aib);
  memset(cnt, 0, sizeof cnt);
  idx = n;
  for (int i = n; i >= 1; i--) {
    while (v[idx].first - 1 > v[i].first) {
      update(v[idx].first, v[idx].second);
      idx--;
    }
    answer += v[i].first * countAib(v[i].second) - sumAib(v[i].second);
  }
  cout << setprecision(0) << fixed << answer + eps;
  return 0;
}
