#include <bits/stdc++.h>
using namespace std;
long long modexp(long long a, long long b) {
  long long c = 1;
  while (b) {
    if ((b & 1)) {
      c *= a;
      c %= 1000000007;
    }
    a *= a;
    a %= 1000000007;
    b >>= 1;
  }
  return c;
}
long long a[300004];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%Ld", &a[i]);
  }
  sort(a + 1, a + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (modexp(2, i - 1) * a[i]) % 1000000007;
    ans += (modexp(2, n - i) * (1000000007 - a[i])) % 1000000007;
  }
  cout << ans % 1000000007 << endl;
  return 0;
}
