#include <bits/stdc++.h>
using namespace std;
long long A[1111111];
long long P[1111111];
void preprocess(long long n) {
  long long p = 2;
  P[0] = 1;
  P[1] = 2;
  for (long long i = 2; i <= n; ++i) {
    P[i] = (P[i - 1] * 2) % 1000000007;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n;
  int i;
  cin >> n;
  for (i = 0; i < n; ++i) cin >> A[i];
  preprocess(n);
  sort(A, A + n, greater<int>());
  long long s = 0;
  for (i = 0; i < n; ++i) {
    s += (A[i] * (P[n - i - 1] - P[i])) % 1000000007;
    s %= 1000000007;
  }
  if (s < 0)
    cout << 1000000007 + s << '\n';
  else
    cout << s << '\n';
  return 0;
}
