#include <bits/stdc++.h>
using namespace std;
const long long mod = 10e9 + 7;
int main() {
  int n;
  cin >> n;
  long long x[n];
  vector<long long> perm;
  for (int i = 0; i < (n); i++) cin >> x[i];
  for (int j = 0; j < (n - 1); j++) perm.push_back(x[j]);
  long long sum = 0;
  do {
    for (int i = 0; i < (n - 1); i++) {
      if (i == n - 2)
        sum += abs(x[n - 1] - perm[i]);
      else
        sum += abs(perm[i + 1] - perm[i]);
      sum %= mod;
    }
  } while (next_permutation(perm.begin(), perm.end()));
  sum %= mod;
  cout << sum << endl;
  return 0;
}
