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