#include <bits/stdc++.h>
const int md = 1e9 + 7;
const long long hs = 199;
const long double eps = 1e-9, pi = acos(-1);
using namespace std;
int n;
long long curr = 0, tot = 0;
vector<long long> a;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = 1, pw = 1; i < n; i++, pw = (2 * pw) % md)
    curr =
        ((curr + (a[i] - a[i - 1]) * (pw - 1) % md) * 2 + a[i] - a[i - 1]) % md,
    tot = (tot + curr) % md;
  cout << tot << '\n';
}
