#include <bits/stdc++.h>
using namespace std;
const int max_n = 300005;
long long mod = 1e9 + 7;
long long a[max_n];
long long two[max_n];
long long sum[max_n];
int n;
int main() {
  scanf("%d", &n);
  two[0] = 1;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (i > 0) {
      two[i] = (two[i - 1] * 2) % mod;
    }
  }
  sort(a, a + n);
  long long ans = 0;
  sum[0] = a[0];
  for (int i = 1; i < n; i++) {
    sum[i] = (sum[i - 1] + a[i]) % mod;
  }
  for (int i = 0; i < n - 1; ++i) {
    long long temp = sum[n - 1] - sum[i] - sum[n - 1 - i - 1];
    temp = (temp + mod) % mod;
    ans += (two[i] * temp % mod);
    ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
