#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const double g = 10.0, eps = 1e-9;
const int N = 300000 + 10, maxn = 16, inf = 9999999;
long long a[N], sum[N], p[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  p[0] = 1;
  for (long long i = 1; i <= n; i++) {
    p[i] = p[i - 1] << 1;
    p[i] %= 1000000007;
  }
  sum[0] = 0;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (long long i = 1; i <= n; i++) sum[i] = (sum[i - 1] + a[i]) % 1000000007;
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    ans += (p[i] *
            (sum[n] + 1000000007 - sum[i + 1] + 1000000007 - sum[n - i - 1]) %
            1000000007) %
           1000000007;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}
