#include <bits/stdc++.h>
using namespace std;
long long p[500010];
long long a[500010];
int main() {
  p[0] = 1;
  for (int i = 1; i <= 400000; i++) {
    p[i] = p[i - 1] * 2;
    p[i] %= 1000000007;
  }
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) scanf("%I64d", a + i);
  long long ans = 0;
  sort(a, a + N);
  for (int i = 1; i < N; i++) {
    ans += 1LL * a[i] * (p[i] - 1);
    ans %= 1000000007;
  }
  for (int i = 0; i < N - 1; i++) {
    ans -= 1LL * a[i] * (p[N - i - 1] - 1);
    ans %= 1000000007;
  }
  if (ans < 0) ans += 1000000007;
  cout << ans << endl;
}
