#include <bits/stdc++.h>
using namespace std;
long long pw(long long a, long long k, long long p) {
  if (k == 0) return 1;
  return (k % 2 == 0 ? pw((a * a) % p, k / 2, p) : (a * pw(a, k - 1, p)) % p);
}
int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> V(n);
  for (int i = 0; i < n; ++i) cin >> V[i];
  sort(V.begin(), V.end());
  long long ans = 0, d = 1, s = 0, P = 1000000007;
  long long dm = pw(2, n - 2, P), odw = pw(2, P - 2, P);
  for (int i = 0; i < n / 2; ++i) {
    s += V[n - i - 1] - V[i];
    s %= P;
    if (n % 2 != 0 || i != n / 2 - 1)
      ans += s * (d + dm);
    else
      ans += s * d;
    ans %= P;
    dm = (dm * odw) % P;
    d = (d * 2) % P;
  }
  cout << ans << endl;
}
