#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int n, i, j, k, t;
  scanf("%lld", &n);
  long long int prev = 0, ans = 0, count = 0, diff = 0, sum = 0, powe = 0;
  long long int a[n];
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a, a + n);
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  prev = a[1] - a[0];
  ans = prev;
  count = 2;
  for (i = 2; i < n; i++) {
    count = (count * 2) % 1000000007;
    powe = (count - 1) % 1000000007;
    diff = (a[i] - a[i - 1]) % 1000000007;
    sum = ((2 * prev) % 1000000007 + (diff * powe) % 1000000007) % 1000000007;
    ans = ((ans) % 1000000007 + (sum) % 1000000007) % 1000000007;
    prev = sum % 1000000007;
  }
  cout << ans % 1000000007 << endl;
}
