#include <bits/stdc++.h>
using namespace std;
long long int n, a[300100], x, y, sm, p, q, prod[300100], c, j;
stack<long long int> s;
int main() {
  cin >> n;
  c = 1;
  j = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    prod[j++] = c;
    c = c * 2;
    c = c % 1000000007;
  }
  sort(a, a + n);
  sm = 0;
  for (long long int i = 0; i < n; i++) {
    x = i;
    y = n - i - 1;
    p = prod[x] % 1000000007;
    q = prod[y] % 1000000007;
    sm = (sm % 1000000007 +
          ((a[i] % 1000000007) * ((p - q) % 1000000007)) % 1000000007) %
         1000000007;
  }
  cout << sm << "\n";
  return 0;
}
