#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const long long mod = 1e9 + 7;
long long a[N];
int n;
long long fast(long long b, long long e) {
  if (!e) return 1;
  return ((e & 1) ? b : 1) * fast(b * b % mod, e / 2) % mod;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", a + i);
  sort(a, a + n);
  long long cur = 0;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (i) {
      long long x = (fast(2, i) - 1 + mod) % mod;
      ans += ((a[i] * x) % mod - cur + mod) % mod;
      ans %= mod;
    }
    cur = (cur * 2) % mod;
    cur = (cur + a[i]) % mod;
  }
  cout << ans << '\n';
  return 0;
}
