#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100, mod = 1e9 + 7;
int n, a[N], ans, bin[N];
inline void ad(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline void dc(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
int main() {
  int i, j;
  bin[0] = 1;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    bin[i] = (long long)bin[i - 1] * 2 % mod;
  }
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; ++i) {
    ad(ans, (long long)a[i] * bin[i - 1] % mod);
    dc(ans, (long long)a[i] * bin[n - i] % mod);
  }
  printf("%d", ans);
}
