#include <bits/stdc++.h>
using namespace std;
const long long m = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  long long a[n + 1], x[n + 1], b = 0;
  a[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    a[i + 1] = (a[i] * 2) % m;
  }
  sort(x, x + n);
  for (int i = 0; i < n; i++) {
    b += (x[i] * (a[i] - a[n - i - 1])) % m;
    b %= m;
  }
  cout << b % m;
  return 0;
}
