#include <bits/stdc++.h>
using namespace std;
signed main(signed argc, char* argv[]) {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  const long long MOD = 1000000007;
  long long n, ans = 0;
  cin >> n;
  vector<long long> fact(n), a(n), tw(n);
  fact[0] = 1;
  tw[0] = 1;
  cin >> a[0];
  for (long long i = 1; i < n; i++) {
    cin >> a[i];
    fact[i] = fact[i - 1] * i % MOD;
    tw[i] = tw[i - 1] * 2 % MOD;
  }
  long long sum = a[n - 2] - a[0];
  long long mn = 0, mn_sum = 0;
  for (long long i = 0; i < n - 2; i++) {
    if (i) {
      mn_sum += a[i] - a[i - 1] + a[n - 2] - a[n - 2 - i];
      mn = mn + mn_sum;
    }
    ans = (ans +
           (sum * (i + 1) - mn) % MOD * tw[n - i - 3] % MOD * fact[i] % MOD) %
          MOD;
    ans = (ans + (a[n - 1] - a[n - 2 - i]) % MOD * tw[n - i - 2] % MOD *
                     fact[i] % MOD) %
          MOD;
  }
  ans = (ans + (a[n - 1] - a[0]) % MOD * fact[n - 2] % MOD) % MOD;
  cout << ans << endl;
}
