#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long a[3 * 100005];
long long hh(long long x, long long y) {
  long long s = 1;
  while (y) {
    if (y & 1) s = s * x % mod, y--;
    x = x * x % mod;
    y /= 2;
  }
  return s;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  long long sum = 0;
  sort(a + 1, a + 1 + n);
  long long x = 0;
  for (int j = 0; j <= n - 2; j++) x = (x + hh(2, j) + mod) % mod;
  long long t = 0, tt = n - 2;
  ;
  for (int i = 1; i <= n / 2; i++) {
    sum = (sum - x * a[i] + mod) % mod;
    sum = (sum + x * a[n + 1 - i] + mod) % mod;
    x = (x - hh(2, t) - hh(2, tt) + mod) % mod;
    t++;
    tt--;
  }
  cout << (sum + mod) % mod << endl;
}
