#include <bits/stdc++.h>
using namespace std;
int n;
long long sum;
long long data[300005];
int data1[300005];
int main() {
  data1[0] = 1;
  for (int i = 1; i < 300005; i++) {
    data1[i] = 2 * data1[i - 1] % 1000000007;
  }
  while (cin >> n) {
    sum = 0;
    for (int i = 0; i < n; i++) cin >> data[i];
    sort(data, data + n);
    for (int i = 0; i < n; i++) {
      sum += ((((long long)(data1[i]) - data1[n - 1 - i]) % 1000000007) *
              (data[i] % 1000000007)) %
             1000000007;
      sum %= 1000000007;
    }
    cout << sum << endl;
  }
  return 0;
}
