#include <bits/stdc++.h>
using namespace std;
long long bigpower(long long x, long long y, long long N) {
  long long ans = 1;
  long long power = x;
  while (y > 0) {
    if (y % 2 == 1) ans = (ans * power) % N;
    power = (power * power) % N;
    y /= 2;
  }
  return ans % 1000000007;
}
int main() {
  long long n;
  cin >> n;
  long long sum = 0;
  vector<long long> a;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.rbegin(), a.rend());
  for (long long i = 0; i < n; i++) {
    long long p = bigpower(2, n - i - 1, 1000000007);
    long long q = bigpower(2, i, 1000000007);
    long long x = ((a[i] % 1000000007) * (p - 1) % 1000000007) % 1000000007;
    long long y = ((a[i] % 1000000007) * (q - 1) % 1000000007) % 1000000007;
    sum = (sum % 1000000007 + x % 1000000007) % 1000000007;
    sum = (sum % 1000000007 - y % 1000000007 + 1000000007) % 1000000007;
  }
  cout << sum % 1000000007 << endl;
  return 0;
}
