#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
inline long long f(long long x) { return x % MOD; }
int main() {
  int n;
  cin >> n;
  vector<long long> X(n);
  for (int i = 0; i < n; ++i) cin >> X[i];
  sort(X.begin(), X.end());
  long long acum = 0;
  long long res = 0;
  long long pw = 2;
  for (int i = 1; i < n; ++i) {
    acum = f(2 * acum + (pw - 1) * (X[i] - X[i - 1]));
    res = f(res + acum);
    pw = f(2 * pw);
  }
  cout << res << endl;
}
