#include <bits/stdc++.h>
using namespace std;
long long a[300005] = {0};
long long two[300005] = {0};
const long long mod = 1e9 + 7;
int main() {
  two[0] = 1;
  for (int i = 1; i <= 300000; i++) {
    two[i] = (two[i - 1] * 2LL) % mod;
  }
  long long res = 0;
  int n;
  while (cin >> n) {
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    sort(a, a + n + 1);
    res = 0;
    for (int i = 1; i <= n; i++) {
      res += (a[i] * (two[i - 1] - two[n - i]));
      res %= mod;
    }
    cout << res << endl;
  }
  return 0;
}
