#include <bits/stdc++.h>
using namespace std;
long long mas[1000000];
long long ss[1000000];
long long mod = 1e9 + 7;
long long binpow(long long a, long long n) {
  long long res = 1;
  while (n)
    if (n & 1) {
      res *= a;
      res %= mod;
      --n;
    } else {
      a *= a;
      a %= mod;
      n >>= 1;
    }
  return res;
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> mas[i];
  }
  sort(mas + 1, mas + n + 1);
  long long ans = 0;
  for (long long i = n; i >= 1; --i) {
    ss[i] = ss[i + 1] + mas[i];
  }
  for (long long i = 1; i <= n - 1; ++i) {
    long long st = n - i;
    ans -= mas[i] * (binpow(2, st) - 1);
    ans %= mod;
  }
  for (long long i = n; i >= 2; --i) {
    long long st = i - 1;
    ans += mas[i] * (binpow(2, st) - 1);
    ans %= mod;
  }
  cout << (ans + mod * mod) % mod << endl;
}
