#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 10;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;
int t, n;
long long a[MAX];
long long f[MAX];
int calc(int l, int r) { return (1LL * (a[r] - a[l]) * f[r - l - 1]); }
int main() {
  ios::sync_with_stdio(false);
  f[0] = 1;
  for (int i = 1; i < MAX; i++) f[i] = (f[i - 1] * 2) % MOD;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long res = 0;
  long long prev = 0;
  for (int i = 1; i < n; i++) {
    prev = ((prev * 2) % MOD +
            (1LL * (f[i] - 1LL) * (0LL + a[i] - a[i - 1])) % MOD) %
           MOD;
    res = (res + prev) % MOD;
  }
  cout << res;
  return 0;
}
