#include <bits/stdc++.h>
using namespace std;
long double a[200005], sum[200005];
map<int, long double> mp;
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long double diffsum = 0;
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum[i] = a[i];
    if (i > 0) sum[i] += sum[i - 1];
  }
  long double j = 1;
  for (i = 1; i < n; i++) {
    diffsum += (j * a[i] - sum[i - 1]);
    j++;
  }
  mp[a[n - 1]]++;
  for (i = n - 2; i >= 0; i--) {
    diffsum -= mp[a[i] + 1];
    diffsum += mp[a[i] - 1];
    mp[a[i]]++;
  }
  cout << fixed << setprecision(0) << diffsum;
  return 0;
}
