#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, sum = 0;
  cin >> n;
  vector<long long> x(n), p = {1};
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    p.push_back(p.back() * 2 % 1000000007LL);
  }
  sort(x.begin(), x.end());
  for (int i = 0; i < n - 1; i++)
    sum = (sum + (x[n - i - 1] - x[i]) * (p[n - i - 1] - 1)) % 1000000007LL;
  cout << sum + (sum < 0 ? 1000000007LL : 0);
}
