#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int Mod = 1e9 + 7;
int n;
long long x[maxn], sum1;
long long c[maxn];
int main() {
  cin >> n;
  c[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    c[i + 1] = (c[i] * 2) % Mod;
  }
  sort(x, x + n);
  for (int i = 0; i < n; i++) {
    sum1 += (c[i] - c[n - i - 1]) * x[i] % Mod;
    sum1 %= Mod;
  }
  cout << sum1 << endl;
  return 0;
}
