#include <bits/stdc++.h>
using namespace std;
int table[300000];
int tableA[300000];
int tableB[300000];
void init() {
  table[0] = 1;
  for (int i = 1; i < 300000; i++) {
    table[i] = (table[i - 1] << 1) % 1000000007;
  }
}
int main() {
  init();
  int n;
  int tmp;
  int res = 0;
  long long val;
  vector<int> x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    x.push_back(tmp);
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(x.begin(), x.end());
  int n2 = n / 2;
  tableA[0] = x[0];
  tableB[0] = x[n - 1];
  for (int i = 1; i < n2; i++) {
    tableA[i] = (tableA[i - 1] + x[i]) % 1000000007;
    tableB[i] = (tableB[i - 1] + x[n - i - 1]) % 1000000007;
  }
  for (int i = 0; i < n2; i++) {
    if ((i * 2 + 2) == n)
      tmp = table[i];
    else
      tmp = table[i] + table[n - 2 - i];
    val = ((long long)(tableB[i] - tableA[i] + 1000000007)) * tmp % 1000000007;
    res = (res + val) % 1000000007;
  }
  cout << res << endl;
  return 0;
}
