#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long x[n];
  for (int i = 0; i < n; i++) scanf("%lld", &x[i]);
  long long dp[1 << (n - 1)][n];
  long long y = 1e9 + 7;
  for (int i = 0; i < 1 << (n - 1); i++) {
    for (int j = 0; j < n; j++) dp[i][j] = 0;
  }
  dp[1][0] = x[1] - x[0];
  int sub;
  int right;
  for (int i = 2; i < (1 << (n - 1)); i++) {
    for (int j = 0; j < n - 1; j++) {
      if ((i & (1 << j)) == 0) continue;
      sub = i ^ (1 << j);
      right = n - 1;
      for (int k = j + 1; k < n - 1; k++) {
        if (sub & (1 << k)) continue;
        right = k;
        break;
      }
      if (sub == 0) dp[i][j] += x[right] - x[j];
      for (int k = 0; k < n - 1; k++) {
        if (k == j || (i & (1 << k)) == 0) continue;
        if (i == 3 && j == 0) cout << right << endl;
        dp[i][j] += dp[sub][k] + (x[right] - x[j]);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += dp[(1 << (n - 1)) - 1][i];
  }
  cout << ans % y << endl;
  return 0;
}
