#include <bits/stdc++.h>
using namespace std;
void rd(int &a) { scanf("%d", &a); }
void rd(int &a, int &b) { scanf("%d %d", &a, &b); }
void rd(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
void rd(long long &a) { scanf("%lld", &a); }
void rd(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void rd(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void rd(unsigned long long &a) { scanf("%lld", &a); }
void rd(unsigned long long &a, unsigned long long &b) {
  scanf("%lld %lld", &a, &b);
}
void rd(unsigned long long &a, unsigned long long &b, unsigned long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void rd(double &a) { scanf("%lf", &a); }
void rd(double &a, double &b) { scanf("%lf %lf", &a, &b); }
void rd(double &a, double &b, double &c) { scanf("%lf %lf %lf", &a, &b, &c); }
long long mod = 1000000007;
int main() {
  unsigned long long n, i, j, k, dis, t, sum = 0, temp;
  rd(n);
  vector<unsigned long long> vec(n);
  for (i = 0; i < n; i++) rd(vec[i]);
  if (vec.size() <= 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(vec.begin(), vec.end());
  vector<unsigned long long> arr(n + 2);
  arr[0] = 1;
  arr[1] = 2;
  j = 2;
  for (i = 2; i <= n; i++) {
    arr[i] = arr[i - 1] % mod + j % mod;
    j = j * 2;
    j = j % mod;
  }
  for (i = 1; i < n; i++) {
    k = vec[i] - vec[i - 1];
    temp = (arr[i] - 1) * (arr[n - i] - 1);
    temp = temp % mod;
    j = temp * k;
    j = j % mod;
    sum += j;
    sum = sum % mod;
  }
  cout << sum << endl;
  return 0;
}
