#include <bits/stdc++.h>
using namespace std;
inline int setBit(int N, int pos) { return N = N | (1 << pos); }
inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }
const int MAX = 300005;
const long long MOD = 1000000007;
int n, arr[MAX];
long long other[MAX], cum[MAX], p[MAX];
long long solve() {
  int i = 2, j = n - 1, idx = 0;
  long long ret = 0, here = cum[n], temp;
  if (n == 1) return cum[n];
  p[0] = 1;
  for (int x = 1; x <= n; x++) {
    p[x] = p[x - 1] * 2;
    p[x] %= MOD;
  }
  int cnt = n / 2;
  if (n % 2) cnt++;
  while (cnt--) {
    temp = (here * p[idx]) % MOD;
    ret += temp;
    if (ret >= MOD) ret -= MOD;
    if (idx != n - idx - 1) {
      temp = (here * p[n - idx - 1]) % MOD;
      ret += temp;
      if (ret >= MOD) ret -= MOD;
    }
    if (i >= 1 && i <= n && j >= 1 && j <= n) {
      here += cum[j];
      if (here >= MOD) here -= MOD;
      here -= cum[i - 1];
      if (here < 0) here += MOD;
      i++, j--;
    }
    idx++;
  }
  return ret;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
  sort(arr + 1, arr + 1 + n);
  for (i = 1; i <= n - 1; i++) {
    other[i] = arr[i + 1] - arr[i];
    cum[i] = other[i] + cum[i - 1];
  }
  n--;
  printf("%lld\n", solve());
  return 0;
}
