#include <bits/stdc++.h>
using namespace std;
inline bool comp(const pair<pair<int, int>, int> &a,
                 const pair<pair<int, int>, int> &b) {
  return (a.second > b.second);
}
long long int MOD = 1e9 + 7;
int n, x[1000005], p = 1;
long long a, s;
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i];
  sort(x + 1, x + n + 1);
  for (int i = 2; i <= n; i++) {
    s += x[n] - x[i - 1];
    s -= x[n] - x[n - i + 2];
    s = (s + MOD) % MOD;
    a += p * s;
    a %= MOD;
    p = (p * 2) % MOD;
  }
  cout << a;
  return 0;
}
