#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int maxn = (5e2 + 10);
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
using namespace std;
map<long long, long long> ys;
long long a[200010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  long double ans = 0, sum = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    ys[a[i]] += 1;
  }
  for (long long i = 1; i <= n; i++) {
    ans += sum - (long double)(n - i + 1) * (long double)a[i];
    ans += ys[a[i] - 1] - ys[a[i] + 1];
    sum -= a[i];
    ys[a[i]] -= 1;
  }
  cout << fixed << setprecision(0) << ans;
  return 0;
}
