#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (T x : p) os << x << " ";
  os << "]" << endl;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "{ ";
  for (T x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const map<Tk, Tv>& p) {
  os << "{ ";
  for (pair<Tk, Tv> x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) {
  os << "{" << p.first << ',' << p.second << "}";
  return os;
}
const int MOD = 1000000000 + 7;
const int INF = 1000000000 + 5;
const int MAX = 300005;
long long power(long long n, long long m) {
  if (m == 0) return 1;
  long long x = power(n, m / 2);
  if (!(m & 1))
    return (x * x) % 1000000007;
  else
    return (((x * x) % 1000000007) * n) % 1000000007;
}
long long p2[MAX + 5];
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x[i]);
  }
  sort(x.begin(), x.end());
  p2[0] = 1;
  for (int i = 1; i < MAX; i++) {
    p2[i] = (p2[i - 1] << 1);
    if (p2[i] >= 1000000007) p2[i] -= 1000000007;
  }
  vector<long long> X(n), P(n);
  for (int i = 0; i < n; i++) {
    long long p = p2[i];
    X[i] = (x[i] * p) % 1000000007;
    P[i] = p;
  }
  for (int i = n - 2; i >= 0; i--) {
    X[i] += X[i + 1];
    if (X[i] >= 1000000007) X[i] -= 1000000007;
    P[i] += P[i + 1];
    if (P[i] >= 1000000007) P[i] -= 1000000007;
  }
  long long Answer = 0;
  for (int i = 0; i < n - 1; i++) {
    long long ans =
        (X[i + 1] + 1000000007 - (x[i] * P[i + 1]) % 1000000007) % 1000000007;
    ans *= power(p2[i + 1], 1000000007 - 2);
    ans %= 1000000007;
    Answer += ans;
    if (Answer >= 1000000007) Answer -= 1000000007;
  }
  cout << Answer << endl;
}
