#include <bits/stdc++.h>
using namespace std;
const int modulo = 1000000007;
long long putere[300005];
long long dp[300005];
long long v[300005];
long long modul(long long x) {
  if (x < 0) return -x;
  return x;
}
int main() {
  putere[0] = 1;
  long long n, raspuns = 0, suma = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    putere[i] = putere[i - 1] << 1;
    putere[i] = putere[i] % modulo;
  }
  for (int i = 1; i <= n; ++i) cin >> v[i];
  sort(v + 1, v + n + 1);
  for (int i = 2; i <= n; ++i) {
    dp[i] = dp[i - 1] + modul(v[i] - v[i - 1]);
    dp[i] = dp[i] % modulo;
  }
  for (int i = 1; i < n; ++i) {
    suma += (dp[n - i + 1] - dp[i]);
    suma = suma % modulo;
    while (suma < 0) suma += modulo;
    raspuns = (raspuns + suma * putere[i - 1]) % modulo;
  }
  cout << raspuns;
  return 0;
}
