#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, q, k;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
long long arr[N];
string str, ss;
long long pw[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  sort(arr + 1, arr + 1 + n);
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = (pw[i - 1] * 2) % mod;
  long long sol = 0, cursum = 0;
  for (int i = 1; i <= n; ++i) {
    sol += (pw[i - 1] - 1) * arr[i] - cursum;
    sol %= mod;
    cursum = cursum * 2 + arr[i];
    cursum %= mod;
  }
  cout << sol << endl;
  return 0;
}
