#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int n, i, a;
long double sum, ans;
map<int, int> frq;
int number[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &number[i]);
  for (i = n; i >= 1; i--) {
    a = number[i];
    sum += a;
    ans -= a * 1LL * (n - i + 1) - sum;
    ans -= frq[a + 1] - frq[a - 1];
    frq[a]++;
  }
  cout << fixed << setprecision(0) << ans;
  return 0;
}
