CodeEff/ECCO huggingface dataset:
# Original solution
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(eval(input()))
xy = [0] * n
for i in range(n):
    x, y = list(map(int, input().split()))
    xy[x - 1] = [x, y, i]
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][1]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][2])
        G[xy[i][2]].append(p[1])
    #heapq.heappush(h, [xy[i][1], xy[i][2]])
    if c:
        heapq.heappush(h, minv)
    else:
        heapq.heappush(h, [xy[i][1], xy[i][2]])
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)

# Optimized solution
import heapq
from collections import deque

def bfs(i, c):
    color[i] = c
    cnt[c] += 1
    q = deque()
    q.append(i)
    while q:
        j = q.popleft()
        for k in G[j]:
            if color[k] == -1:
                color[k] = c
                cnt[c] += 1
                q.append(k)
    return

n = int(eval(input()))
xy = [0] * n
for i in range(n):
    x, y = list(map(int, input().split()))
    xy[x - 1] = [y, i]
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
    G.append([])
for i in range(n):
    c = 0
    while h[0][0] < xy[i][0]:
        p = heapq.heappop(h)
        if c == 0:
            minv = p
        c = 1
        G[p[1]].append(xy[i][1])
        G[xy[i][1]].append(p[1])
    if c:
        heapq.heappush(h, minv)
    else:
        heapq.heappush(h, [xy[i][0], xy[i][1]])
color = [-1] * n
c = 0
for i in range(n):
    if color[i] == -1:
        bfs(i, c)
        c += 1
for i in range(n):
    ans = cnt[color[i]]
    print(ans)
# Original solution
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N = int(eval(input()))

uf = UnionFind(N)

xy = []
min_y = []
for i in range(N):
    x, y = list(map(int, input().split()))
    xy.append((x, y, i))
    min_y.append(y)

xy.sort()

s = set()

for i in range(N):
    x, y, a = xy[i]
    s.add(i)

    remove = set()
    for j in s:
        if j == i:
            continue

        x2, y2, b = xy[j]

        if y2 < y:
            uf.union(b, a)
            root = uf.find(b)
            if min_y[root] > y:
                min_y[root] = y
                remove.add(j)
            else:
                remove.add(i)
    s -= remove

for i in range(N):
    print((uf.get_size(i)))


# Optimized solution
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N = int(eval(input()))

uf = UnionFind(N)

xy = []
min_y = []
for i in range(N):
    x, y = list(map(int, input().split()))
    xy.append((x, y, i))
    min_y.append(y)

xy.sort()

min_y = N+1

for i in range(N-1):
    x, y, a = xy[i]
    x1, y1, b = xy[i+1]
    min_y = min(min_y, y)
    if min_y != N - i:
        uf.union(a, b)

for i in range(N):
    print((uf.get_size(i)))
# Original solution
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
y_to_i = [0]*(N+1)
for i,(x,y) in enumerate(A):
  y_to_i[y] = i
A.sort()
ans = [0]*N
from bisect import *
lis = []
cum_max = N

for x,y in A:
  insort(lis,y)
  lis_max,lis_min = lis[-1],lis[0]
  if lis_max==cum_max and len(lis)==lis_max-lis_min+1:
    for y1 in lis:
      ans[y_to_i[y1]] = len(lis)
    cum_max = lis_min-1
    lis = []
print(*ans, sep='\n')


# Optimized solution
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
y_to_i = [0]*(N+1)
for i,(x,y) in enumerate(A):
  y_to_i[y] = i
A.sort()
ans = [0]*N
from bisect import *
rem_max = N
cum_max = 0
cum_min = N+1
lis = []
for x,y in A:
  cum_max = max(cum_max, y)
  cum_min = min(cum_min, y)
  lis.append(y)
  if cum_max==rem_max and len(lis)==cum_max-cum_min+1:
    for y1 in lis:
      ans[y_to_i[y1]] = len(lis)
    rem_max = cum_min-1
    lis = []
    cum_max = 0
    cum_min = N+1
print(*ans, sep='\n')
# Original solution
a,b=list(map(int,input().split()));print(([a+b,a+b-24][a+b>=24]))

# Optimized solution
a,b=list(map(int,input().split()));print(((a+b)%24))
# Original solution
a,b=list(map(int,input().split()))

m=a+b

if m>=24:
  print((int(m-24)))
else:
  print((int(m)))

