#include <bits/stdc++.h>
using namespace std;
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
long long int a[300005];
long long int val[300005];
int main() {
  long long int n;
  long long int temp1 = 0, temp = 0, temp2 = 0, temp3 = 0, temp4 = 0;
  long long int sum = 0;
  cin >> n;
  if (n == 1) {
    cout << "0 \n";
    return 0;
  }
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  sum = a[1] - a[0];
  val[1] = sum;
  for (long long int i = 2; i < n; i++) {
    temp = val[i - 1];
    temp1 = (modpow((long long int)2, i - 1, (long long int)1000000007) - 1) %
            1000000007;
    temp2 = (temp1 * (a[i] - a[i - 1])) % 1000000007;
    temp3 = (temp + temp2) % 1000000007;
    temp4 = ((2 * temp3) % 1000000007 + (a[i] - a[i - 1])) % 1000000007;
    val[i] = temp4;
  }
  for (long long int i = 2; i < n; i++) sum = (sum + val[i]) % 1000000007;
  cout << sum << "\n";
  return 0;
}
