#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using db = double;
const int mxn = 300006;
const ll mod = 1E9L + 7;
int n;
ll a[mxn];
ll p[mxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  sort(a, a + n);
  p[0] = 1;
  for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 2 % mod;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans -= a[i] * p[n - 1 - i];
    ans += a[i] * p[i];
    ans %= mod;
  }
  cout << (ans + mod) % mod << endl;
  return 0;
}
