#include <bits/stdc++.h>
const uint64_t MOD = (uint64_t)1e9 + 7;
uint64_t points[300000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%I64d", points + i);
  std::sort(points, points + n);
  uint64_t result = 0, last = points[0], power = 2;
  for (int i = 1; i < n; ++i) {
    result = (result + points[i] * (power + MOD - 1) + MOD - last) % MOD;
    last = ((last << 1) + points[i]) % MOD;
    power = (power << 1) % MOD;
  }
  printf("%I64d\n", result);
}
