#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y,
                    long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int n;
  unsigned long long int sum = 0;
  cin >> n;
  int p = 1000000007;
  long long int arr[n], diff[n], f[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  diff[0] = 0;
  for (int i = 1; i < n; i++) {
    diff[i] = arr[i] - arr[i - 1];
  }
  f[0] = 0;
  f[1] = 0;
  for (int i = 1; i < n; i++) {
    f[i] =
        ((2 * f[i - 1]) % p + (((power(2, i, p) - 1) * (diff[i] % p)) % p)) % p;
    sum += f[i];
  }
  sum = sum % p;
  cout << sum << endl;
  return 0;
}
