#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int oo = 1000000007;
int n;
long long x[N], ssuf[N], p[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &x[i]);
  }
  sort(x + 1, x + n + 1);
  for (int i = 1; i <= n; ++i) ssuf[i] = ssuf[i - 1] + x[i];
  int k = 1;
  p[0] = 1;
  for (int i = 1; i <= n; ++i) p[i] = (p[i - 1] * 2) % oo;
  long long ans = 0;
  for (int l = 1; l <= n; ++l) {
    long long tmp = -ssuf[n - l] + ssuf[n] - ssuf[l];
    tmp %= oo;
    ans += (tmp * p[l - 1]) % oo;
    ans %= oo;
  }
  cout << ans;
}
