#include <bits/stdc++.h>
using namespace std;
long double ans;
map<long long int, long long int> mp;
long long int n;
long long int y, x, t, t1;
long long int s[300001], a[300001];
int main() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (long long int i = n; i >= 1; i--) s[i] = s[i + 1] + a[i];
  for (long long int i = (long long)1; i < n; i++) {
    mp[a[i]]--;
    ans += s[i + 1] - (n - i) * a[i] - mp[a[i] + 1] + mp[a[i] - 1];
  }
  printf("%.0Lf\n", ans);
  return 0;
}
