#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n;
long long power[300009], arr[300009];
long long len, l, r, ans, add;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  power[0] = 1;
  for (int i = 1; i <= n; i++) {
    power[i] = power[i - 1] * 2;
    power[i] += MOD;
    power[i] = power[i] % MOD;
  }
  sort(arr, arr + n);
  ans = 0;
  for (int i = 1; i < n; i++) {
    l = i;
    r = n - i;
    len = arr[i] - arr[i - 1];
    add = ((power[l] - 1 + MOD) * (power[r] - 1 + MOD)) % MOD * len;
    add = add % MOD;
    ans += add;
    ans += MOD;
    ans = ans % MOD;
  }
  cout << ans << "\n";
}
