#include <bits/stdc++.h>
using namespace std;
const int base = 1e9 + 7;
const int N = 3e5 + 5;
int Pow[N], A[N];
int main() {
  Pow[0] = 1;
  for (int i = 1; i < N; ++i) Pow[i] = (2 * Pow[i - 1]) % base;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", A + i);
  sort(A, A + n);
  int res = 0;
  for (int i = 1; i < n; ++i) {
    int d = A[i] - A[i - 1];
    int p = (1LL * (Pow[i] - 1 + base) * (Pow[n - i] - 1 + base)) % base;
    (res += 1LL * p * d % base) %= base;
  }
  printf("%d\n", res);
}
