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