#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long two[300300];
long long sum[300300];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  two[0] = 1;
  for (int i = 1; i < 300300; i++) two[i] = (two[i - 1] * 2) % MOD;
  int n;
  cin >> n;
  vector<long long> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  sum[0] = 0;
  for (int i = 1; i < n; i++) sum[i] = (sum[i - 1] + x[i - 1]) % MOD;
  sum[n] = (sum[n - 1] + x[n - 1]) % MOD;
  long long ans = 0;
  for (int i = 0; i <= n - 2; i++) {
    int k = min(n - i - 1, i + 1);
    ans =
        (ans + (two[i] * (MOD * 2 + sum[n] - sum[n - k] - sum[k])) % MOD) % MOD;
  }
  cout << ans;
  return 0;
}
