#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
const int MOD = 1e9 + 7;
int n;
int a[N + 10], base[N + 10];
void Prepare() {
  base[0] = 1;
  for (int i = 1; i <= N; i++) base[i] = base[i - 1] * 2 % MOD;
}
int main() {
  Prepare();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = ((ans + 1LL * a[i] * (base[i - 1] - base[n - i]) % MOD) % MOD + MOD) %
          MOD;
  printf("%d\n", ans);
  return 0;
}