# Optimized solution
a, b = list(map(int, input().split()))
ans = a+b
     
if ans >=24:
  ans = ans-24
      
print(ans)
# Original solution
A,B=list(map(int,input().split()))
print(((A+B)%24))

# Optimized solution
print((sum(map(int,input().split()))%24))
# Original solution
a,b=list(map(int,input().split()));print(((a+b)%24))

# Optimized solution
print((eval(input().replace(*' +'))%24))
# Original solution
print((sum(map(int,input().split()))%24))

# Optimized solution
A,B = list(map(int,input().split()))
print(((A+B)%24))
# Original solution
A, B = list(map(int,input().split()))
t = A+B
if(t < 24):
  print(t)
else:
  print((t-24))

# Optimized solution
A, B = list(map(int,input().split()))
print(((A+B)%24))
# Original solution
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(eval(input()))
C = list(sorted(map(int, input().split()), reverse=True))

MAX = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def p(n, r, mod):
    return fac[n] * finv[n - r] % mod
    
comInit(MOD)

ans = 0
pow_list = [1] * (N + 1)
for i in range(1, N + 1):
    pow_list[i] = (2 * pow_list[i - 1]) % MOD
base = pow_list[N]
for i, c in enumerate(C):
    now = pow_list[N - i - 1]
    tot = 0
    if i >= 1:
        tot = pow_list[i] + i * pow_list[i - 1]
    else:
        tot = pow_list[i]
    ans += (tot * now * c) % MOD
    ans %= MOD
print((ans * base % MOD))





# Optimized solution
MOD = 10 ** 9 + 7
N = int(eval(input()))
C = list(sorted(map(int, input().split()), reverse=True))

ans = 0
pow_list = [1] * (N + 1)
for i in range(1, N + 1):
    pow_list[i] = (2 * pow_list[i - 1]) % MOD
base = pow_list[N]

# 基本戦略:コストが一番高いものを一番最後に変更する
for i, c in enumerate(C):
    now = pow_list[N - i - 1]
    tot = 0
    # コストがi番目に大きい値は、最後からi番目に変更を行うので
    # 左からi-bitまでに何個1が立ったかで加算回数が決まる
    if i >= 1:
        tot = pow_list[i] + i * pow_list[i - 1]
    else:
        tot = pow_list[i]
    ans += (tot * now * c) % MOD
    ans %= MOD
print((ans * base % MOD))
# Original solution
import sys
sys.setrecursionlimit(10**6)


N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
MOD = 10**9 + 7


