#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 3e5 + 5;
const long long INF = 1e14;
const long long eps = 1e-14;
long long x[N];
long long p2[N];
int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) cin >> x[i];
  sort(x + 1, x + n + 1);
  p2[0] = 1;
  for (long long i = 1; i < n; i++) p2[i] = (p2[i - 1] * 2) % MOD;
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    ans = (ans + x[i] * p2[i - 1]) % MOD;
    ans = (ans + MOD - x[i] * p2[n - i]) % MOD;
  }
  cout << ans << "\n";
  return 0;
}
