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