#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll N = 300005;
ll ara[N], sum[N], total;
int main() {
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ara[i];
  }
  sort(ara, ara + n);
  sum[0] = 1;
  for (int i = 1; i < n; i++) {
    sum[i] = ((sum[i - 1] % mod) * (2 % mod)) % mod;
  }
  for (int i = 0; i < n; i++) {
    total += ara[i] * (sum[i] - sum[n - 1 - i]);
    total = total % mod;
  }
  cout << total << "\n";
  return 0;
}
