#include <bits/stdc++.h>
using namespace std;
long long a[300007], one;
long long p(long long n) {
  if (!n) return 1;
  long long r = p(n / 2);
  r = (r * r) % 1000000007;
  if (n % 2) r = (r * 2) % 1000000007;
  return r;
}
long long serSum(long long n) {
  return (1000000007 + p(n + 1) - 1) % 1000000007;
}
int main(void) {
  std::ios::sync_with_stdio(false);
  long long n, i, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = n - 1; i; i--) {
    ans = (ans + (a[i] * serSum(i - 1)) % 1000000007) % 1000000007;
  }
  for (i = 0; i < n - 1; i++) {
    ans = (1000000007 + ans - (a[i] * serSum(n - 2 - i)) % 1000000007) %
          1000000007;
  }
  cout << ans << endl;
  return 0;
}
