#include <bits/stdc++.h>
using namespace std;
inline int rin() {
  int ans = 0;
  char c = getchar();
  while (c < '0' || '9' < c) c = getchar();
  while ('0' <= c && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return ans;
}
int N;
int ls[300010];
int main() {
  N = rin();
  for (int i = 0; i < N; i++) ls[i] = rin();
  sort(ls, ls + N);
  long long t, s;
  long long ans = 0;
  t = 1;
  s = ls[0];
  for (int i = 1; i < N; i++) {
    ans += t * ls[i] - s;
    ans %= 1000000007;
    s = (s * 2 + ls[i]) % 1000000007;
    t = (t * 2 + 1) % 1000000007;
  }
  ans = (ans + 1000000007) % 1000000007;
  printf("%d\n", (int)ans);
  return 0;
}
