Problem:
 Score : 500 points    Problem Statement For two sequences S and T of length N consisting of 0 and 1 , let us define f(S, T) as follows:    Consider repeating the following operation on S so that S will be equal to T . f(S, T) is the minimum possible total cost of those operations.   Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \times C_i , where D is the number of integers j such that S_j \neq T_j (1 \leq j \leq N) just before this change.     There are 2^N \times (2^N - 1) pairs (S, T) of different sequences of length N consisting of 0 and 1 . Compute the sum of f(S, T) over all of those pairs, modulo (10^9+7) .      Constraints  1 \leq N \leq 2 \times 10^5  1 \leq C_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  C_1  C_2  \cdots  C_N       Output Print the sum of f(S, T) , modulo (10^9+7) .        Sample Input 1 1
1000000000      Sample Output 1 999999993  There are two pairs (S, T) of different sequences of length 2 consisting of 0 and 1 , as follows:   S = (0), T = (1): by changing S_1 to 1 , we can have S = T at the cost of 1000000000 , so f(S, T) = 1000000000 .  S = (1), T = (0): by changing S_1 to 0 , we can have S = T at the cost of 1000000000 , so f(S, T) = 1000000000 .   The sum of these is 2000000000 , and we should print it modulo (10^9+7) , that is, 999999993 .       Sample Input 2 2
5 8      Sample Output 2 124  There are 12 pairs (S, T) of different sequences of length 3 consisting of 0 and 1 , which include:   S = (0, 1), T = (1, 0)   In this case, if we first change S_1 to 1 then change S_2 to 0 , the total cost is 5 \times 2 + 8 = 18 . We cannot have S = T at a smaller cost, so f(S, T) = 18 .       Sample Input 3 5
52 67 72 25 79      Sample Output 3 269312

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    mod = 10**9 + 7

    n = int(input())
    c = list(map(int, input().split()))
    c.sort()
    res = 0
    b = pow(2, n, mod)
    for i in range(n):
        l = pow(2, i, mod)
        if n-i-2 >= 0:
            r = pow(2, n-i-1, mod) + (n-i-1)*pow(2, n-i-2, mod)
        else:
            r = pow(2, n-i-1, mod)
        res += b*c[i]*l*r % mod
        res %= mod
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    mod = 10**9 + 7

    n = int(input())
    c = list(map(int, input().split()))
    c.sort()
    res = 0
    b = pow(2, n, mod)
    for i in range(n):
        l = pow(2, i, mod)
        if n-i-2 >= 0:
            r = pow(2, n-i-1, mod) + (n-i-1)*pow(2, n-i-2, mod)
        else:
            r = pow(2, n-i-1, mod)
        res += b*c[i]*l*r % mod
        res %= mod
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
MOD=10**9+7
N=int(input())
clist=list(map(int,input().split()))
clist.sort()

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  else:
    pow2=powmod(a,p//2)
    if p%2==0:
      return (pow2**2)%MOD
    else:
      return (a*pow2**2)%MOD

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

print(base*coef%MOD)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N = int(input())
    a = list(map(int,input().split()))
    a.sort()
    a = np.array(a)
    MOD = 10**9+7
    
    base = np.array([N-i+1 for i in range(N)])
    
    l = (np.sum((a*base)%MOD))%MOD
    f = pow(4,N-1,MOD)
    print(f*l%MOD)

if __name__ == "__main__":
    main()

Solution (Python):
N,*C = map(int, open(0).read().split())
MOD = 10**9+7
p2 = [1]*(2*N+1)
for i in range(1,2*N+1):
  p2[i] = p2[i-1]*2%MOD
C.sort()
ans = 0
for i,c in enumerate(C):
  n = N-1-i
  ans += c*(n*p2[n-1]+p2[n])*p2[N+i]%MOD
print(ans%MOD)

Solution (Python):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
p2 = [1]*N
for i in range(1,N):
  p2[i] = p2[i-1]*2%mod
N,*C = map(int, open(0).read().split())
C.sort()
ans = 0
for i,c in enumerate(C):
  n = N-1-i
  ans += c*(n*p2[n-1]+p2[n])*p2[n+1]*p2[2*i]%mod
print(ans%mod)

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

ans = 0
for i, c in enumerate(C, start=1):
    M = N - i
    ans += c * (M + 2)
    ans %= MOD
ans *= pow(4, N - 1, MOD)
print(ans % MOD)

Solution (Python):


def pow2(n, mod):
    """2のn乗まで"""
    t = 1
    yield t
    for _ in range(n):
        t = t * 2 % mod
        yield t


def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    *c, = map(int, input().split())

    c.sort()

    *two, = pow2(N, MOD)

    ans = 0
    for l, x in enumerate(c):
        
        
        
        r = N - l - 1

        t = two[r]
        if r != 0:
            t = (t + two[r - 1] * r) % MOD  
        t = t * two[l] % MOD
        t = t * x % MOD
        ans = (ans + t) % MOD  

    ans = ans * two[N] % MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


def pow2(n, mod):
    """2のn乗まで"""
    t = 1
    yield t
    for _ in range(n):
        t = t * 2 % mod
        yield t


def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    *c, = map(int, input().split())

    c.sort()

    *two, = pow2(N, MOD)

    ans = 0
    for l, x in enumerate(c):
        
        
        
        r = N - l - 1

        t = two[r]
        if r != 0:
            t += two[r - 1] * r  
        t = t * two[l] % MOD
        t = t * x % MOD
        ans += t

    ans = ans * two[N] % MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
C = sorted(list(map(int,input().split())))[::-1]
ans = 0
MOD = 10**9 + 7
for k in range(N):
    ans += pow(2,2*N-2,MOD)*(k+2)*C[k]
print(ans%MOD)

Solution (Python):
MOD = 10 ** 9 + 7
N = int(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)

Solution (Python):
MOD = 10 ** 9 + 7
N = int(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)

Solution (Python):
mod = int(10 ** 9) + 7

def main():
    n = int(input())
    c = list(map(int, input().split()))

    c.sort()
    pow2 = [None for _ in range(2*n+1)]
    pow2[0] = 1
    for i in range(1, 2*n+1):
        pow2[i] = (pow2[i-1] * 2) % mod

    total_cost = [None for _ in range(n)]
    for i in range(n):
        k = n - i - 1
        p2k2 = (pow2[k-1] * (k + 2)) % mod
        if k-1 < 0:
            p2k2 = 1
        total_cost[i] = (((p2k2 * c[i]) % mod) * pow2[2*i] * pow2[k+1]) % mod

    ans = sum(total_cost) % mod

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
MOD = 10 ** 9 + 7
N = int(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 *= lst[N - 2]
ANS %= MOD
ANS *= lst[N] 
print (ANS % MOD)

Solution (Python):
mod = 10 ** 9 + 7

N = int(input())
C = list(map(int, input().split()))
C.sort(reverse=True)

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

ans = 0
coef = pow(2, N-1, mod)
for c in C:
    ans += c * coef
    ans %= mod
    coef = (coef + pow(2, N - 2, mod)) % mod

ans *= pow(2, N, mod)
ans %= mod
print(ans)

Solution (Python):
N=int(input())
c=sorted([int(i) for i in input().split()])
mod=10**9+7
ans=0
for i in range(N):
    ans+=(c[i]*(((N-i+1)*pow(2,(N-2)%(mod-1),mod))%mod))%mod
    ans%=mod
print((ans*pow(2,N,mod))%mod)

Solution (Python):
n = int(input())
c = list(map(int,input().split()))
mod = 10**9+7
c.sort()
ans = 0
for i in range(n):
    ans += c[i]*(2+n-1-i)*pow(4,n-1,mod)
    ans %= mod

ans %= mod
print(ans)

Solution (Python):
ans = 0
P = 10**9+7
n = int(input())
c = list(map(int, input().split()))
c = sorted(c)

for i in range(n):
    alr = pow(4, i, P)
    use_bit = n - 1 - i
    flip = pow(2, use_bit, P)
    ret = 1
    if use_bit > 0:
        ret = (pow(2, use_bit, P) + use_bit*pow(2, use_bit-1, P))%P
    ans = (ans + alr*flip*ret*c[i])%P

print((ans*2)%P)

Solution (Python):
n = int(input())
c = list(map(int, input().split()))
MOD = 10 ** 9 + 7

c = sorted(c)
nokori = n - 1
ans = 0
ptn = (pow(2, n, MOD) ** 2) * pow(2, MOD - 2, MOD) % MOD
for i, val in enumerate(c):
    ans += (ptn * val) + (ptn * nokori * val * pow(2, MOD - 2, MOD))
    ans %= MOD
    nokori -= 1

print(ans % MOD)

Solution (Python):
N = int(input())
C = list(map(int, input().split()))

MOD = 10 ** 9 + 7
C.sort()
ans = 0
for i in range(N):
    l = i
    r = N - i - 1
    now = pow(2, r, MOD)
    if r > 0:
        now += pow(2, r - 1, MOD) * r
    now *= pow(2, l, MOD)
    now *= C[i]
    ans += now
print(ans * pow(2, N, MOD) % MOD)

Solution (Python):
mod = 10**9 + 7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)

b = pow(2, 2*n-2, mod)
a = 2 * b % mod

ans = 0
for i in range(n):
    ans += c[i] * (a + i * b)
    ans %= mod

print(ans)

Solution (Python):
mod = 10**9 + 7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)

