#include <bits/stdc++.h>
using namespace std;
long long a[300005];
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long x = 1;
  for (int i = 0; i < n; i++) {
    ans = ans + x * (a[i] - a[n - 1 - i]);
    ans = ((ans % 1000000007LL) + 1000000007LL) % 1000000007LL;
    x = x * 2;
    x %= 1000000007LL;
  }
  cout << ans << endl;
  return 0;
}
