#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < (int)(n); ++i) cin >> x[i];
  sort(x.begin(), x.end());
  vector<long long> pow(n + 1);
  pow[0] = 1, pow[1] = 2;
  for (int i = 2; i < n; ++i) pow[i] = pow[i - 1] * 2 % MOD;
  vector<long long> d(n + 1, 0);
  for (int i = 1; i < n; ++i)
    d[i] = (d[i - 1] + (x[i] - x[i - 1]) * 1ll * (pow[i] - 1) % MOD * 1ll *
                           (pow[n - i] - 1) % MOD) %
           MOD;
  cout << d[n - 1] << endl;
}
