#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 1e5;
const long long mod = 1e9 + 7;
long long k[maxn + 5];
long long fac2[maxn + 5];
long long sumfac2[maxn + 5];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &k[i]);
  }
  sort(k + 1, k + 1 + n);
  fac2[0] = 1ll;
  sumfac2[1] = 1ll;
  for (int i = 1; i <= n; ++i) {
    fac2[i] = fac2[i - 1] * 2ll % mod;
    sumfac2[i + 1] = (sumfac2[i] + fac2[i]) % mod;
  }
  int l = n - 1, r = 0;
  long long ans = 0ll;
  for (int i = n; i >= 1; --i) {
    ans = (ans + (k[i] * sumfac2[l--] - k[i] * sumfac2[r++]) % mod + mod) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}
