#include <bits/stdc++.h>
using namespace std;
const int maxN = 300001, mod = 1000000007;
int T[maxN];
long long pref[maxN];
inline void add_mod(int& a, int b) { a = (a + b) % mod; }
inline void mult_mod(int& a, int b) { a = (long long)a * b % mod; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", T + i);
  sort(T + 1, T + n + 1);
  for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + T[i];
  int res = 0, power = 1;
  for (int i = 1; i < n; i++) {
    int temp = (pref[n] - pref[i] - pref[n - i]) % mod;
    mult_mod(temp, power);
    add_mod(res, temp);
    mult_mod(power, 2);
  }
  printf("%d\n", res);
  return 0;
}
