#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long power[N], n, mod = 1e9 + 7;
long long arr[N];
int main() {
  ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
  power[1] = 1;
  for (int i = 2; i < N; i++) power[i] = (power[i - 1] * 2) % mod;
  for (int i = 2; i < N; i++) power[i] = (power[i] + power[i - 1]) % mod;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + ((((power[i] * arr[i]) % mod) -
                   (((power[n - 1 - i] * arr[i]) % mod)) + mod) %
                  mod)) %
          mod;
  }
  cout << ans;
  return 0;
}
