#include <bits/stdc++.h>
using namespace std;
const int N = 300010, md = 1e9 + 7;
int n, a[N], pw[N];
int ans;
void solve() {
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    ans = (ans + 1LL * a[i] * (pw[i - 1] - 1) % md) % md;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  pw[0] = 1;
  for (int i = 1; i < N; ++i) pw[i] = 2LL * pw[i - 1] % md;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  solve();
  for (int i = 1; i <= n; ++i) a[i] *= -1;
  solve();
  cout << (ans + md) % md << endl;
}
