#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmin(T& a, const U& b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T, class U>
bool chmax(T& a, const U& b) {
  if (a >= b) return false;
  a = b;
  return true;
}
const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
int Main(int N, vector<int>& X) {
  mint ans = 0;
  vector<mint> MX(N);
  for (int i = 0; i < (int)(N); i++) MX[i] = X[i];
  vector<int> indices(N - 1);
  for (int i = 0; i < (int)(N - 1); i++) indices[i] = i;
  do {
    vector<int> ref_id(N);
    for (int i = 0; i < (int)(N); i++) ref_id[i] = i;
    for (int i = 0; i < (int)(N - 1); i++) {
      auto it = find(ref_id.begin(), ref_id.end(), indices[i]);
      auto it2 = next(it, 1);
      ans += X[*it2] - X[*it];
      ref_id.erase(it);
    }
  } while (next_permutation(indices.begin(), indices.end()));
  return ans.x;
}
int main(void) {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < (int)(N); i++) cin >> X[i];
  cout << Main(N, X) << endl;
  return 0;
}
