#include <bits/stdc++.h>
using namespace std;
int n;
long long expo(long long b, long long ex) {
  if (ex == -1) return 0;
  if (ex == 0) return 1;
  if (ex == 1) return b % 1000000007;
  long long r = expo(b, ex >> 1);
  if (ex & 1) return (((r * r) % 1000000007) * b) % 1000000007;
  return (r * r) % 1000000007;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long a = (expo(2, i)) + 1000000007;
    a %= 1000000007;
    long long b = (expo(2, n - i - 1)) + 1000000007;
    b %= 1000000007;
    ans += 1000000007 + (a * v[i]) % 1000000007 - (b * v[i]) % 1000000007;
    ans %= 1000000007;
  }
  cout << ans << endl;
}
