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