#include <bits/stdc++.h>
using namespace std;
long long int temp[300001];
void init() {
  int i;
  temp[0] = 1;
  for (i = 1; i < 300001; i++) {
    temp[i] = (temp[i - 1] * 2) % 1000000007;
  }
}
int main() {
  init();
  long long int n, i, sum1 = 0, sum2 = 0;
  cin >> n;
  long long int arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  for (i = 0; i < n; i++) {
    sum1 = (sum1 + ((temp[i] - 1) * arr[i]) % 1000000007) % 1000000007;
    sum2 = (sum2 + ((temp[n - i - 1] - 1) * arr[i]) % 1000000007) % 1000000007;
  }
  sum1 = sum1 + 1000000007;
  sum1 = (sum1 - sum2) % 1000000007;
  cout << sum1 << endl;
}
