#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const long long MOD = 1e9 + 7;
long long n, x[N], ans, pw[N], dp[N], num[N];
inline long long add(long long a, long long b) {
  a += b;
  while (a >= MOD) a -= MOD;
  return a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> x[i];
  if (n == 1) {
    cout << 0 << '\n';
    return 0;
  }
  sort(x, x + n);
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pw[i] = add(pw[i - 1], pw[i - 1]);
  }
  dp[1] = x[1] - x[0];
  num[1] = 1;
  for (int i = 2; i < n; ++i) {
    long long now = x[i] - x[i - 1];
    dp[i] = add(dp[i - 1], num[i - 1] * now);
    dp[i] = add(dp[i], dp[i]);
    dp[i] = add(dp[i], now);
    num[i] = add(num[i - 1], num[i - 1]);
    num[i] = add(num[i], 1);
  }
  for (int i = 0; i < n; ++i) ans = add(ans, dp[i]);
  cout << ans << '\n';
}
