#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e9 + 7;
int a[300005];
int n;
long long fastPow(long long val, long long deg) {
  long long cur = val, res = 1;
  for (; deg != 0; deg >>= 1) {
    if (deg & 1) {
      res *= cur;
      res %= mod;
    }
    cur *= cur;
    cur %= mod;
  }
  return res;
}
long long rev(long long val) { return fastPow(val, mod - 2); }
long long segmentLength(int ind) { return a[ind + 1] - a[ind]; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  long long sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    sum += a[i + 1] - a[i];
  }
  sum %= mod;
  long long tempSum = sum;
  long long two = fastPow(2, n - 2);
  long long twoRev = rev(2);
  long long ans = 0;
  int mid = n - 1;
  bool desc = true;
  for (int i = n - 1; i > 0; --i) {
    ans += two * sum;
    ans %= mod;
    two *= twoRev;
    two %= mod;
    if (i == 1) break;
    if (desc && mid < 2) {
      desc = false;
    } else if (desc) {
      tempSum -= segmentLength(n - 1 - i) + segmentLength(i - 1);
      mid -= 2;
    } else {
      tempSum += segmentLength(i - 1) + segmentLength(n - 1 - i);
      mid += 2;
    }
    tempSum %= mod;
    tempSum += mod;
    tempSum %= mod;
    if (desc)
      sum += tempSum;
    else
      sum -= tempSum;
    if (mid == 0) desc = false;
    sum %= mod;
    sum += mod;
    sum %= mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
