#include <bits/stdc++.h>
using namespace std;
const int maxn = 300050;
const int p = 1e9 + 7;
int x[maxn], n;
long long ans;
long long fuck(int x) {
  if (x < 0) return 0;
  long long ans = 1, a = 2;
  while (x) {
    if (x & 1) ans = (ans * a) % p;
    x >>= 1;
    a = (a * a) % p;
  }
  return ans - 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
  sort(x + 1, x + n + 1);
  for (int i = 1; i <= n; ++i)
    ans = ((((ans + fuck(i - 1) * x[i]) % p) - ((fuck(n - i) * x[i]) % p)) % p +
           p) %
          p;
  cout << ans << endl;
  return 0;
}