b = pow(2, 2*n-2, mod)
a = 2 * b % mod

ans = 0
for i in range(n):
    ans += c[i] * (a + i * b)
    ans %= mod

print(ans)

Solution (Python):
MOD = 1000000007
def inv(x, mod=MOD):
    return pow(x, mod-2, mod)
n = int(input())
c = list(map(int, input().split()))

c.sort()

ans = 0

for i, x in enumerate(c, 1):
    mem = x
    mem = mem * pow(2, n-1, MOD) % MOD
    mem = mem * inv(pow(2, n, MOD) - 1) % MOD
    mem = mem * (1 + (n - i) * inv(2)) % MOD
    ans += mem
    ans %= MOD

ans = ans * (pow(2, n) - 1) % MOD
ans = ans * pow(2, n) % MOD
print(ans)

Solution (Python):
def examA():
    N = I()
    X = [LI()for _ in range(N)]
    l = 0; r = inf
    while(r-l>_ep):
        now = (l+r)/2
        x_l = -inf; x_r = inf
        y_l = -inf; y_r = inf
        for x,y,c in X:
            move = now / c
            x_l = max(x_l,x-move)
            x_r = min(x_r,x+move)
            y_l = max(y_l,y-move)
            y_r = min(y_r,y+move)
        if x_l<=x_r-_ep and y_l<=y_r-_ep:
            r = now
        else:
            l = now
    ans = r
    print(ans)
    return

