#include <bits/stdc++.h>
using namespace std;
const int maxn = 301010;
const int mod = 1e9 + 7;
const int inv = (mod + 1) >> 1;
int n;
long long pow2[maxn] = {1};
long long a[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &a[i]), pow2[i] = (pow2[i - 1] << 1) % mod;
  sort(a + 1, a + n + 1);
  long long sum = 0, ans = 0;
  for (int i = 2; i <= n; ++i)
    sum = (sum + (a[i] - a[1]) * pow2[i - 2] % mod) % mod;
  ans = sum;
  for (int i = 2; i < n; ++i) {
    sum = (sum - (a[i] - a[i - 1]) * (pow2[n - i + 1] - 1)) % mod * inv % mod;
    ans = (sum + ans) % mod;
  }
  cout << (ans % mod + mod) % mod;
}
