#include <bits/stdc++.h>
using namespace std;
long long int a[1000005];
long long int b[1000005];
int main() {
  long long int i, j, k, m, n, d, sum, sum1, left, right, mm, mmm, w, max, min;
  long long int c = 1000000007;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  b[0] = 1;
  b[1] = 2;
  for (i = 2; i <= 300000; i++) {
    b[i - 1] = b[i - 1] % c;
    b[i] = (b[i - 1] * 2) % c;
  }
  sum = 0;
  sort(a, a + n);
  max = 0;
  min = 0;
  j = n - 1;
  for (i = 0; i < n; i++) {
    max = (max % c + (b[j] * (a[j] % c)) % c) % c;
    j = j - 1;
  }
  j = n - 1;
  for (i = 0; i < n; i++) {
    min = (min % c + (b[j] * (a[i] % c)) % c) % c;
    j = j - 1;
  }
  sum = ((max % c) - (min % c) + c) % c;
  cout << sum;
  return 0;
}
