https://www.acmicpc.net/problem/15824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
static final int DIVISOR = 1_000_000_007;
static int N;
static int[] scoville;
static void input() {
Reader scanner = new Reader();
N = scanner.nextInt();
scoville = new int[N];
for(int idx = 0; idx < N; idx++)
scoville[idx] = scanner.nextInt();
}
static void solution() {
Arrays.sort(scoville);
long[] dp = new long[N];
dp[0] = 1;
for(int idx = 1; idx < N; idx++)
dp[idx] = (dp[idx - 1] * 2) % DIVISOR;
long answer = 0;
for(int idx = 0; idx < N; idx++)
answer = (answer + (scoville[idx] * (dp[idx] - dp[(N - 1) - idx]))) % DIVISOR;
System.out.println(answer);
}
public static void main(String[] args) {
input();
solution();
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
}
}