#include <bits/stdc++.h>
const int Max = 500005;
using namespace std;
long long a[Max], b[Max], sum = 0;
int main() {
  int n;
  b[0] = 1;
  for (int i = 1; i <= 400000; i++) {
    b[i] = b[i - 1] * 2;
    b[i] %= 1000000000 + 7;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    sum += 1LL * a[i] * (b[i] - 1);
    sum %= 1000000000 + 7;
  }
  for (int i = 0; i < n - 1; i++) {
    sum -= 1LL * a[i] * (b[n - i - 1] - 1);
    sum %= 1000000000 + 7;
  }
  if (sum < 0) {
    sum += 1000000000 + 7;
    sum %= 1000000000 + 7;
  }
  cout << sum << endl;
  return 0;
}
