#include <bits/stdc++.h>
using namespace std;
long long pow2(int n) {
  if (n == 0) return 1;
  if (n % 2) return (2 * (pow2(n - 1))) % 1000000007;
  long long ans = pow2(n / 2);
  return ((ans % 1000000007) * (ans % 1000000007)) % 1000000007;
}
int main() {
  int n;
  cin >> n;
  vector<long long> x(n), sum(n, 0);
  for (int i = 0; i < n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  sum[0] = x[0];
  for (int i = 1; i < n; i++) sum[i] = (sum[i - 1] + x[i]);
  long long ans = 0;
  vector<long long> diff(n - 1, 0);
  for (int i = 0; i < n - 1; i++) {
    diff[i] = sum[n - 1] - sum[i];
    diff[i] -= sum[n - 2 - i];
    diff[i] %= 1000000007;
  }
  for (int i = 0; i < n - 1; i++) {
    ans =
        ((pow2(n - 2 - i) * diff[n - 2 - i]) % 1000000007 + ans % 1000000007) %
        1000000007;
  }
  cout << ans % 1000000007 << endl;
}
