#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ret = 0;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long prefix = 1;
  for (int i = 1; i < n; i++) {
    long long curVal = (prefix * a[i]) % 1000000007LL;
    ret = (ret + curVal) % 1000000007LL;
    prefix = (prefix * 2LL + 1LL) % 1000000007LL;
  }
  vector<long long> coEff(n);
  prefix = 1;
  for (int i = n - 1; i >= 0; i--) {
    coEff[i] = prefix - 1LL;
    prefix = (prefix * 2LL) % 1000000007LL;
  }
  for (int i = 0; i < n; i++) {
    long long curVal = (coEff[i] * a[i]) % 1000000007LL;
    ret -= curVal;
    if (ret < 0) {
      ret += 1000000007LL;
    }
  }
  cout << ret << endl;
}
