#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long mod_pow(long long base, long long exponent) {
  if (exponent == 0) return 1;
  long long temp = mod_pow(base, exponent / 2);
  long long res;
  if (exponent % 2) {
    res = (((temp * temp) % mod) * base) % mod;
  } else {
    res = (temp * temp) % mod;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int minus = n - i - 1;
    int plus = i;
    long long num_minus = mod_pow(2, minus);
    long long num_plus = mod_pow(2, plus);
    ans = (ans + (arr[i] * (num_plus - num_minus)) % mod) % mod;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
