#include <bits/stdc++.h>
using namespace std;
const long long Max = 3e5 + 9, Mod = 1e9 + 7;
long long ans, pw[2][Max], x[Max];
int main() {
  pw[0][0] = 1;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    pw[0][i] = (pw[0][i - 1] * 2) % Mod;
    pw[1][i] = (pw[0][i] - 1) % Mod;
  }
  sort(x + 1, x + 1 + n);
  for (int i = 1; i < n; i++) {
    long long t = (pw[1][i] * pw[1][n - i]) % Mod;
    t = (t * (x[i + 1] - x[i])) % Mod;
    ans = (ans + t) % Mod;
  }
  cout << ans;
}
