#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
void DBG() { cerr << "]" << '\n'; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << h;
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
const int MOD = (int)(1e9) + 7;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &o : a) cin >> o;
  sort(a.begin(), a.end());
  vector<int> pw(n);
  pw[0] = 1;
  for (int i = 1; i < n; i++) pw[i] = 2LL * pw[i - 1] % MOD;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int v = 1LL * a[i] * pw[i] % MOD;
    ans = (ans + v) % MOD;
    v = 1LL * a[i] * pw[n - i - 1] % MOD;
    ans = (ans - v + MOD) % MOD;
  }
  cout << ans << '\n';
  return 0;
}
