#include <bits/stdc++.h>
using namespace std;
long long MAX = 1e+9 + 7;
int dp(int n, vector<long long> a) {
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    vector<long long> b = a;
    if (i > 0) {
      b.insert(next(b.begin(), i - 1), b.at(i - 1) + b.at(i));
      b.erase(next(b.begin(), i));
    }
    b.erase(next(b.begin(), i));
    ans += (a.at(i) + dp(n - 1, b)) % MAX;
  }
  return ans;
}
int main(void) {
  int N;
  cin >> N;
  vector<long long> x(N), a(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    a.at(i) = x.at(i + 1) - x.at(i);
  }
  int ans = dp(N - 1, a);
  cout << ans << endl;
}
