#include <bits/stdc++.h>
const int mod = 1e9 + 7;
int main() {
  int n;
  std::cin >> n;
  long *a = new long[n + 1]();
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  std::sort(a + 1, a + n + 1);
  long long p = 1;
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    ret += a[i] * p % mod;
    p = (p << 1) % mod;
  }
  p = 1;
  for (int i = n; i >= 1; i--) {
    ret += mod - a[i] * p % mod;
    p = (p << 1) % mod;
  }
  ret %= mod;
  std::cout << ret;
}
