#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<long long, long long>;
long long const N = 2e5 + 5;
long long n, sm;
ld ans;
map<long long, long long> cnt;
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    ans += i * x - sm;
    sm += x;
    if (cnt.count(x - 1)) ans -= cnt[x - 1];
    if (cnt.count(x + 1)) ans += cnt[x + 1];
    cnt[x]++;
  }
  cout << fixed << setprecision(0) << ans << '\n';
  return 0;
}
