#include <bits/stdc++.h>
using namespace std;
int select(vector<int> x, int selected) {
  if (x.size() == 2) {
    return x[1] - x[0];
  }
  int sum = (x[selected + 1] - x[selected]) * (x.size() - 2) % 1000000007;
  x.erase(x.begin() + selected);
  for (int i = 0; i < x.size() - 1; i++) {
    sum = (sum + select(x, i)) % 1000000007;
  }
  return sum;
}
int main() {
  int N;
  cin >> N;
  vector<int> x;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    x.push_back(num);
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans = (ans + select(x, i)) % 1000000007;
  }
  cout << ans << endl;
}
