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