#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
const int MAXN = 300300;
const int MOD = 1000000007;
int N;
long long A[MAXN];
int main() {
  cin >> N;
  for (int i = 0; i < (N); ++i) {
    cin >> A[i];
  }
  sort(A, A + N);
  long long res = 0;
  long long acc = 0;
  long long mul = 1;
  for (int i = (1); i <= (N - 1); ++i) {
    acc *= 2;
    acc += mul * (A[i] - A[i - 1]);
    acc %= MOD;
    res += acc;
    if (res >= MOD) res -= MOD;
    mul *= 2;
    mul += 1;
    if (mul >= MOD) mul -= MOD;
  }
  cout << res << endl;
  return 0;
}
