#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m;
int main() {
  long long int n, i, sum = 0, x;
  long double ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    ans = ans + (i * x - sum);
    sum = sum + x;
    if (m.count(x - 1)) ans = ans - m[x - 1];
    if (m.count(x + 1)) ans = ans + m[x + 1];
    m[x]++;
  }
  cout << fixed << setprecision(0) << ans;
}
