#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 200042;
const long long m = 1e9 + 7;
long long add(long long x, long long y) {
  x = (1ll * x + m + y) % m;
  return x;
}
long long mul(long long x, long long y) {
  long long ans = (x * 1ll * y) % m;
  while (ans < 0) ans += m;
  return ans;
}
long long binpow(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
long long inv(long long x) { return binpow(x, m - 2); }
long long divide(long long x, long long y) { return mul(x, inv(y)); }
long long fact[N];
void precalc() {
  fact[0] = 1;
  for (long long i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
long long C(long long n, long long k) {
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
long long A(long long n, long long m) { return divide(fact[n], fact[n - m]); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n = 0;
  cin >> n;
  vector<long long> x(n);
  for (auto& c : x) cin >> c;
  sort((x).begin(), (x).end());
  long long ansmn = 0, ansmx = 0;
  for (int i = 0; i < n; i++) {
    ansmn = add(ansmn, mul(x[i], binpow(2, n - i - 1)));
    ansmx = add(ansmx, mul(x[i], binpow(2, i)));
  }
  cout << add(ansmx, -ansmn);
  return 0;
}
