#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double EPS = 1e-9;
const long long MAX = 1e9 - 1;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
inline long long mul(long long a, long long b) { return (a * 1ll * b) % mod; }
inline long long binPow(long long a, long long k) {
  long long ans = 1;
  while (k > 0) {
    if (k & 1) ans = mul(ans, a);
    a = mul(a, a);
    k >>= 1;
  }
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i <= n - 1; i++) cin >> v[i];
  long long ans = 0;
  sort(v.begin(), v.end());
  long long dp[n];
  dp[0] = 0;
  for (long long i = 1; i <= n - 1; i++) {
    dp[i] = 2 * dp[i - 1];
    dp[i] %= mod;
    dp[i] += ((binPow(2, i) - 1) * (v[i] - v[i - 1])) % mod;
    dp[i] %= mod;
  }
  long long sum = 0;
  for (long long i = 0; i <= n - 1; i++) {
    sum += dp[i];
    sum %= mod;
  }
  cout << sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc;
  tc = 1;
  for (long long i = 1; i <= tc; i++) solve();
}
