#include <bits/stdc++.h>
using namespace std;
long long powr(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = powr(x, y / 2);
  if (y % 2 == 0)
    return (temp * temp) % 1000000007;
  else
    return (x * temp * temp) % 1000000007;
}
int main() {
  int n;
  scanf("%d", &n);
  int arr[300001];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  sort(arr, arr + n, greater<int>());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (arr[i] * (powr(2, n - i - 1) - 1)) % 1000000007;
    ans -= (arr[i] * (powr(2, i) - 1));
    ans = ((ans % 1000000007) + 1000000007) % 1000000007;
  }
  printf("%d", ans);
  return 0;
}
