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