#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long n, long long pow, long long m) {
  long long ret = 1;
  while (pow) {
    if (pow % 2) {
      ret *= n;
      ret %= m;
    }
    n *= n;
    n %= m;
    pow /= 2;
  }
  return ret;
}
long long arr[3 * 100009];
int main() {
  long long n, a, sum = 0, sum1 = 0;
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &arr[i]);
  sort(arr + 1, arr + n + 1);
  for (long long i = 1; i <= n; i++) {
    sum += (arr[i] * (bigmod((long long)2, i - 1, 1000000000 + 7)));
    sum -= (arr[i] * (bigmod((long long)2, n - i, 1000000000 + 7)));
    sum %= 1000000000 + 7;
  }
  printf("%I64d\n", sum);
}
