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