#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, INF = 9e18;
const int inf = 2e9;
long long x[400010];
long long p2[400010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  p2[0] = 1;
  for (int i = 1; i <= n; i++) {
    p2[i] = (p2[i - 1] * 2) % MOD;
  }
  sort(x, x + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + (x[i] * p2[i]) % MOD) % MOD;
    ans = (ans + (MOD - (x[i] * p2[n - i - 1]) % MOD) % MOD) % MOD;
    ;
  }
  cout << ans << "\n";
  return 0;
}
