#include <bits/stdc++.h>
using namespace std;
int main() {
  bool ok = true;
  int n;
  cin >> n;
  map<int, int> m1;
  long double ans = 0, s = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    s += a;
    m1[a]++;
    ans += (long double)i * a - s;
    ans += m1[a + 1] - m1[a - 1];
  }
  printf("%.0Lf", ans);
}
