#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
inline long long add(long long x, long long y) {
  long long res = x + y;
  if (res >= MOD) {
    res -= MOD;
  }
  return res;
}
inline long long sub(long long x, long long y) {
  long long res = x - y;
  if (res < 0) {
    res += MOD;
  }
  return res;
}
inline long long mult(long long x, long long y) { return (x * y) % MOD; }
int n;
vector<long long> x, s;
long long res, cur1, cur2, step;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  x.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    cur1 = add(cur1, x[i + 1]);
    cur2 = add(cur2, x[i]);
  }
  step = 1;
  for (int i = 0; i < n - 1; ++i) {
    res = add(res, mult(step, sub(cur1, cur2)));
    step = mult(step, 2LL);
    cur1 = sub(cur1, x[i + 1]);
    cur2 = sub(cur2, x[n - i - 2]);
  }
  cout << res << endl;
}
