#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int p[n + 1];
  p[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    p[i] = (p[i - 1] * 2) % 1000000007;
  }
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long int sum = 0;
  for (long long int i = 1; i < n; i++) {
    long long int x = (a[i] - a[i - 1]) % 1000000007;
    sum =
        (sum + ((x * (p[n - i] - 1)) % 1000000007 * (p[i] - 1)) % 1000000007) %
        1000000007;
  }
  cout << sum << endl;
  return 0;
}
