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