#include <bits/stdc++.h>
using namespace std;
long long x[300009];
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i];
  sort(x, x + n);
  long long a = x[0], b = 1, ans = 0;
  for (int i = 1; i < n; i++) {
    ans = (ans + x[i] * (2 * b - 1) - a) % 1000000007;
    a = (2 * a + x[i]) % 1000000007;
    b = 2 * b % 1000000007;
  }
  cout << ans << endl;
}
