#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
  bool start = false, neg = false;
  char c;
  num = 0;
  while ((c = getchar()) != EOF) {
    if (c == '-')
      start = neg = true;
    else if (c >= '0' && c <= '9') {
      start = true;
      num = num * 10 + c - '0';
    } else if (start)
      break;
  }
  if (neg) num = -num;
}
const int maxn = (int)(3e5) + 5;
const int mo = (int)(1e9) + 7;
int ai[maxn], p[maxn];
int main() {
  int n;
  read(n);
  for (int i = (1); i <= (n); i++) read(ai[i]);
  sort(ai + 1, ai + n + 1);
  p[0] = 1;
  for (int i = (1); i <= (n); i++) {
    p[i] = p[i - 1] + p[i - 1];
    if (p[i] >= mo) p[i] -= mo;
  }
  long long res = 0;
  for (int i = (1); i <= (n); i++)
    (res += 1LL * (p[i - 1] - p[n - i] + mo) * ai[i]) %= mo;
  printf("%I64d\n", res);
  return 0;
}
