#include <bits/stdc++.h>
using namespace std;
vector<int> v;
long long int pow_bhaji(long long int base, long long int exponent,
                        long long int mod = 1e9 + 7) {
  long long int x = 1;
  long long int y = base;
  while (exponent > 0) {
    if (exponent % 2 == 1) x = (x * 1ll * y) % mod;
    y = (y * 1LL * y) % mod;
    exponent = exponent / 2;
  }
  return x % mod;
}
long long int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  long long int pre = v[0], sol = 0, popw = 2;
  for (int i = 1; i < n; i++) {
    sol =
        (sol + (v[i] * 1ll * ((popw - 1 + mod) % mod)) % mod - pre + mod) % mod;
    pre = (pre * 1ll * 2 + v[i]) % mod;
    popw = (popw * 1ll * 2) % mod;
  }
  cout << sol << "\n";
}
