#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long prec[300500], tmp[300500], sum = 0, fac;
  scanf("%d", &n);
  prec[0] = 0;
  prec[1] = 1;
  for (int i = 2; i <= n; ++i) {
    prec[i] = (prec[i - 1] * 2) % (long long)(1e9 + 7) + 1;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &tmp[i]);
  }
  sort(tmp, tmp + n);
  fac = prec[n - 1];
  for (int i = 1; i < n; ++i) {
    sum = (sum + ((tmp[i] - tmp[i - 1]) * fac) % (long long)(1e9 + 7)) %
          (long long)(1e9 + 7);
    fac = (fac + prec[n - i - 1]) % (long long)(1e9 + 7);
    fac = (fac - prec[i] + (long long)(1e9 + 7)) % (long long)(1e9 + 7);
  }
  cout << sum << endl;
  return 0;
}
