#include <bits/stdc++.h>
using namespace std;
map<long long, long long> c;
long long n, a, sigma;
long double answer;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    answer += (i * a) - sigma;
    answer -= c[a - 1];
    answer += c[a + 1];
    c[a]++;
    sigma += a;
  }
  cout << fixed << setprecision(0) << answer;
  return 0;
}
