#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, sum = 0, t;
  long double ans = 0;
  map<long long, unsigned> mp;
  scanf("%I64d", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%I64d", &t);
    ans += t * i - sum - mp[t - 1] + mp[t + 1];
    mp[t]++;
    sum += t;
  }
  cout << fixed << setprecision(0) << ans << endl;
}
