#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 100000 + 1;
const long long mod = 1000000000 + 7;
const long long inv2 = 500000004;
long long pow2[maxn];
long long sum2[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> vc(n);
  for (int i = 0; i < n; ++i) cin >> vc[i];
  sort(vc.begin(), vc.end());
  pow2[0] = 1;
  for (int i = 1; i <= n; ++i) pow2[i] = 2LL * pow2[i - 1] % mod;
  long long cur = 0;
  long long ans = 0;
  vector<long long> last;
  for (int i = 1; i < n; ++i) {
    cur += (1LL * (vc[i] - vc[0]) * pow2[i - 1]) % mod;
    cur %= mod;
    sum2[i - 1] = pow2[i - 1];
    if (i - 2 >= 0) sum2[i - 1] += sum2[i - 2];
    sum2[i - 1] %= mod;
  }
  ans += cur;
  for (int i = 1; i < n; ++i) {
    cur =
        ((cur - 1LL * (vc[i] - vc[i - 1]) * sum2[n - 1 - i]) % mod + mod) % mod;
    cur = (cur * inv2) % mod;
    ans = (ans + cur) % mod;
  }
  cout << ans << endl;
  return 0;
}
