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):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def solve():
    n = II()
    c = LI()
    c.sort(reverse=True)
    ans = pow(4, n - 1, mod)
    tmp = 0
    for i in range(n):
        tmp += c[i] * (i + 2)
        tmp %= mod

    print(ans*tmp%mod)
        
    return



if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())

def power(a, b):
	if b == 0:
		return 1
	elif b == 1:
		return a % 1000000007
	elif b % 2 == 0:
		return (power(a, b//2) ** 2) % 1000000007
	else:
		return (power(a, b//2) ** 2 * a) % 1000000007
 
def divide(a, b):
	return (a * power(b, 1000000005)) % 1000000007



fac_lim = 200000
fac = [None]*(fac_lim+1)
fac[0] = 1
for i in range(fac_lim):
    fac[i+1] = fac[i] * (i+1)
    fac[i+1] = fac[i + 1] % 1000000007

fac_inv = [None]*(fac_lim+1)
fac_inv[fac_lim] = power(fac[fac_lim], 1000000005)
for i in range(fac_lim, 0, -1):
    fac_inv[i-1] = (fac_inv[i] * i)  % 1000000007

def conv(a, b):
    return (fac[a] * fac_inv[a-b] * fac_inv[b]) % 1000000007

MOD = 10**9 + 7

C = [int(i) for i in input().split()]
C.sort(reverse=True)

ans = 0
for i in range(N):
    ans += C[i] * (1+divide(i, 2))

ans *= power(2, 2*N-1)
ans %= MOD

print(ans)

Solution (Python):
import sys
INF=1e9
mod=1e9+7
n=int(input())
lit=list(map(int,input().split()))
lit.sort()
ans=0
for i in range(n):
    ans=(ans+lit[i]*(n-i+1)%mod)%mod
for i in range((n-1)):
    ans=ans*4%mod
ans=int(ans)
print(ans)

Solution (Python):
import sys
INF=1e9
mod=1e9+7
n=int(input())
lit=list(map(int,input().split()))
lit.sort()
ans=0
for i in range(n):
    ans=(ans+lit[i]*(n-i+1)%mod)%mod
for i in range(2*(n-1)):
    ans=ans*2%mod
ans=int(ans)
print(ans)

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

def power(p, e):
  ret = 1
  while(e):
    if(e & 1):
      ret *= p
      ret %= mod
    p *= p
    e >>= 1
  return ret

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

f = 0
for i in range(N):
  f += (N - i + 1) * C[i]
  f %= mod

f *= power(2, N - 1)**2 % mod
f %= mod
print(f)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
mod = 10 ** 9 + 7
res = 0
if N == 1:
  print(a[0] * 2 % mod)
  exit(0)
for i in range(N):
  res += a[i] * (pow(2, N - 1, mod) % mod + pow(2, N - 2, mod) * i % mod) % mod
  res %= mod
print(res * pow(2, N, mod) % mod)

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

def power(a, n, mod):
    """
    a >= 1, n >= 0の場合のみに対応
    """
    if n == 0:
        return 1
    elif n == 1:
        return a % mod
    elif n % 2 == 0:
        num = power(a, n // 2, mod)
        return num ** 2 % mod
    elif n % 2 == 1:
        num = power(a, (n - 1) // 2, mod)
        return a * num ** 2 % mod

"""
ans = ¥Sum_{S, T} ¥Sum_i C_i * (S[i:] ¥xorSum T[i:])
    = ¥Sum_i C_i ¥Sum_{S, T} (S[i:] ¥xorSum T[i:])

¥Sum_{S, T} (S[i:] ¥xorSum T[i:])について考える。
添字iからN-1までの中にk箇所S[j] != T[j]なるjが存在したとすると、
この時C_iが足される回数は
    cmb(N-i-1, k-1) * 2^{N-i} * k * 4^i
これをkについて総和を取れば、C_iの足される回数は
    2^{N+i} * ¥Sum_{k=1}^{N-i} k * cmb(N-i-1, k-1)
        = 2^{N+i} * ¥Sum_{k=0}^{N-i-1} (k+1) * cmb(N-i-1, k)
        = 2^{N+i} * {¥Sum_{k=0}^{N-i-1} cmb(N-i-1, k) + (N-i-1) * ¥Sum_{k=1}^{N-i-1} cmb(N-i-2, k-1)}
        = 2^{N+i} * {2^{N-i-1} + (N-i-1) * ¥Sum_{k=0}^{N-i-2} cmb(N-i-2, k)}
        = 2^{N+i} * {2^{N-i-1} + (N-i-1) * 2^{N-i-2}}
        = 2^{2N-1} + (N-i-1) * 2^{2N-2}
        =4^{N-1} * (N-i+1)
"""
ans = 0
for i in range(N):
    ans += C[i] * (N - i + 1) * power(4, N - 1, mod)
    ans %= mod
print(ans)

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

print((sum([(n + 2 - i) * ci for i, ci in enumerate(c, 1)]) * pow(4, n - 1, p)) % p)

Solution (Python):
import sys
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
if n==1:
  print(c[0]*2%mod)
  sys.exit()
c.sort()
c.reverse()
ans=0
x=pow(2,n-2,mod)
for i in range(n):
  ans+=c[i]*(i+2)*x
  ans%=mod
ans*=pow(2,n,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() * 2**N
print(answer%MOD)

Solution (Python):
MOD = 1000000007

N = int(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)

Solution (Python):
MOD = 1000000007

N = int(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)

Solution (Python):

n = int(input())
c = [int(i) for i in input().split()]
mod = 10**9+7

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

ans *= 4**(n-1)
ans %= mod
print(ans)

Solution (Python):

n = int(input())
c = [int(i) for i in input().split()]
mod = 10**9+7

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

ans %= mod
ans *= 4**(n-1)
ans %= mod
print(ans)

Solution (Python):
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


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


C.sort()


beki = [1]
for i in range(1, 3*N+20):
    beki.append((beki[i-1]*2)%MOD)


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

print(ans % MOD)

Solution (Python):
MOD = 10**9+7
class mint:
    def __init__(self, x):
        self.x = x % MOD if isinstance(x, int) else int(x) % MOD
    def __str__(self):
        return str(self.x)
    __repr__ = __str__
    def __iadd__(self, other):
        self.x += other.x if isinstance(other, mint) else other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __isub__(self, other):
        self.x += MOD-other.x if isinstance(other, mint) else MOD-other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __imul__(self, other):
        self.x *= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __imod__(self, other):
        self.x %= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __add__(self, other):
        return (
            mint(self.x + other.x) if isinstance(other, mint) else
            mint(self.x + other)
        )
    def __sub__(self, other):
        return (
            mint(self.x - other.x) if isinstance(other, mint) else
            mint(self.x - other)
        )
    def __mul__(self, other):
        return (
            mint(self.x * other.x) if isinstance(other, mint) else
            mint(self.x * other)
        )
    def __mod__(self, other):
        return (
            mint(self.x % other.x) if isinstance(other, mint) else
            mint(self.x % other)
        )
    def __truediv__(self, other):
        return (
            mint(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(self.x * pow(other, MOD - 2, MOD))
        )
    def __pow__(self, other):
        return (
            mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
            mint(pow(self.x, other, MOD))
        )
    __radd__ = __add__
    def __rsub__(self, other):
        return (
            mint(other.x - self.x) if isinstance(other, mint) else
            mint(other - self.x)
        )
    __rmul__ = __mul__
    def __rmod__(self, other):
        return (
            mint(other.x % self.x) if isinstance(other, mint) else
            mint(other % self.x)
        )
    def __rtruediv__(self, other):
        return (
            mint(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(other * pow(self.x, MOD - 2, MOD))
        )
    def __rpow__(self, other):
        return (
            mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
            mint(pow(other, self.x, MOD))
        )

n = int(input())
c = list(map(int, input().split()))
c.sort()
ans=mint(0)
mn=mint(n)
for i in range(n):
    r=mint(n-i-1)
    l=mint(i)
    if r.x>0:
        ans+=(2**r+2**(r-1)*r)*2**l*2**mn*c[i]
    else:
        ans+=2**l*2**mn*c[i]

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from math import factorial

def comb(a,d):
    return factorial(a)//factorial(b)//factorial(a-b)

mod = 10**9+7

N = int(input())
C_input = list(map(int, input().split()))

C = sorted(C_input)
ans = 0
for ind, s in enumerate(C):
    ans+= C[ind] * (N+1-ind)
    ans %= mod
print(int(ans* 2**(2*N-2)) %mod)

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

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

mod=10**9+7


ans=0
for i in range(N):
    ans+=C[i]*(N-i+1)
    ans%=mod
    
p=pow(4,N-1,mod)
print((ans*p)%mod)

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

MOD = 10 ** 9 + 7
pow = 4 ** (N - 1) % MOD

ans = 0
for i, c in zip(range(N), C):
    ans += (i + 2) * c % MOD
    ans %= MOD

print(ans * pow % MOD)

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

Solution (Python):
MOD=10**9+7
MAXN=4*(10**5)

two_power=[1 for _ in range(MAXN+10)]
for i in range(1, MAXN+10):
    two_power[i]=(two_power[i-1]*2)%MOD

n=int(input())
c=list(map(int, input().split()))
c.sort(reverse=True)
ans=0
x=two_power[2*n-1]
d=two_power[2*n-2]
for i in range(n):
    ans+=(x+i*d)*c[i]
print(ans%MOD)

Solution (Python):
N = int(input())
C = [int(c) for c in input().split()]
C.sort()
MOD = 10**9+7
p2 = [1]
for i in range(2*N+10):
  p2 += [p2[-1]*2%MOD]

ans = 0
for i in range(N):
  m = (p2[N-1-i]+(N-i-1)*p2[N-i-2])*C[i]

  m = m*p2[N+i]%MOD
  ans += m
print(ans%MOD)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

A.sort()
x = (A * np.arange(N+1,1,-1) % MOD).sum() % MOD
x *= pow(2, N+N-2, MOD); x %= MOD
print(x)

Solution (Python):
import numpy as np

n = int(input())
c = np.array(input().split(),dtype=int)
mod = 10**9+7

c = sorted(c)[::-1]

e4 = 1
k = n-1
inst = 4
while k > 0:
    if k%2 == 1:
        e4 = (e4*inst)%mod
    k = k//2
    inst = (inst**2)%mod

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

print(ans)

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

mod = 10**9+7

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

Solution (Python):
def main():
    mod=1000000007
    n=int(input())
    C=list(map(int,input().split()))
    C.sort(reverse=True)
    ans=0
    for i,c in enumerate(C):
        ans+=c*(i+2)
        ans%=mod
    ans*=pow(4,n-1,mod)
    ans%=mod
    print(ans)
    
if __name__=='__main__':
    main()

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

Solution (Python):
n = int(input())
c = list(map(int, input().split()))
mod = 10**9+7
c.sort(reverse=True)
ans = 0
for k, num in enumerate(c):
    ans += (k+2)*num
    ans %= mod

for _ in range(2*n-2):
    ans *= 2
    ans %= mod

print(ans)

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

Solution (Python):
N = int(input())
C = list(map(int,input().split()))
C.sort(reverse=True)
MOD = 10**9+7
if N==1:
    print((C[0]*2)%MOD)
    exit()

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

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

Solution (Python):
from sys import stdin
f_i = stdin

mod = 10 ** 9 + 7

N = int(f_i.readline())

C = map(int, f_i.readline().split())
C = sorted(C)

x = (C_i * i % mod for i, C_i in zip(range(N + 1, 1, -1), C))

ans = pow(4, N - 1, mod) * sum(x) % mod

print(ans)

Solution (Python):


import itertools
import sys

N = int(input())
C = [int(x) for x in input().split()]


C.sort()


sum = 0
for i in range(N):
	sum += (N + 1 - i) * C[i]
sum *= 2 ** (N - 2)
sum *= 2 ** N


print(int(sum % (10 ** 9 + 7)))

Solution (Python):
def power(n, r, mod=10**9+7):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


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

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

ans *= power(4, N-1)
ans %= MOD
print(ans)

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

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

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

Solution (Python):
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
if n==1:
  print((2*arr[0])%mod)
else:
  table=[1]
  for _ in range(n):
    tmp=table[-1]*2
    tmp%=mod
    table.append(tmp)
  for i in range(n):
    if i==n-1:    
      ans+=(table[i-1]*(n-i+1)*arr[i])%mod
    else:
      ans+=(table[i]*(n-i+1)*table[n-i-2]*arr[i])%mod
  print((ans*table[n])%mod)

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

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

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

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

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


def mod(a):
    if a >= M:
        a %= M
    return a

def powmod(a, n):
    if n == 0:
        return 1
    if n % 2:
        return mod(a * powmod(a, n - 1))
    else:
        return mod(powmod(a, n // 2)**2)

result = 0
for i, v in enumerate([mod(i * powmod(2, (n - 1) * 2)) for i in range(2, 2 + n)]):
    result = mod(result + mod(v * a[i]))
print(result)

Solution (Python):

import sys

N=input()
C=map(int, sys.stdin.readline().split())
C.sort()

mod=10**9+7
D=[]
d0=pow(2,N-1,mod)


for i in range(N):
    if i==0:
        D.append(d0)
    else:
        next=(2*D[-1]-d0)*pow(2,mod-2,mod)+d0
        D.append(next%mod)



ans=0
for c,d in zip(C,D[::-1]):
    ans+=c*d
    ans%=mod

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

print ans%mod

Solution (Python):

import sys

N=input()
C=map(int, sys.stdin.readline().split())
C.sort()

mod=10**9+7
D=[]
d0=pow(2,N-1,mod)


for i in range(N):
    if i==0:
        D.append(d0)
    else:
        next=(2*D[-1]-d0)*pow(2,mod-2,mod)+d0
        D.append(next%mod)



ans=0
for c,d in zip(C,D[::-1]):
    ans+=c*d
    ans%=mod

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

print ans%mod

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

mod = 10**9 + 7

C = sorted(C)[::-1]

ans = 0

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

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

Solution (Python):


MOD = 10**9+7


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

C.sort(reverse=True)
ans = 0

if N == 1:
    ans = C[0]*2**N
else:
    for i in range(N):
        ans += C[i]*(2+i)

    ans *= 4**(N-1)


print(ans%MOD)

Solution (Python):
import sys


n = int(input())
c = sorted([int(_) for _ in input().split()], reverse=True)
mod = 10**9+7
ans = 0
if n == 1:
    ans += c[0] * 2
    ans %= mod
    print(ans)
    sys.exit()
for i in range(n):
    ans += (c[i] * (pow(2, n-1, mod) + pow(2, n-2, mod) * i)) % mod
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)

Solution (Python):
N=int(input())
C=sorted(list(map(int,input().split())),reverse=True)
mod=10**9+7
def mpow(x,n):
    num=1
    while n > 0:
        if n&1:
            num=num*x%mod
        x=x*x%mod
        n=n>>1
    return(num)
count=0
for i, c in enumerate(C, 2):
    count += c * (i)
    count %= mod
print(count * mpow(2, N-1)*mpow(2, N-1) % mod)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

from bisect import *
from collections import *
from heapq import *



INF = 500000
mod = 10**9+7

N = int(input())
C = [int(x) for x in input().split()]
C.sort(reverse = 1)
x = 0
for i, c in enumerate(C, 1):
    x += c * (i+1)
    x %= mod
print(x * pow(4, N-1, mod) % mod)

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

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

for i in range(n):
  ans += (i+2) * c[i]
  ans %= mod
ans *= two[2*n - 2]
print(ans%mod)

Solution (Python):
N = int(input())
C = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

C.sort()

ret = 0
P = pow(4, N - 1, mod)
for i in range(N) :
  ret += C[i] * P * (N - i + 1) % mod
  ret %= mod

print(ret)

Solution (Python):
N = int(input())
C = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

C.sort()

ret = 0
for i in range(N) :
  rest = N - i - 1
  if rest == 0 :
    ret += C[i] * pow(4, i, mod) * pow(2, N - i, mod) * pow(2, rest, mod) % mod
  else :
    ret += C[i] * pow(4, i, mod) * pow(2, N - i, mod) * (rest + 2) * pow(2, rest - 1, mod) % mod
  ret %= mod

print(ret)

Solution (Python):

def inv(x):
    global mod
    return pow(x,mod-2,mod)

mod=10**9+7
N = int(input())
C = [0]
C.extend(sorted(list(map(int,input().split())), reverse=True)) 







pow2 = [1]
for k in range(1, N+1):    
    pow2.append(pow2[-1] * 2 % mod)



ans=0
for i in range(1, N+1):
    temp = pow2[N - i] * C[i] * ((0 if i == 1 else (pow2[i - 2] * (i - 1))) + pow2[i - 1]) % mod
    ans = (ans + temp) % mod

ans = ans * pow2[N] % mod

print(ans)

Solution (Python):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq
sys.setrecursionlimit(100000)


def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

class mint:
    mod = int(1e9 + 7)
    def __init__(self, v = 0):
        if not ((v >= 0) and (v < mint.mod)):
            v %= mint.mod
            if v < 0: v += mint.mod
        self.V = v
    def __add__(self, other):
        v = self.V + (other.V if isinstance(other, mint) else other)
        return mint(v)
    def __sub__(self, other):
        v = self.V - (other.V if isinstance(other, mint) else other)
        return mint(v)
    def __mul__(self, other):
        v = self.V * (other.V if isinstance(other, mint) else other)
        return mint(v)
    def __floordiv__(self, other):
        v = self.V * mint.inv((other.V if isinstance(other, mint) else other))
        return mint(v)
    def __truediv__(self, other):
        v = self.V * mint.inv((other.V if isinstance(other, mint) else other))
        return mint(v)
    
    def __eq__(self, other):
        return self.V == (other.V if isinstance(other, mint) else mint(other).V)
    def __ne__(self, other):
        return self.V != (other.V if isinstance(other, mint) else other)
    def __int__(self): return self.V
    
    def __radd__(self, other):
        v = (other.V if isinstance(other, mint) else other) + self.V
        return mint(v)
    def __rsub__(self, other):
        v = (other.V if isinstance(other, mint) else other) - self.V
        return mint(v)
    def __rmul__(self, other):
        v = (other.V if isinstance(other, mint) else other) * self.V
        return mint(v)
    def __rfloordiv__(self, other):
        v = (other.V if isinstance(other, mint) else other) * mint.inv(self.V)
        return mint(v)
    def __rtruediv__(self, other):
        v = (other.V if isinstance(other, mint) else other) * mint.inv(self.V)
        return mint(v)

    @staticmethod
    def inv(x):
        a, _, _ = mint.extGCD(x, mint.mod)
        return (a + mint.mod) % mint.mod
    @staticmethod
    def extGCD(x, y):
        r0 = x
        r1 = y
        a0 = 1
        a1 = 0
        b0 = 0
        b1 = 1
        while(r1 > 0):
            q1 = r0 // r1
            r2 = r0 % r1
            a2 = a0 - q1 * a1
            b2 = b0 - q1 * b1
            r0 = r1; r1 = r2
            a0 = a1; a1 = a2
            b0 = b1; b1 = b2
        c = r0
        a = a0
        b = b0       
        return a, b, c
    @staticmethod
    def pow(x, k):
        x = x.V if isinstance(x, mint) else x
        return pow(x, k, mint.mod)

    
    def __str__(self):
        return str(self.V)
    def __repr__(self):
        return str(self.V)

def main():
    N = ri()
    A = ria()
    A = sorted(A)
    A = list(reversed(A))
    Pow2 = [mint(0)] * (N + 1)
    Pow2[0] = mint(1)
    for i in range(1,N+1): Pow2[i] = Pow2[i-1] * 2

    tot = mint(0)
    for i in range(N):
        tot += mint(A[i]) * Pow2[N-1]
        if i > 0: tot += mint(A[i]) * i * Pow2[N-2]
    tot *= Pow2[N]
    print(tot)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()
C = III()
C.sort()

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

print(ans)

Solution (Python):


import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  

def solve(N: int, C: "List[int]"):
    pows = [1]
    for i in range(N):
        pows.append(pows[i] * 2 % MOD)

    C.sort(reverse=True)
    ret = 0
    for i, v in enumerate(C):
        if i > 0:
            ret += (pows[i] + pows[i - 1] * i) * (pows[N - i - 1]) * v
        else:
            ret += pows[i] * (pows[N - i - 1]) * v
    ret = ret * pows[N] % MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [int(next(tokens)) for _ in range(N)]  
    solve(N, C)

if __name__ == '__main__':
    main()

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

MOD = 10 ** 9 + 7

m = 4 ** (n-1) % MOD

c.sort(reverse=True)

ans = 0
for i in range(n):
    ans = (ans + c[i] * (i+2) * m) % MOD

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

C.sort()

for i in range(N):
    left = pow(2, 2*i, MOD)
    
    if i==N-1:
        right = 1
    else:
        right = pow(2, 2*N-2*i-3, MOD)*(N-i+1)

    ans += left*right*2*C[i]
    ans %= MOD

print(ans)

Solution (Python):

n=int(input())
C=sorted(list(map(int,input().split())))
mod=10**9+7

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

sum=0
for i in range(n):
    l=i 
    r=n-i 
    if r==1:
        ans=pow2[l]
        ans=ans*C[i]%mod
        sum=(sum+ans)%mod
    else:
        ans=pow2[r-1]
        ans=(ans+pow2[r-2]*(r-1)%mod)%mod
        ans=ans*pow2[l]%mod
        ans=ans*C[i]%mod
        sum=(sum+ans)%mod
print((sum*pow2[n]%mod))

Solution (Python):
import collections as c
ip = lambda : map(int, input().split())
mod = 10**9+7

N = int(input())
l = list(ip())
l.sort()

ans = 0
f = 1
for i in range(N):
    ans = (ans + l[i]*(1+N-i)%mod)%mod
    if i>0:
        f=f*4%mod
ans = ans*f%mod
print(ans)

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

N, *C = map(int, open(0).read().split())

C.sort(reverse=True)
print(pow(4, N - 1, mod) * (sum(i * c for i, c in enumerate(C, 2)) % mod) % mod)

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

N, *C = map(int, open(0).read().split())

C.sort(reverse=True)
print(pow(4, N - 1, mod) * sum(i * c for i, c in enumerate(C, 2)) % mod)

Solution (Python):


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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
mod = 10**9+7

n=int(input())
c=list(map(int,input().split()))
c.sort(reverse=True)

lpow = [False] * (n+5)
lpow[0] = 1
def pow(n,p):
    if p<0:return 0
    if lpow[p]:
        return lpow[p]
    else:
        if p % 2 == 0:
            ret = (pow(n,p//2)**2) % mod
        else:
            ret = ((pow(n,p//2)**2)*n) % mod
        lpow[p] = ret
        return ret

res = 0
for i in range(n):
    res += (c[i]*pow(4,n-1)*(i+2))% mod
    res %= mod
print(res)

Solution (Python):



num = int(input())
costs = sorted(list(map(int, input().split())), reverse = True)

total = 0
for i in range(1, num+1):
    total += (i + 1) * costs[i-1]
ans = (total * (4 ** (num - 1))) % (10 ** 9 + 7)
print(ans)

Solution (Python):
import sys

MOD = 10 ** 9 + 7

def make_power_2_table(n=10**6, mod=MOD):
    power = [None] * (n + 1)
    power[0] = 1
    for i in range(n):
        power[i+1] = power[i] * 2 % mod
    return power

power_2 = make_power_2_table(2*10**5)
inv_2 = pow(2, MOD-2, MOD)

n, *c = map(int, sys.stdin.read().split())
c.sort()

def main():
    res = 0
    for i in range(n):
        sum_d = (power_2[n-i-1] + power_2[n-(i+1)] * inv_2 % MOD * (n-(i+1)) % MOD) % MOD
        l_comb = power_2[i]
        res += c[i] * l_comb % MOD * sum_d % MOD
        res %= MOD

    return res * power_2[n] % MOD

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys

MOD = 10 ** 9 + 7

def make_power_2_table(n=10**6, mod=MOD):
    power = [None] * (n + 1)
    power[0] = 1
    for i in range(n):
        power[i+1] = power[i] * 2 % mod
    return power

power_2 = make_power_2_table(2*10**5)
inv_2 = pow(2, MOD-2, MOD)

n, *c = map(int, sys.stdin.read().split())
c.sort()

def main():
    r_diffs = (power_2[n] + power_2[n] * n % MOD * inv_2 % MOD) % MOD
    res = 0
    for i in range(n):
        r_diffs = (r_diffs - power_2[n-i-1]) % MOD * inv_2 % MOD
        l_comb = power_2[i]
        res += c[i] * l_comb % MOD * r_diffs % MOD
        res %= MOD

    return res * power_2[n] % MOD

if __name__ == '__main__':
    ans = main()
    print(ans)