#include <bits/stdc++.h>
using namespace std;
long long a[300010], po[300010], ans;
int n, p = 1e9 + 7;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + n + 1);
  po[0] = 1;
  for (int i = 1; i <= n; i++) po[i] = po[i - 1] * 2 % p;
  for (int i = 1; i <= n; i++)
    (ans += a[i] * (p + po[i - 1] - po[n - i]) % p) %= p;
  printf("%I64d\n", ans);
  return 0;
}
