#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int main() {
  long long n, cnt[300005] = {}, a[300005] = {}, ans = 0;
  cin >> n;
  cnt[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[i] = (2 * cnt[i - 1]) % 1000000007;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    ans = (ans + cnt[i - 1] * a[i]) % 1000000007;
    ans = (ans - cnt[n - i] * a[i]) % 1000000007;
    if (ans < 0) ans += 1000000007;
  }
  cout << ans;
  return 0;
}
