#include <bits/stdc++.h>
using namespace std;
long long int modv[300005];
long long int mods[300005];
int arr[300005];
int modulo(int a, int b, int c) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % c;
    }
    y = (y * y) % c;
    b /= 2;
  }
  return x % c;
}
int main() {
  modv[0] = 1;
  mods[0] = 1;
  for (int i = 1; i < 300005; i++) {
    modv[i] = (modv[i - 1] * 2) % 1000000007;
    mods[i] = (mods[i - 1] + modv[i]) % 1000000007;
  }
  long long int inv = modulo(2, 1000000007 - 2, 1000000007);
  int n;
  scanf("%d", &n);
  ;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    ;
  }
  sort(arr, arr + n);
  long long int sumv = 0;
  for (int i = 1; i < n; i++) {
    sumv = (sumv + arr[i] * modv[i - 1]) % 1000000007;
  }
  long long int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    long long int temp = (arr[i] * mods[n - i - 2]) % 1000000007;
    temp = (sumv - temp + 1000000007) % 1000000007;
    ans = (ans + temp) % 1000000007;
    sumv = (sumv - arr[i + 1] + 1000000007) % 1000000007;
    sumv = (sumv * inv) % 1000000007;
  }
  printf("%lld\n", ans);
  ;
}
