#include <bits/stdc++.h>
using namespace std;
template <typename T>
void dprint(T begin, T end) {
  for (auto i = begin; i != end; i++) {
    cerr << (*i) << " ";
  }
  cerr << "\n";
}
const long long MOD = 1e9 + 7;
int n;
long long a[310000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%lld", a + i);
  sort(a, a + n);
  long long ans = 0;
  long long now = 1;
  for (int i = 0; i < n; ++i) {
    ans = (ans + a[i] * now) % MOD;
    now = (now * 2) % MOD;
  }
  now = 1;
  for (int i = n - 1; i >= 0; --i) {
    ans = (ans - a[i] * now + MOD * MOD) % MOD;
    now = (now * 2) % MOD;
  }
  cout << ans << "\n";
  return 0;
}
