#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
const long long mod = 1000000007;
int n;
long long a[maxn], pre[maxn], su[maxn];
long long ans;
long long rec[maxn];
long long fp(long long a, int b) {
  long long Ans = 1;
  while (b) {
    if (b & 1) Ans = (Ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return Ans;
}
void Get_fix() {
  memset(pre, 0, sizeof(pre));
  memset(su, 0, sizeof(su));
  pre[0] = a[0];
  su[n - 1] = a[n - 1];
  for (int i = 1; i < n; ++i) pre[i] = (pre[i - 1] + a[i]) % mod;
  for (int i = n - 1; i >= 0; --i) su[i] = (a[i] + su[i + 1]) % mod;
}
void out() {
  for (int i = 0; i < n; ++i) printf("%I64d ", pre[i]);
  printf("\n");
  for (int i = 0; i < n; ++i) printf("%I64d ", su[i]);
  printf("\n");
}
int main() {
  for (int i = 0; i < maxn; ++i) {
    rec[i] = fp(2LL, i);
  }
  while (~scanf("%d", &n)) {
    ans = 0;
    for (int i = 0; i < n; ++i) scanf("%I64d", a + i);
    sort(a, a + n);
    Get_fix();
    for (int len = 0; len < n; ++len) {
      ans += (rec[len] * ((su[n - len - 1] - pre[len]) % mod)) % mod;
      ans %= mod;
    }
    printf("%I64d\n", (ans + mod) % mod);
  }
  return 0;
}
