#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long x[300001];
long long p[300001] = {1};
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
    p[i + 1] = p[i] * 2 % MOD;
  }
  sort(x, x + n);
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    ret = (ret + x[i - 1] * (p[i - 1] - p[n - i])) % MOD;
  }
  cout << (ret + MOD) % MOD;
}
