#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int md = 1e9 + 7;
int n;
int x[N];
int get(int n) {
  if (n == 0) return 1;
  if (n & 1)
    return get(n - 1) * 1LL * 2 % md;
  else {
    int b = get(n / 2);
    return b * 1LL * b % md;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
  }
  sort(x + 1, x + 1 + n);
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    int X = get(i - 1) - 1;
    int Y = get(n - i + 1) - 1;
    int sum = ((X * 1LL * Y) % md) * 1LL * (x[i] - x[i - 1]) % md;
    ans += sum;
    if (ans >= md) ans -= md;
  }
  cout << ans;
  return 0;
}
