#include <bits/stdc++.h>
using namespace std;
int n;
int arr[300300];
const int MOD = 1000000007;
int pwr(int base, int pw) {
  int res = 1;
  while (pw) {
    if (pw & 1) res = (res * 1LL * base) % MOD;
    base = (base * 1LL * base) % MOD;
    pw >>= 1;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
  sort(arr, arr + n);
  int out = 0;
  for (int i = 0; i < n; ++i) {
    out -= (arr[i] * 1LL * (pwr(2, n - 1 - i) - 1)) % MOD;
    if (out < 0) out += MOD;
    out += (arr[i] * 1LL * (pwr(2, i) - 1)) % MOD;
    if (out >= MOD) out -= MOD;
  }
  printf("%d\n", out);
}
