#include <bits/stdc++.h>
int cmpfnc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int i, n;
  scanf("%d", &n);
  int arr[300005];
  for (i = 0; i < n; i++) scanf("%d", &arr[i]);
  qsort(arr, n, sizeof(int), cmpfnc);
  long long int sum = arr[0];
  long long int count = 1;
  long long int t2 = 0;
  for (i = 1; i < n; i++) {
    long long int t3 =
        ((count % 1000000007) * (arr[i] % 1000000007)) % 1000000007;
    t2 = (t2 + (t3 - sum + 1000000007) % 1000000007) % 1000000007;
    sum = (sum * 2 + arr[i]) % 1000000007;
    count = (count * 2 + 1) % 1000000007;
  }
  printf("%lld\n", t2);
  return 0;
}
