#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 500000 + 5;
const int INF = 0x3f3f3f3f;
const int P = 1000000007;
const double PI = acos(-1.0);
template <typename T>
inline T read(T &x) {
  x = 0;
  int _f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') _f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = _f ? -x : x;
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
int i, n, x[N], A[N], ans;
bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  read(n);
  for (A[0] = i = 1; i <= n; i++) read(x[i]), A[i] = A[i - 1] * 2LL % MOD;
  sort(x + 1, x + 1 + n, cmp);
  for (i = 1; i <= n; i++) {
    (ans += 1LL * x[i] * A[n - i] % MOD) %= MOD;
  }
  for (i = n; i >= 1; i--) {
    (ans -= 1LL * x[i] * A[i - 1] % MOD) %= MOD;
    if (ans < 0) ans += MOD;
  }
  printf("%d\n", ans);
  return 0;
}
