#include <bits/stdc++.h>
int n, ans, c, sum[300005], x[300005], p2[300005];
int main() {
  scanf("%d", &n);
  p2[0] = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", x + i);
    p2[i] = 2ll * p2[i - 1] % 1000000007;
  }
  std::sort(x + 1, x + n + 1);
  for (int i = 1; i <= n; ++i) sum[i] = (sum[i - 1] * 1ll + x[i]) % 1000000007;
  for (int i = 2, t; i <= n; ++i) {
    c = p2[i - 2];
    t = (sum[n] - sum[n - i + 1]) % 1000000007;
    t = ((t - sum[i - 1]) % 1000000007 + 1000000007) % 1000000007;
    t = 1ll * t * c % 1000000007;
    ans = (ans + t) % 1000000007;
  }
  printf("%d\n", ans);
  return 0;
}
