#include <bits/stdc++.h>
using namespace std;
double pi = 3.141592653589793;
long long mod = 1000000007;
long long INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
long long llmax = 9223372036854775807;
long long llmin = -9223372036854775807;
int main() {
  int n, left = 0;
  long long ans = 0, tmp;
  cin >> n;
  vector<long long> x(n), y(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    y[i] = i;
  }
  do {
    for (int i = 0; i < n - 1; i++) {
      b[i] = 1;
    }
    for (int i = 0; i < n - 1; i++) {
      ans += x[y[i] + b[y[i]]] - x[y[i]];
      ans %= mod;
      tmp = y[i];
      while (1) {
        if (b[y[i] - tmp] > 0) {
          b[y[i] - tmp] += b[y[i]];
          break;
        } else
          tmp++;
        if (y[i] - tmp == 0) {
          break;
        }
      }
      b[y[i]] = 0;
    }
  } while (next_permutation(y.begin(), y.end() - 1));
  cout << ans << endl;
}
