#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
  int n;
  scanf("%d", &n);
  vector<ll> v(n);
  vector<int> permutation(n - 1);
  for (int i = 0; i < (n); ++i) {
    cin >> v[i];
    if (i != n - 1) permutation[i] = i;
  }
  ll base_length = v[n - 1] - v[0];
  ll ans = 0;
  do {
    ans += base_length;
    for (int i = 0; i < (n - 1); ++i) {
      if (permutation[i] > i) {
        ans += v[permutation[i] + 1] - v[permutation[i]];
      }
    }
  } while (next_permutation((permutation).begin(), (permutation).end()));
  cout << ans % 1000000007;
  cout << "\n";
  return 0;
}
