#include <bits/stdc++.h>
using namespace std;
vector<int> x;
int modulo_sum(int a, int b) {
  return ((a % 1000000007) + (b % 1000000007)) % 1000000007;
}
int modulo_subtract(int a, int b) {
  return ((a % 1000000007) - (b % 1000000007)) % 1000000007;
}
int modulo_mult(int a, int b) { return ((long long)a * b) % 1000000007; }
int power(int n) {
  int ini = 2;
  int ret = 1;
  while (n >= 1) {
    if (n % 2 == 1) ret = modulo_mult(ret, ini);
    ini = modulo_mult(ini, ini);
    n /= 2;
  }
  return ret;
}
int powerr[300005];
int main() {
  int n;
  cin >> n;
  powerr[0] = 1;
  for (int i = 1; i <= n; i++) {
    powerr[i] = modulo_sum(powerr[i - 1], powerr[i - 1]);
    int apl;
    cin >> apl;
    x.push_back(apl);
  }
  x.push_back(0);
  sort(x.begin(), x.end());
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = modulo_sum(
        ans,
        modulo_mult(modulo_sum(powerr[i - 1], (-1) * powerr[n - i]), x[i]));
  }
  cout << ans << endl;
  return 0;
}