def examB():
    N = I()
    C = LI()
    C.sort()
    base = pow(2,2*N-1,mod)
    inv = pow(2,mod-2,mod)
    ans = 0
    for i in range(N):
        cur = C[i]*base*(1+(N-1-i)*inv)
        ans += cur
        ans %= mod
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return


import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-9)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
N = int(input())
mod = int(1e9) + 7
C = list(map(int, input().split()))
C.sort(reverse=True)
def doubling(n, m):
  y = 1
  base = n
  while m != 0:
    if m % 2 == 1:
      y *= base
      y %= mod
    base *= base
    base %= mod
    m //= 2
  return y
b = 1
if N == 1:
  L, R = 0, 1
else:
  b = doubling(2, N-2)
  L, R = b, (2 * b) % mod
S1 = 0
S2 = 0
for i in range(N):
  S1 += (i * C[i]) % mod
  S1 %= mod
  S2 += C[i]
  S2 %= mod
print((doubling(2, N) * (S1 * L + S2 * R)) % mod)

Solution (Python):
n = int(input())
c = list(map(int, input().split()))

mod = 10**9+7

c.sort()


ans = 0
for i in range(1,n+1):
    ans += (i+1)*c[n-i]

print(pow(2,2*n-2,mod)*ans%mod)

Solution (Python):
n = int(input())
C = list(map(int,input().split()))
C.sort(reverse = True)
mod = 10**9 + 7

