#include <bits/stdc++.h>
using namespace std;
int n;
long long f[300003];
long long e2[300003];
int main(void) {
  ios::sync_with_stdio(0);
  cin >> n;
  e2[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    e2[i] = (e2[i - 1] << 1) % ((long long)1e9 + 7);
  }
  sort(f + 1, f + n + 1);
  long long res = 0;
  for (int i = 1; i <= n; i++)
    res = (res + (e2[i - 1] - e2[n - i]) * f[i] % ((long long)1e9 + 7)) %
          ((long long)1e9 + 7);
  cout << res << endl;
}
