#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
unsigned long long factorial(int a) {
  if (a > 1) return a * factorial(a - 1);
  return 1;
}
long long positive_modulo(long long i, long long n) { return (i % n + n) % n; }
int main() {
  long long mod2[64];
  long long ans = 0;
  mod2[0] = 2;
  for (long long i = 1; i < 64; i++) {
    mod2[i] = (mod2[i - 1] * mod2[i - 1]) % mod;
  }
  int n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long aans[n], temp = a[0];
  aans[0] = 0;
  ;
  for (long long i = 1; i < n; i++) {
    long long temp2 = 1;
    for (long long j = 0; j < 32; j++) {
      if (1 << (j) & (i)) temp2 = (temp2 * mod2[j]) % mod;
    }
    temp2--;
    aans[i] = (temp2 * a[i] - temp) % mod;
    temp = (temp * 2 + a[i]) % mod;
  }
  ans = 0;
  for (long long i = 0; i < n; i++) {
    ans = (ans + aans[i]) % mod;
  }
  cout << positive_modulo(ans, mod);
  return 0;
}
