#include <bits/stdc++.h>
using namespace std;
long long n, arr[300100], aux[300100], mod = 1000000007, ans, a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1, j = 2; i <= n - 1; i++, j = (j * 2) % mod)
    aux[i] = j - 1;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  a = n - 1;
  for (int i = n - 1; i >= 0; i--, a--, b++)
    ans = (ans + (arr[i] * aux[a])) % mod,
    ans = (ans - (arr[i] * aux[b])) % mod;
  if (ans < 0) ans = mod + ans;
  cout << ans;
}
