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