pow2 = [1]*(n+1) + [1]
for i in range(n):
    pow2[i+1] = (pow2[i] * 2)%mod

ans = 0

for i,c in enumerate(C):
    ans += (c*(i*pow2[i-1]%mod + pow2[i])%mod)*pow2[n-i-1]
    ans %= mod

ans *= pow2[n]
ans %= mod
print(ans)

Solution (Python):

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

ans = 0
mod = 10**9 + 7

for l in range(N):
    r = N - l - 1
    if r > 0:
        ans += C[l] * (pow(2, r-1, mod) * r + pow(2, r, mod)) * pow(2, l, mod)
    else:
        ans += C[l] * (pow(2, r, mod)) * pow(2, l, mod)
        
print(int(ans * pow(2, N, mod)) % mod)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n0 = int(input())
    c0 = list(map(int, readline().split()))
    c0.sort(reverse=True)

    ans = 0
    mul = pow(2, n0 - 1, MOD)
    add = pow(2, max(0, n0 - 2), MOD)

    for i, cc in enumerate(c0, 1):
        ans += cc * mul
        ans %= MOD
        mul += add
        mul %= MOD

    ans *= pow(2, n0, MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))
lists=sorted(lists,reverse=True)

mod=10**9+7
dp=[0 for i in range(n+1)]
dp[1]=2*lists[0]
for i in range(1,n):
    x=lists[i]
    y=pow(2,i,mod)
  
    dp[i+1]=4*dp[i]+(i+2)*(y**2)*lists[i]
    dp[i+1]%=mod

print(dp[n]%mod)

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))
lists=sorted(lists,reverse=True)

mod=10**9+7
dp=[0 for i in range(n+1)]
dp[1]=2*lists[0]
for i in range(1,n):
    x=lists[i]
    y=pow(2,i,mod)
  
    dp[i+1]=4*dp[i]+(i+2)*(y**2)*lists[i]
    dp[i+1]%=mod

print(dp[n]%mod)

Solution (Python):
n = int(input())
c = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0
for i,x in enumerate(c):
    ans += x * (n - i + 1)
    ans %= mod

ans *= pow(2,2*n-2,mod)

ans %= mod

print(ans)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()

two_power = np.array([(1+N-i) * pow(2, (N-2), MOD) % MOD if i < N-1 else pow(2, i, MOD) for i in range(N)])
answer = (C * two_power % MOD).sum() % MOD * pow(2, N, MOD)
print(answer%MOD)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))



N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()

two_power = np.array([(1+N-i) * pow(2, (N-2), MOD) % MOD if i < N-1 else pow(2, i, MOD) for i in range(N)])
answer = (C * two_power % MOD).sum() % MOD * pow(2, N, MOD)
print(answer%MOD)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))



N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()

two_power = np.array([(1+N-i) * pow(2, (N-2), MOD) % MOD if i < N-1 else pow(2, i, MOD) for i in range(N)])
answer = (C * two_power % MOD).sum() % MOD
answer *= pow(2, N, MOD)
print(answer%MOD)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()

two_power = np.array([(1+N-i) * pow(2, (N-2), MOD) % MOD if i < N-1 else pow(2, i, MOD) for i in range(N)])
answer = (C * two_power % MOD).sum() * 2**N
print(answer%MOD)

