#include <bits/stdc++.h>
using namespace std;
const int m = 1e9 + 7;
long long q(int a, int n) {
  if (!n) return 1;
  int x = q(a, n / 2);
  long long ans = (long long)x * x % m;
  if (n & 1) ans = ans * a % m;
  return ans;
}
int main() {
  int n;
  cin >> n;
  long long a[300001];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0; i < n; i++)
    ans = (ans + (a[i] * (q(2, i) - 1)) % m + m) % m,
    ans = (ans - (a[i] * (q(2, n - i - 1) - 1)) % m + m) % m;
  cout << ans << endl;
}
