#include <bits/stdc++.h>
using namespace std;
static const int INTINF = (2147483647);
static const long long LLINF = (9223372036854775807);
static const int MAX = 2000 + 1;
static const long long MOD = 1e9 + 7;
namespace Printer {
template <class T>
void print(T x) {
  cout << x << endl;
}
template <class T>
void print(T x, T y) {
  cout << x << "," << y << endl;
}
template <class T>
void print(vector<T> v) {
  for (int i = 0; i < (v.size()); ++i) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
template <class T>
void print(vector<vector<T> > vv) {
  for (int i = 0; i < (vv.size()); ++i) {
    for (int j = 0; j < (vv[i].size()); ++j) {
      if (j) cout << " ";
      cout << vv[i][j];
    }
    cout << endl;
  }
}
void print(pair<int, int> p) {
  cout << "(" << p.first << ", " << p.second << ")" << endl;
}
};  // namespace Printer
using namespace Printer;
long long N;
long long X[MAX];
long long dp[MAX][MAX];
long long calc(int a, int b, double num) {
  if (a == b) {
    return 0;
  }
  if (dp[a][b] != -1) {
    return dp[a][b];
  }
  dp[a][b] = 0;
  if (b - a <= 1) {
    dp[a][b] = X[b] - X[a];
    dp[a][b];
  } else {
    for (int i = 1; i < (num + 1); ++i) {
      dp[a][b] += (X[b] - X[a + i - 1] + calc(a, a + i - 1, num - 1) +
                   calc(a + i, b, num - 1));
      dp[a][b] %= MOD;
    }
  }
  return dp[a][b];
}
long long solve(long long a, long long num) {
  if (num == 1) {
    return a * num;
  }
  long long tmp = solve(a, num - 1);
  while (tmp > MOD) {
    tmp -= MOD;
  }
  return tmp * num;
}
int main(int argc, const char* argv[]) {
  cin >> N;
  for (int i = 0; i < (N); ++i) cin >> X[i];
  for (int i = 0; i < (MAX); ++i) {
    fill(dp[i], dp[i] + MAX, -1);
  }
  long long ans = calc(0, N - 1, N - 1);
  ans %= MOD;
  print(long long(ans));
  return 0;
}