Solution (Python):
n = int(input())
c = list(map(int, input().split()))
c.sort()
MOD = 1000000007
ans = 0
P = pow(4, n-1, MOD)
if n == 1:
  ans = c[0]*2 % MOD
else:
  for i in range(n):
    ans += P*c[i]*(n+1-i)
    ans %= MOD
 
print(ans)

Solution (Python):
def main():
    N = int(input())
    C = list(map(int, input().split()))
    C.sort()
    mod = 10 ** 9 + 7
    r = 0
    n = N
    i = 0
    for c in C:
        if n == 1:
            r = (r + c * pow(2, N - 1, mod)) % mod
        else:
            r = (r + c * (n + 1)* pow(2, n - 2, mod) * pow(2, N - n, mod)) % mod
        n -= 1
    return 2**N * r % mod

print(main())

Solution (Python):
def main():
    N = int(input())
    mod = 10**9 + 7
    C = list(map(int, input().split()))
    C.sort()
    r = 0
    for i, v in enumerate(C[:-1]):
        r += pow(2, N-i-2, mod) * (N- i + 1) * v * pow(2, i, mod)
        r %= mod
    r += C[-1] * pow(2, N-1, mod)
    r *= pow(2, N, mod)
    r %= mod
    return r
print(main())

Solution (Python):
def main():
    N = int(input())
    mod = 10**9 + 7
    C = list(map(int, input().split()))
    C.sort()
    r = 0
    for i, v in enumerate(C[:-1]):
        r += pow(2, N-i-2, mod) * (N- i + 1) * v * pow(2, i, mod)
    r += C[-1] * pow(2, N-1, mod)
    r *= pow(2, N, mod)
    r %= mod
    return r
print(main())

Solution (Python):
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(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())

Solution (Python):
MOD = 1000000007

def modpow(a, p):
    res = 1
    while p > 0:
        if p % 2 == 1:
            res = res * a % MOD
        p = p // 2
        a = a * a % MOD
    return res

n = int(input())
a = sorted(list(map(int, input().split())))[::-1]

ans = 0

for i, v in enumerate(a):
    ans += modpow(2, 2 * n - i - 1) * v * (modpow(2, i) + i * modpow(2, i - 1))
    ans = ans % MOD

print(ans)

Solution (Python):
MOD = 10**9+7
n = int(input())
c = sorted(list(map(int, input().split())))
ans = 2**(2*n-2) % MOD
a = 0
for i in range(1,n+1):
	a = (a + c[i-1] * (2+n-i)) % MOD
ans = (ans * a) % MOD
print(ans)

Solution (Python):

mod = int(1e9 + 7)
maxN = int(2e5 + 100)
pow = [1] * maxN
cost = []


def add(x, y) : return (x + y) % mod
def mul(x, y) : return x % mod * (y % mod) % mod
def prepare() :
    for i in range(1, maxN):
        pow[i] = mul(pow[i - 1], 2)

prepare()
n = int(input())
inp = input().split()
for i in range(0, n) :
    cost.append( int(inp[i]))
cost.sort()

ans = 0
for i in range(1, n + 1) :
    cur = mul(pow[i - 1], mul(int(cost[i - 1]), pow[n - i]))
    if i < n : cur = add(cur, pow[i - 1] * pow[n - i - 1] % mod * int(cost[i - 1])
                          % mod * (n - i) % mod)
    ans = add(ans, cur)
print(mul(ans, pow[n]))
''' test
6
623 77 177 26 865 192
'''

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
c=list(map(int,input().split()))
INF=10**9+7
c.sort()
ans=0
for i in range(n):
    ans=ans+c[i]*(n-i+1)
    ans=ans%INF
x=pow(2,2*n-2,INF)
ans=(ans*x)%INF
print(ans)

