#include <bits/stdc++.h>
using namespace std;
int factorialMethod(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
int main() {
  int N;
  int x[N];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  int k, m;
  int distance = 0;
  int now;
  random_device rnd;
  for (int i = 1; i < N; i++) {
    m = ((rnd() % (N - i - 1)) + 1);
    int mcount = 0;
    for (int n = 0; n < m; n++) {
      if (x[n] == -1) {
        mcount += 1;
      }
    }
    k = m - mcount;
    distance += (x[k + 1] - x[k]);
    now = x[k];
    for (int j = 0; j < N; j++) {
      if (x[i] == now && i != k) {
        x[i] = -1;
      }
    }
  }
  cout << distance * factorialMethod(N - 1) << "\n";
}
