#include <bits/stdc++.h>
bool debug = 1;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
long long v[200100];
long long sum[200100];
map<long long, vector<int> > pos;
long long n;
long long check() {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      if (abs(v[j] - v[i]) > 1) {
        res += v[j] - v[i];
      }
    }
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    pos[v[i]].push_back(i);
  }
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + v[i];
  }
  long double res = 0;
  for (long long i = 1; i <= n; i++) {
    res += sum[n] - sum[i];
    res -= v[i] * (n - i);
  }
  for (int i = 1; i <= n; i++) {
    long long ant = v[i] - 1;
    long long prox = v[i] + 1;
    if (pos.find(ant) != pos.end()) {
      res += (long double)(pos[ant].end() -
                           lower_bound(pos[ant].begin(), pos[ant].end(), i));
    }
    if (pos.find(prox) != pos.end()) {
      res -= (long double)(pos[prox].end() -
                           lower_bound(pos[prox].begin(), pos[prox].end(), i));
    }
  }
  printf("%.0Lf\n", res);
  return 0;
}