Solution (Python):
N = int(input())
*C, = map(int, input().split())
C.sort(reverse=True)
p = 10**9+7
S = 0
for i in range(N):
    S = (S+(i+2)*C[i]) % p
S = (S*pow(4, N-1, p)) % p
print(S)

Solution (Python):
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
c.sort(reverse=True)
ans=0
po2=[1]
for i in range(n):
    po2.append(po2[-1]*2%mod)
for i,j in enumerate(c,1):
    ans+=j*((i-1)*po2[i-2]+po2[i-1])*po2[n-i]*po2[n-i]*po2[i]%mod
    ans%=mod
print(ans)

Solution (Python):
def main():
    n=int(input())
    c=sorted(list(map(int,input().split())))
    mod=10**9+7
    ans=0
    for i,j in enumerate(c):
        ans=(ans+j*(n-i+1))%mod
        
    ans=(ans*4**(n-1))%mod
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = sorted(list(map(int,input().split())),reverse=True)
mod = 10**9+7

ans = 0

for i in range(n-1,-1,-1):
    ans += ((2+i)*l[i])
b = pow(2,2*n-2,mod)
print(ans*b%mod)

Solution (Python):
mod = 10**9 + 7
n = int(input())
c = list(map(int,input().split()))
c.sort(reverse = True)
ans = 0
for i in range(n):
    ans += c[i]*(i+2) 
    ans %= mod
ans *= pow(4,n-1,mod)
ans %= mod
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    c = LI()
    c.sort()
    if n == 1:
        print(2*c[0]%mod)
        return
    k = pow(2,n-2,mod)
    p = pow(2,n,mod)
    f = [k*(i+2)%mod for i in range(n)][::-1]
    ans = 0
    for i in range(n):
        ans += c[i]*f[i]
        ans %= mod
    print(ans*p%mod)
    return


if __name__ == "__main__":
    solve()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')



class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))


def main():
    N=I()
    C=sorted(LI())
    ans = ModInt(0)
    for i,c in enumerate(C):
        R = ModInt(N-i-1)
        
        ans += (ModInt(2)**i) * c * ( 2**R + R*(2**(R-1)) )
    ans *= 2**N
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache





MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
C = inputIL()

C.sort()

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

MAX = (N+1)*pow(2,N-2,MOD)
MIN = pow(2,N-1,MOD)

d = inv(N-1) * (MAX-MIN) % MOD
  
ans = 0
for i in range(N):
  ans = (ans + (C[N-1-i] * (MIN+d*i)) % MOD ) % MOD

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

Solution (Python):
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse =  True)

MOD = 10 ** 9 + 7

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

start = pow(2, N - 1, MOD)
step = pow(2, N - 2, MOD)
ans = 0
for c in C:
    ans += c * start
    ans %= MOD
    start += step
    start %= MOD

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

print (ans)

Solution (Python):
def main():
    N = int(input())
    C = list(map(int, input().split()))
    C.sort()
    MOD = 10 ** 9 + 7
    two = [0] * (N + 1)
    two[0] = 1
    for i in range(N):
        two[i+1] = two[i] * 2
        two[i+1] %= MOD
    ans = 0
    for i in range(N):
        l = i
        r = N - 1 - i
        now = two[r]
        if r != 0:
            now += two[r-1] * r
        now *= two[l]
        now %= MOD
        now *= C[i]
        ans += now
        ans %= MOD

    ans *= two[N]
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()

c = l()

c.sort(reverse = True)

po = 1

for i in range(n-1):
    po *= 4
    po %= mod

co = 0

for i in range(n):
    co += (i+2)*c[i]
    co %= mod
    
print((co * po) % mod)

Solution (Python):
n = int(input())
c = list(map(int, input().split()))
mod = 10 ** 9 + 7

c.sort(reverse=True)
ans = 0
for i, e in enumerate(c):
    ans += e * (2 + i)
    ans %= mod

ans *= pow(2, 2 * n - 2, mod)
ans %= mod

print(ans)