#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long x[N];
  for (long long i = 0; i < N; i++) {
    cin >> x[i];
  }
  long long ans = 0;
  long long flag = 0;
  long long indexes[N - 1];
  long long p = 1000000007;
  for (long long i = 0; i < N - 1; i++) indexes[i] = i;
  do {
    for (long long n = 0; n < N - 1; n++) {
      for (long long m = n; m < N - 1; m++) {
        if (indexes[n] < indexes[m]) {
          ans = ans - x[n] + x[m];
          flag = 1;
        }
        if (flag == 1) break;
      }
      if (flag == 0) {
        ans = ans + x[N - 1] - x[n];
      }
      flag = 0;
      if (ans > p) {
        ans = ans - p;
      }
    }
  } while (std::next_permutation(indexes, indexes + N - 1));
  cout << ans << endl;
}
