#include <bits/stdc++.h>
using namespace std;
int n, ans;
int x[1100000], pw[1100000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
  sort(x + 1, x + n + 1);
  pw[0] = 1;
  for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 2 % 1000000007;
  for (int i = 1; i < n; i++)
    ans = (ans + 1LL * (x[i + 1] - x[i]) * (pw[i] - 1) % 1000000007 *
                     (pw[n - i] - 1)) %
          1000000007;
  printf("%d\n", (ans + 1000000007) % 1000000007);
}
