#include <bits/stdc++.h>
#pragma comment(linker, "/stack:640000000")
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
long long int arr[300010];
const long long int mod = 1000000007;
long long int bigmod(long long int a, long long int p, long long int mod) {
  long long int ans = 1;
  while (p) {
    if (p & 1) ans = ans * a % mod;
    a = a * a % mod;
    p >>= 1;
  }
  return ans;
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &arr[i]);
    }
    sort(arr + 1, arr + n + 1);
    int l = n - 1, r = 0;
    long long int res = 0;
    for (int i = n; i >= 1; i--) {
      long long int tmp = bigmod(2LL, l, mod);
      long long int temp = bigmod(2LL, r, mod);
      temp *= arr[i];
      temp %= mod;
      tmp *= arr[i];
      tmp %= mod;
      long long int ans = tmp - temp;
      res += ans;
      res %= mod;
      res += mod;
      res %= mod;
      l--;
      r++;
    }
    printf("%lld\n", res);
  }
  return 0;
}
