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