#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int N, x[300001];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  sort(x, x + N);
  vector<long long> pows(N);
  pows[0] = 1;
  for (int i = 1; i < N; i++) {
    pows[i] = pows[i - 1] * 2;
    pows[i] %= MOD;
  }
  for (int i = 1; i < N; i++) {
    pows[i] += pows[i - 1];
    pows[i] %= MOD;
  }
  long long result = 0;
  for (int i = 0; i < N; i++) {
    long long a = (i > 0 ? pows[i - 1] : 0);
    long long b = (i < N - 1 ? pows[N - i - 2] : 0);
    result += (a - b) * x[i];
    result %= MOD;
  }
  if (result < 0) result += MOD;
  cout << result << '\n';
  return 0;
}
