#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n];
  long long int sum = 0, positive = 0, negative = 0, power = 1,
                mod = (pow(10, 9) + 7);
  for (int i = 0; i <= n - 1; i++) {
    cin >> x[i];
  }
  sort(x, x + n);
  for (int i = 0; i <= n - 1; i++) {
    positive += (long long)x[n - 1 - i];
    positive %= mod;
    negative += (long long)x[i];
    negative %= mod;
    sum += (positive >= negative)
               ? ((positive - negative) * power) % mod
               : mod + (((positive - negative) * power) % mod);
    sum %= mod;
    power *= 2;
    power %= mod;
  }
  cout << sum << "\n";
  return 0;
}
