#include <bits/stdc++.h>
using namespace std;
long long n, res, nt, b, f;
long long p[300007], pp[300007], a[300007];
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  p[1] = 2;
  pp[1] = 0;
  for (int i = 2; i <= n; i++) {
    pp[i] = (2 * pp[i - 1] + 1) % 1000000007;
  }
  res = 0;
  for (int i = 1; i <= n; i++) {
    res += (a[i] * pp[i]) % 1000000007;
    res -= (a[i] * pp[n + 1 - i]) % 1000000007;
    while (res < 0) res += 1000000007;
    res %= 1000000007;
  }
  cout << res << endl;
  return 0;
}