ans = 0
# どうも公式ドキュメントによると、組み込み関数のpowの第三引数に値渡すとMODとってくれるらしいので、完全に無駄
def pow_mod(x, n, mod):
    if n == 0:
        return 1 % mod
    elif n % 2 == 0:
        y = pow_mod(x, n//2, mod)
        return y * y % MOD
    else:
        return x * pow_mod(x, n-1, mod) % mod

for i in range(N):
    # 詳細は開設動画の通りだが、i桁目の右にr個の数字、左にlこの数字がある
    l = i
    r = N - i - 1
    # i桁目の寄与が C[i] * 2**l * (2**r + r * 2**(r-1))で、最後に2**Nをかける（Tのとり方が2**Nこあるので）
    # -> C[i] * 2**l * (2**(N+r) + r * 2**(r+N-1))
    ans += ((C[i] * pow_mod(2, l, MOD)) % MOD * (pow_mod(2, N+r, MOD) + r * pow_mod(2, N+r-1, MOD))) % MOD
    ans %= MOD

print(ans)

# Optimized solution
"""



"""

import sys
sys.setrecursionlimit(10**6)


N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
MOD = 10**9 + 7


ans = 0
# どうも公式ドキュメントによると、組み込み関数のpowの第三引数に値渡すとMODとってくれるらしいので、完全に無駄
def pow_mod(x, n, mod):
    if n == 0:
        return 1 % mod
    elif n % 2 == 0:
        y = pow_mod(x, n//2, mod)
        return y * y % MOD
    else:
        return x * pow_mod(x, n-1, mod) % mod

for i in range(N):
    # 詳細は開設動画の通りだが、i桁目の右にr個の数字、左にlこの数字がある
    l = i
    r = N - i - 1
    # i桁目の寄与が C[i] * 2**l * (2**r + r * 2**(r-1))で、最後に2**Nをかける（Tのとり方が2**Nこあるので）
    # -> C[i] * 2**l * (2**(N+r) + r * 2**(r+N-1))
    ans += ((C[i] * pow(2, l, MOD)) % MOD * (pow(2, N+r, MOD) + r * pow(2, N+r-1, MOD))) % MOD
    ans %= MOD

print(ans)
# Original solution
MOD = 1000000007

N = int(eval(input()))
C = list(map(int,input().split()))

C.sort(reverse=True)

ans = 0

if N > 1:
    for i in range(N):
        ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
        ans %= MOD
else:
    ans = 2*C[0]%MOD

print(ans)

# Optimized solution
MOD = 1000000007

N = int(eval(input()))
C = list(map(int,input().split()))

C.sort(reverse=True)

ans = 0

for i in range(N):
    ans += C[i]*(2+i)*pow(4,N-1,MOD)
    ans %= MOD

print(ans)
# Original solution
MOD=10**9+7

N=int(eval(input()))
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
for i in range(N):
  out+=(pow(2, N-1)+pow(2, N-2)*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print((int(out%MOD)))

# Optimized solution
MOD=10**9+7

N=int(eval(input()))
if N==1:
  C=int(eval(input()))
  print((2*C%MOD))
  exit()
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print((int(out%MOD)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
mod = 10 ** 9 + 7
ans = 1
for _ in range(n):
  ans *= 2
cef = [ans//2]
for i in range(n-1):
  tmp = cef[-1] + ans // 4
  tmp %= mod
  cef.append(tmp)
son = 0
for i in range(n):
  son += cef[i] * a[i]
  son %= mod
ans *= son
ans %= mod
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
mod = 10 ** 9 + 7
ans = 1
for _ in range(2*n-2):
  ans *= 2
  ans %= mod
cef = [i+2 for i in range(n)]
for i in range(n):
  a[i] *= cef[i]
ans *= sum(a)
ans %= mod
print(ans)
# Original solution
number=10**9+7

n=int(eval(input()))
c=list(map(int, input().split()))

c.sort(reverse=True)
sum=0
for i in range(1, n+1):
    sum=(sum+(4**(n-1))*(i+1)*c[i-1])%number
print(sum)


# Optimized solution

number=10**9+7

n=int(eval(input()))
c=list(map(int, input().split()))

c.sort(reverse=True)
sum=0
for i in range(1, n+1):
    sum=(sum+(pow(4, (n-1), number))*(i+1)*c[i-1])%number
print(sum)
# Original solution
mod=10**9+7
n=int(eval(input()))
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
for i in range(n):
  ans+=pow(2,2*n-2,mod)*(n-i+1)*arr[i]
  ans%=mod
print((int(ans)))

# Optimized solution
mod=10**9+7
n=int(eval(input()))
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
total=pow(2,2*n-2,mod)
for i in range(n):
  ans+=total*(n-i+1)*arr[i]
  ans%=mod
print((int(ans)))
# Original solution
import sys

n = int(eval(input()))
c_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls.sort(reverse=True)
MOD = 10 ** 9 + 7

res = 0
for i, c in enumerate(c_ls):
    res += (2 ** (n - 2) * (i + 2)) * c % MOD
    res %= MOD
res = res * (2 ** n) % MOD
print((int(res)))

# Optimized solution
import sys

n = int(eval(input()))
c_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls.sort(reverse=True)
MOD = 10 ** 9 + 7

res = 0
for i, c in enumerate(c_ls):
    res += (i + 2) * c % MOD
    res %= MOD
res = res * (4 ** (n - 1)) % MOD
print((int(res)))
# Original solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
print((dp[-1]*(2*p) % mod))

# Optimized solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
S,T
"""

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
    p %= mod
p *= 2
p %= mod
print((dp[-1]*p % mod))
# Original solution
MOD = 10**9+7
n = int(eval(input()))
c = list(map(int, input().split()))
c.sort(reverse=True)
cnt = 0
pt = [2**i for i in range(n+1)]

for i, x in enumerate(c):
    r = n-i-1
    cnt += (pt[i] + (0 if i <= 0 else pt[i-1]) * i) * pt[r] * x
    cnt %= MOD

print((cnt * (pt[n] % MOD) % MOD))


# Optimized solution
MOD = 10**9+7
n = int(eval(input()))
c = list(map(int, input().split()))
c.sort(reverse=True)
cnt = 0
a, b = 2**(n-1), 0 if n <= 1 else 2**(n-2)
for i, x in enumerate(c):
    cnt += (a + b*i) * x

print((cnt * (2 ** n % MOD) % MOD))
# Original solution
MOD = 10 ** 9 + 7
N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()

if N == 1:
    print((2 * C[0] % MOD))
    exit()


lst = [0] * (N + 3)
lst[0] = 1
for i in range(1, N + 3):
    lst[i] = (lst[i - 1] * 2) % MOD


ANS = 0
for i, c in enumerate(C):
    ANS += c * (N + 1 - i)

ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print((ANS % MOD))

# Optimized solution
MOD = 10 ** 9 + 7
N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()

if N == 1:
    print((2 * C[0] % MOD))
    exit()

ANS = 0
for i, c in enumerate(C):
    ANS += c * (N + 1 - i)

ANS *= pow(2, N - 2, MOD)
ANS %= MOD
ANS *= pow(2, N, MOD)
print((ANS % MOD))
# Original solution
N = int(eval(input()))
C = list(map(int, input().split()))

MOD = 10 ** 9 + 7

C.sort()
C = C[::-1]

a0 = 2 ** (N - 1)
d = 2 ** (N - 2)
answer = 0
for i in range(N):
  answer = (answer + (a0 + d * i) * C[i]) % MOD
answer = (answer * pow(2, N, MOD)) % MOD
print((int(answer)))

# Optimized solution
N = int(eval(input()))
C = list(map(int, input().split()))

MOD = 10 ** 9 + 7

C.sort()
C = C[::-1]

a0 = pow(2, N - 1, MOD)
d = pow(2, N - 2, MOD) if N - 2 >= 0 else 0
answer = 0
for i in range(N):
  answer = (answer + (a0 + d * i) * C[i]) % MOD
answer = (answer * pow(2, N, MOD)) % MOD
print((int(answer)))
# Original solution
MOD = 10**9 + 7

N = int(eval(input()))
Cs = list(map(int, input().split()))

As = [1]
accA = 1
m = 2
for i in range(1, N):
    A = (accA + m) % MOD
    As.append(A)
    accA = (accA + A) % MOD
    m = m * 2 % MOD

m = 1
for i in reversed(list(range(N))):
    As[i] = As[i] * m % MOD
    m = m * 2 % MOD

Cs.sort(reverse=True)

ans = 0
for C, A in zip(Cs, As):
    ans += C * A % MOD

print((ans * pow(2, N, MOD) % MOD))


# Optimized solution
MOD = 10**9 + 7

N = int(eval(input()))
Cs = list(map(int, input().split()))

Cs.sort(reverse=True)

pow2 = pow(2, 2*N-2, MOD)

ans = 0
for i, C in enumerate(Cs, start=1):
    ans += C*(i+1)*pow2
    ans %= MOD

print(ans)
# Original solution
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def main():
    N = int(eval(input()))
    mod = 10**9 + 7
    C = list(map(int, input().split()))
    C.sort()
    c = cmbs(mod)
    r = 0
    for i, v in enumerate(C):
        t = 0
        for j in range(i, N):
            t += (j - i + 1) * c.cmb(N-i-1, j-i)
        t *= v * pow(2, i, mod)
        r += t
    r *= pow(2, N, mod)
    r %= mod
    return r
print((main()))


# Optimized solution
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def main():
    N = int(eval(input()))
    mod = 10**9 + 7
    C = list(map(int, input().split()))
    C.sort()
    r = 0
    for i, v in enumerate(C[:-1]):
        t = pow(2, N-i-2, mod) * (N- i + 1)
        t *= v * pow(2, i, mod)
        r += t
    r += C[-1] * pow(2, N-1, mod)
    r *= pow(2, N, mod)
    r %= mod
    return r
print((main()))
# Original solution
n = int(eval(input()))
C = list(map(int, input().split()))

mod = 10**9 + 7

if n == 1:
    ans = 2 * C[0]
    ans %= mod
    print(ans)
    exit()


ans = 0
pattern = 2 ** (n-1)
C.sort(reverse=True)
for c in C:
    ans += (c * pattern) % mod
    pattern += 2 ** (n-2)
    pattern %= mod
    ans %= mod

print((ans*(2**n) % mod))

# Optimized solution
n = int(eval(input()))
C = list(map(int, input().split()))

mod = 10**9 + 7

if n == 1:
    ans = 2 * C[0]
    ans %= mod
    print(ans)
    exit()


ans = 0
pattern = 2 ** (n-1) % mod
d = 2 ** (n-2) % mod
C.sort(reverse=True)
for c in C:
    ans += (c * pattern) % mod
    pattern += d
    pattern %= mod
    ans %= mod

print((ans*(2**n) % mod))
# Original solution
import os
import sys

# from libs.debug import debug

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort(reverse=True)


def div_mod(a, b, mod):
    return a * pow(b, mod - 2, mod) % mod


# (1+x)^k = kC0 * x^0 + kC1 * x^1 + kC2 * x^2 + ... + kCk * x^k
# (1+x)^k * x = kC0 * x^1 + kC1 * x^2 + kC2 * x^3 + ... + kCk * x^(k+1)
# 微分して x=1 を代入すると、上から1番目からk番目になる通り数 * D の総和になる
# kC0 * 1 + kC1 * 2 + kC2 * 3 + ... + kCk * (k+1)
def df(k):
    # (1+x)^x * x を微分した値を返す。
    # https://mathtrain.jp/composite
    # http://w3e.kanazawa-it.ac.jp/math/category/bibun/keisan/diff-gh.html
    # f(x) = 1+x
    # g(x) = x^k
    # h(x) = x
    # g(f(x)) * h(x) = (1+x)^k * x
    # f'(x) = 1
    # g'(x) = kx^(k-1)
    # h'(x) = 1
    # g'(f(x)) = g'(f(x)) * f'(x) = k(1+x)^(k-1)
    # (g(f(x)) * h(x))' = g'(f(x)) * h(x) + g(f(x)) * h'(x)
    #                   = k(1+x)^(k-1) + (1+x)^k
    # (g(f(1)) * h(1))' = k * 2^(k-1) + 2^k
    #                   = k * 2^k / 2 + 2^k
    #                   = (k + 2) / 2 * 2^k
    return div_mod((k + 2) * pow(2, k, MOD), 2, MOD)


ans = 0
for k in range(N):
    # k までの選び方 * 上から何番目か * C[k] * k より後ろの選び方
    ans += df(k) * C[k] * pow(2, N - k - 1, MOD)
    ans %= MOD
print((ans * pow(2, N, MOD) % MOD))


# Optimized solution
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort(reverse=True)

assert pow(2, MOD - 2, MOD) == 500000004


def div2(a):
    return a % MOD * 500000004 % MOD


pow2 = [1]
for _ in range(N):
    pow2.append(pow2[-1] * 2 % MOD)


# (1+x)^k = kC0 * x^0 + kC1 * x^1 + kC2 * x^2 + ... + kCk * x^k
# (1+x)^k * x = kC0 * x^1 + kC1 * x^2 + kC2 * x^3 + ... + kCk * x^(k+1)
# 微分して x=1 を代入すると、上から1番目からk番目になる通り数 * D の総和になる
# kC0 * 1 + kC1 * 2 + kC2 * 3 + ... + kCk * (k+1)
def df(k):
    # a(x) = (1+x)^k * x として、a'(1) を返す。
    # https://mathtrain.jp/composite
    # http://w3e.kanazawa-it.ac.jp/math/category/bibun/keisan/diff-gh.html
    # f(x) = 1+x
    # g(x) = x^k
    # h(x) = x
    # g(f(x)) * h(x) = (1+x)^k * x
    # f'(x) = 1
    # g'(x) = kx^(k-1)
    # h'(x) = 1
    # g'(f(x)) = g'(f(x)) * f'(x) = k(1+x)^(k-1)
    # (g(f(x)) * h(x))' = g'(f(x)) * h(x) + g(f(x)) * h'(x)
    #                   = k(1+x)^(k-1) + (1+x)^k
    # (g(f(1)) * h(1))' = k * 2^(k-1) + 2^k
    #                   = k * 2^k / 2 + 2^k
    #                   = (k + 2) / 2 * 2^k
    return div2((k + 2) * pow2[k])


ans = 0
for k in range(N):
    # k までの選び方 * 上から何番目か * C[k] * k より後ろの選び方
    ans += df(k) * C[k] * pow2[N - k - 1]
    ans %= MOD
print((ans * pow2[N] % MOD))