#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int t;
void solve();
int main() {
  t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
}
void solve() {
  long long mod = 1e9 + 7;
  int n;
  vector<long long> a;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < int(n); ++i) {
    cin >> a[i];
  }
  sort((a).begin(), (a).end());
  long long ans = 0;
  long long p2 = 1;
  for (int i = 0; i < int(n); ++i) {
    ans = (ans + ((a[i] * p2) % mod)) % mod;
    p2 = (p2 * 2) % mod;
  }
  p2 = 1;
  for (int i = n - 1; i >= 0; --i) {
    ans = ((ans - ((a[i] * p2) % mod)) + mod) % mod;
    p2 = (p2 * 2) % mod;
  }
  cout << ans;
}
