#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e+5;
const long long mod = 1e+9 + 7;
int n;
int point[maxn + 5];
long long power[maxn + 5];
long long ans = 0;
int main() {
  scanf("%d", &n);
  power[0] = 1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &point[i]), power[i] = (power[i - 1] * 2) % mod;
  sort(point + 1, point + 1 + n);
  for (int i = 1; i <= n; i++) {
    long long tmp = ((power[i - 1] - power[n - i]) * point[i]) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans << endl;
  return 0;
}
