#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, m = 1e9 + 7, x, sum = 0, ans = 1;
  cin >> n;
  vector<long long> v, r;
  for (i = 0; i < n; ++i) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  r.push_back(1);
  for (i = 0; i < n; ++i) {
    ans = (ans * 2) % m;
    r.push_back(ans);
  }
  for (i = 0; i < n; ++i) {
    sum += (v[i] * (r[i] - r[n - i - 1])) % m;
    sum = sum % m;
  }
  cout << sum % m;
}
