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