#include <bits/stdc++.h>
using namespace std;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const long long infi = 0x3f3f3f3f;
const long long mod = 1000000007;
long long gcd(long long a, long long b);
long long pow(long long a, long long b);
long long maxMin(vector<long long> vec) {
  long long n = static_cast<long long>((vec).size());
  sort((vec).begin(), (vec).end());
  long long min_sum = 0, max_sum = 0;
  for (long long i = 0; i < n; i++) {
    max_sum = 2 * max_sum + vec[n - 1 - i];
    max_sum %= mod;
    min_sum = 2 * min_sum + vec[i];
    min_sum %= mod;
  }
  return (max_sum - min_sum + mod) % mod;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> vec(n);
  for (auto &x : vec) cin >> x;
  cout << maxMin(vec) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(20);
  long long tt;
  tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long pow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
