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