#include <bits/stdc++.h>
using namespace std;
long long sho = 1000000007;
int n;
vector<int> xv;
vector<vector<int>> diff;
long long ret;
void func(int ix, vector<bool> flag, long long sum) {
  flag[ix] = true;
  int ri = n - 1;
  for (int j = ix + 1; j < n - 1; ++j) {
    if (!flag[j]) {
      ri = j;
      break;
    }
  }
  sum += diff[ix][ri];
  bool isNext = false;
  for (int j = 0; j < n - 1; ++j) {
    if (!flag[j]) {
      isNext = true;
      func(j, flag, sum);
    }
  }
  if (!isNext) {
    ret = (ret + sum) % sho;
  }
}
int main() {
  ret = 0;
  cin >> n;
  xv.resize(n);
  for (auto& x : xv) {
    cin >> x;
  }
  diff.resize(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      diff[i][j] = xv[i] - xv[j];
    }
    for (int j = i; j < n; ++j) {
      diff[i][j] = xv[j] - xv[i];
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    long long sum = 0;
    vector<bool> flag(n - 1, false);
    func(i, flag, sum);
  }
  cout << ret << endl;
  return 0;
}
