#include <bits/stdc++.h>
using namespace std;
double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }
long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
vector<int> parent, rnk;
void make_set(int v) {
  parent[v] = v;
  rnk[v] = 0;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (rnk[a] < rnk[b]) swap(a, b);
    parent[b] = a;
    if (rnk[a] == rnk[b]) rnk[a]++;
  }
}
struct edge {
  int u, v, w;
  bool operator<(edge const& other) { return w < other.w; }
};
long long int n, k, y, h, t, f;
long long int kv, q, r, x, z, w, x1, x2, t1, t2, p;
bool cm(pair<long long int, vector<long long int>> a,
        pair<long long int, vector<long long int>> b) {
  return a.first > b.first;
}
vector<pair<long long int, vector<long long int>>> c(500001);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long int a[n];
  for (long long i = 0; i < int(n); i++) cin >> a[i];
  long long int c[n + 1];
  c[0] = 1;
  for (int i = 1; i <= n; i++)
    c[i] = (c[i - 1] * 2) % (long long int)1000000007;
  sort(a, a + n);
  for (int i = n - 1; i >= 0; i--) {
    kv = (kv + a[i] *
                   ((c[i] - c[n - i - 1] + (long long int)1000000007) %
                    (long long int)1000000007) %
                   (long long int)1000000007) %
         (long long int)1000000007;
  }
  cout << kv;
  return 0;
}
