#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long double eps = 1e-7;
const long long dd = 1e5;
vector<long long> step;
int main() {
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  long long now = 1;
  step.assign(n * 2, 0);
  for (long long i = 0; i < n * 2; ++i) {
    step[i] = now;
    now *= 2;
    now %= inf;
  }
  vector<long long> dt;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    dt.push_back(x);
  }
  sort(dt.begin(), dt.end());
  vector<long long> dp(n);
  for (long long i = 1; i < dt.size(); ++i) {
    long long delta = dt[i] - dt[i - 1];
    dp[i] = 2ll * dp[i - 1] +
            2ll * delta * (((step[i - 1] - 1) % inf + inf) % inf) + delta;
    dp[i] %= inf;
  }
  long long sum = 0;
  for (auto x : dp) sum += x, sum %= inf;
  cout << sum;
  return 0;
}
