#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 300009;
int n, ans, x[N];
inline int read() {
  char c = getchar();
  int f = 1, ret = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret * f;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    x[i] = read();
  }
  sort(x + 1, x + 1 + n);
  for (int i = 2, sum = x[1], w = 2; i <= n; i++) {
    ans = (ans + x[i] * (w - 1ll) - sum) % MOD;
    sum = (((long long)sum << 1) + x[i]) % MOD;
    w = (w << 1) % MOD;
  }
  cout << (ans + MOD) % MOD << endl;
  return 0;
}
