#include <bits/stdc++.h>
using namespace std;
long long n, a[300100], rs;
int lgp(long long n, long long p) {
  long long first = 1;
  while (p) {
    if (p & 1) {
      first = (first * n) % 1000000007;
      p--;
    }
    p /= 2;
    n = (n * n) % 1000000007;
  }
  return first % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = n; i; i--) {
    long long rsa = (1LL * a[i] * lgp(2, i - 1)) % 1000000007;
    long long rsb = (1LL * a[i] * lgp(2, n - i)) % 1000000007;
    if (rsa < rsb)
      rs += (rsa + 1000000007 - rsb) % 1000000007;
    else
      rs += (rsa - rsb) % 1000000007;
    rs %= 1000000007;
  }
  cout << rs;
}
