#include <bits/stdc++.h>
using namespace std;
long long data[300005];
long long sum1[300005];
long long sum2[300005];
const long long mod = 1e9 + 7;
long long quickmod(long long a, long long b, long long m) {
  long long t = 1;
  while (b) {
    if (b % 2 == 1) {
      t = t * a % m;
    }
    b = b / 2;
    a = a * a % m;
  }
  return t;
}
int main() {
  long long n;
  while (cin >> n) {
    memset(sum1, 0, sizeof(sum1));
    memset(sum2, 0, sizeof(sum2));
    for (long long i = 1; i <= n; i++) {
      cin >> data[i];
    }
    sort(data + 1, data + 1 + n);
    sum1[0] = sum2[0] = 0;
    for (long long i = 1; i <= n; i++) {
      sum1[i] = sum1[i - 1] + data[i];
      sum2[i] = sum2[i - 1] + data[n + 1 - i];
    }
    long long s = 0;
    for (long long i = 1; i <= n - 1; i++) {
      long long tmp = (sum2[i] - sum1[i]) % mod * quickmod(2, i - 1, mod);
      s = (s + tmp % mod) % mod;
    }
    cout << s << endl;
  }
  return 0;
}
