#include <bits/stdc++.h>
using namespace std;
long long N, a[300007], ans, C[300001];
int main() {
  C[1] = 1;
  for (int i = 2; i <= 300000; i++) C[i] = (C[i - 1] * 2 + 1) % 1000000007;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a, a + N);
  for (int i = 0; i < N; i++) {
    long long pref = i, suff = N - i - 1;
    ans += (a[i] * C[pref]) % 1000000007;
    ans -= (a[i] * C[suff]) % 1000000007;
    ans += 1000000007;
    ans %= 1000000007;
  }
  cout << ans;
  return 0;
}
