#include <bits/stdc++.h>
using namespace std;
int const md = 1000000007;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> x(n);
  for (int i = 0; i != n; ++i) {
    scanf("%d", &(x[i]));
  }
  sort(x.begin(), x.end());
  vector<int> pow(n + 1);
  for (int i = 0, p = 1; i != n + 1; ++i) {
    pow[i] = p;
    p = p << 1;
    if (p >= md) p %= md;
  }
  int s = 0;
  for (int i = 0; i != n - 1; ++i) {
    int k;
    k = pow[n] + md + 1 - pow[n - i - 1];
    if (k >= md) k %= md;
    k = k + md - pow[i + 1];
    if (k >= md) k %= md;
    long long prod = (long long)k * (x[i + 1] - x[i]);
    prod = prod % md;
    s += (int)prod;
    if (s >= md) s %= md;
  }
  printf("%d", s);
}
