#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::map<long long, int> freqs;
  long double common_sum = 0, prev_sum = 0, overall_sum = 0;
  long double curr_number, prev_number;
  std::cin >> curr_number;
  prev_number = curr_number;
  freqs[prev_number] += 1;
  for (int i = 1; i != n; ++i) {
    std::cin >> curr_number;
    common_sum = common_sum + i * (curr_number - prev_number);
    long double a5 = 1 * freqs[curr_number - 1];
    long double a7 = -1 * freqs[curr_number + 1];
    prev_sum = common_sum - a5 - a7;
    freqs[curr_number] += 1;
    prev_number = curr_number;
    overall_sum += prev_sum;
  }
  std::cout << std::fixed << std::setprecision(0) << overall_sum;
}
