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