#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000;
long long n, x[maxn + 5], a[300005], b[300005], p = 1000000007, ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) a[i] = ((a[i - 1] + 1) * 2 - 1) % p;
  for (int i = 1; i <= n; i++) cin >> x[i];
  sort(x + 1, x + 1 + n);
  for (int i = 1; i <= n; i++)
    ans = (ans + x[i] * (a[i - 1] - a[n - i] + p) % p) % p;
  cout << ans;
}
