#include <bits/stdc++.h>
using namespace std;
int a[300009];
int mod = 1000000007;
long long int power(int base, long long int exp) {
  if (exp == 0) {
    return 1;
  } else {
    long long int ans;
    if (exp % 2) {
      ans = base * power(base, exp - 1);
    } else {
      ans = power(base, exp / 2);
      ans = ans * ans;
    }
    if (ans >= mod) {
      ans %= mod;
    }
    return ans;
  }
}
int main() {
  int n;
  long long sum = 0, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    ans += ((1ll * a[i] * (power(2, i - 1))) % mod);
    if (ans >= mod) {
      ans = ans - mod;
    }
    ans -= (1ll * a[i] * (power(2, n - i))) % mod;
    if (ans < 0) {
      ans = ((ans % mod) + mod) % mod;
    }
  }
  if (ans >= mod) ans %= mod;
  cout << ans;
}
