#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 1;
long long x[maxn];
long long p[maxn];
int n;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  sort(x, x + n);
  p[0] = 1;
  for (int i = 1; i <= n; ++i) {
    p[i] = p[i - 1] * 2 % mod;
  }
  long long ans = 0;
  for (int i = 1; i < n; ++i) {
    ans = (ans + (x[i] - x[i - 1]) * (p[n] + 1 - p[i] - p[n - i])) % mod;
  }
  ans = (ans + mod) % mod;
  cout << ans % mod << endl;
}
