#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long MOD = 1e9 + 7;
long long fp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return ans;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  vector<long long> x(n);
  for (int i = 0; i < (n); ++i) cin >> x[i];
  sort(x.begin(), x.end());
  long long ans = 0;
  long long dd = 0;
  for (int i = 1; i <= (n - 1); ++i) {
    dd = (2 * dd) % MOD;
    dd = (dd + (fp(2, i) - 1) * (x[i] - x[i - 1]) % MOD) % MOD;
    ans += dd;
  }
  cout << (ans % MOD + MOD) % MOD << endl;
  return 0;
}
