#include <bits/stdc++.h>
using namespace std;
long long int two[300300];
long long int a[300300];
int main() {
  long long int ans = 0;
  two[0] = 1;
  for (int i = 1; i < 300100; i++) {
    two[i] = (two[i - 1] * 2) % 1000000007;
  }
  long long int n;
  scanf("%lld", &n);
  for (long long int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    long long int del = 0, plu = 0;
    if (i == 1)
      plu = 0;
    else
      plu = ((two[i - 1] - 1) * a[i] + 1000000007) % 1000000007;
    if (i == n)
      del = 0;
    else
      del = ((two[n - i] - 1) * a[i] + 1000000007) % 1000000007;
    ans = (ans - del + 1000000007) % 1000000007;
    ans = (ans + plu) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
