#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n];
  int l[n - 1];
  int c = 0;
  int arr[n - 1];
  for (int i = 0; i < n - 1; i++) {
    arr[i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  do {
    for (int i = 0; i < n - 1; i++) {
      l[i] = (x[i + 1] - x[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      c += l[arr[i]];
      if (arr[i] != 0) {
        l[arr[i] - 1] += l[arr[i]];
      }
    }
  } while (std::next_permutation(arr, arr + n));
  c = c % 1000000007;
  cout << c;
}
