#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long int n;
long long int a[N];
long long int pre[N];
long long int po[N];
void brute() {
  po[0] = 1;
  for (long long int i = 1; i < N; i++)
    po[i] = (po[i - 1] + po[i - 1]) % 1000000007;
}
void solve() {
  cin >> n;
  brute();
  for (long long int i = 1; i < n + 1; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (long long int i = 1; i < n + 1; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  long long int ans = 0;
  long long int el = 1;
  for (long long int p = n - 2; p >= 0; p--) {
    long long int x = pre[n] - pre[n - el] - pre[el];
    x = (x + 1000000007) % 1000000007;
    x = (x * po[p]) % 1000000007;
    ans = (ans + x) % 1000000007;
    el++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  while (T--) solve();
  return 0;
}
