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



Sample input:
1
1000000000


Sample output:
999999993

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

# MOD combination
def cmb(n, r, mod=10**9+7):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 2*10**5+10
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 )

ans=0
c.sort(reverse=True)
# r=ruiseki(c)
for i in range(n):
    ans+=c[i]*(i+2)
    ans%=mod
ans*=pow(4,n-1,mod)
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

MOD = 10 ** 9 + 7

N = int(input())
Cs = sorted(map(int, input().split()), reverse = True)

magic = [pow(2, N-1, MOD)]
for _ in range(N-1):
    magic.append( (magic[-1] + pow(2, N-2, MOD)) % MOD )

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

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

print(ans)

Submission status: Accepted

Solution code:

def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())
    C = sorted(map(int, input().split()))
    P = [1] * (N + 1)
    for i in range(N):
        P[i + 1] *= P[i] * 2
        P[i + 1] %= MOD
    ans = 0
    for i in range(N):
        # 各ビットの係数: (2^r + 2^r-1 * r) * 2^l
        l, r = i, N - i - 1
        now = P[r]
        if r != 0:
            now += P[r - 1] * r
        now *= P[l]
        now *= C[i]
        ans += now
        ans %= MOD
    ans *= P[N]
    print(ans % MOD)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

def main():
    n = int(input())
    c = list(map(int, input().split()))
    c.sort()
    ans = 0
    for i in range(n):
        tmp = pow(2, i, MOD)
        if i < n-1:
            tmp *= pow(2, n-i-1, MOD) + pow(2, n-i-2, MOD) * (n-i-1)
        else:
            tmp *= pow(2, n-i-1, MOD)
        tmp %= MOD
        ans += c[i] * tmp
    print(ans * pow(2, n, MOD) % MOD)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
C = LI()
mod = 10**9+7

C = [0] + sorted(C,reverse=True)

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    C = list(map(int, input().split(' ')))
    C.sort()
    pow_2 = 1  # 2 ** (2 * N - 2)
    for _ in range(2 * N - 2):
        pow_2 *= 2
        pow_2 %= MOD
    ans = 0
    for k, c in enumerate(C):
        ans += c * ((N - k + 1) * pow_2)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()
C_array = na()
C_array.sort()
ans = 0
mod = 10 ** 9 + 7
dp = [C_array[0], 0]
arr2 = [0, 1]
j = 1
for i in range(N):
    j = j * 2 % mod
    arr2.append(j)

# print(dp)
cold = C_array[0]
cusum = 0
for i, c in enumerate(C_array[1:]):
    new00 = (dp[0] + cold * arr2[i + 1] + cusum *
             arr2[i] + c * arr2[i + 1]) % mod
    new01 = (dp[1] + cusum * arr2[i] + c * arr2[i + 1]) % mod
    # print(new00,new01)
    new0 = (new00 + new01) % mod
    new1 = (dp[0] + dp[1]) % mod
    dp = [new0, new1]
    # print(dp)
    cusum = (cold + cusum) % mod
    cold = c
ans = (dp[0] + dp[1]) * arr2[N + 1] % mod
print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

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

Submission status: Accepted

Solution code:
N = int(input())
C = sorted(list(map(int,input().split())),reverse=True)
L = 10**9 + 7


if N > 1:
    b = 2**(N-2) % (L)
    a = [C[i] * b * (2+i) % L for i in range(N)]
    print(sum(a)*b*2*2%L)
else:
    print(C[0]*2%L)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


class Combination(object):

    def __init__(self, N, mod=MOD):
        fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N+1):
            fac[i] = fac[i-1]*i % mod
            inv[i] = -inv[mod % i]*(mod//i) % mod
            finv[i] = finv[i-1]*inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        fac = self.fac
        finv = self.finv
        mod = self.MOD
        return fac[n] * (finv[k]*finv[n-k] % mod) % mod


def solve(N: int, C: "List[int]"):

    ans = 0
    C.sort(reverse=True)
    for i, c in enumerate(C, start=1):
        b = c*(pow(2, 2*N-2, MOD)*(i+1)) % MOD
        ans += b
        ans %= MOD
    print(ans % MOD)
    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))  # type: int
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, C)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
M = 10**9+7

pp = [None]*n
v = 1
for i in range(n):
    pp[i] = v
    v *= 2
    v %= M

a.sort()
a = a[::-1]
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pp[i] + i*pp[i-1])*pp[n-i-1]
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pow(2, i, M) + i*pow(2,i-1,M))*pow(2,n-i-1,M)
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


class Combination:
    def __init__(self, mod=10**9+7, n=202020):
        self.f = [0] * n
        self.rf = [0] * n
        self.inv = [0] * n
        self.f[0], self.f[1] = 1, 1
        self.rf[0], self.rf[1] = 1, 1
        self.inv[1] = 1
        self.MOD = mod
        for i in range(2, n):
            self.f[i] = (self.f[i - 1] * i) % self.MOD
            self.inv[i] = (-self.inv[self.MOD % i] * (self.MOD // i)) % self.MOD
            self.rf[i] = (self.rf[i - 1] * self.inv[i]) % self.MOD

    def __call__(self, n, r):
        return (self.f[n] * self.rf[r] * self.rf[n - r]) % self.MOD


C = Combination()

n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
for i in range(n):
    ans = (ans + A[i]*(i+2)) % MOD

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    if i < n - 1:
        ans += c[i] * (n - i + 1) * pow(2, n - i - 2, mod) * pow(2, i, mod)
        ans %= mod

    else:
        ans += c[i] * pow(2, n - i - 1, mod) * pow(2, i, mod)
        ans %= mod


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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import queue
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, C):
    mod = 10**9 + 7
    if N == 1:
        return (C[0] * 2) % mod

    C.sort()
    ans = 0
    a = pow(2, N, mod)
    b = pow(2, N-1, mod)
    c = pow(2, N-2, mod)
    for i in range(N):
        d = (N-i-1) * c
        d %= mod
        n = a * (b + d)
        n %= mod
        ans += n * C[i]
        ans %= mod

    return ans % mod




def main():
    N = read_int()
    C = read_int_n()
    print(slv(N, C))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
C = LI()

MOD = 10 ** 9 + 7


def main():
    ans = 0
    C.sort()
    for i in range(N):
        x = C[i] * (N - i + 1) % MOD
        ans = (ans + x) % MOD
    ans = ans * pow(4, N - 1, MOD) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

p=pow(4,N-1,mod)
ans=ans*p%mod
print(ans)

Submission status: Accepted

Solution code:
mod = int(1e9+7)
n = int(input())
arr = list(map(int, input().split()))
arr.sort()

s = 0
for e in arr:
    s += e
    s %= mod

total = s*pow(2, n-1, mod) % mod

def fn(x):
    if x == 0:
        return 0
    return (x*pow(2, x-1, mod)) % mod

for i in range(n):
    total += fn(n-i-1) * pow(2, i, mod) % mod * arr[i] % mod
    total %= mod
    #print(i, fn(n-i-1), pow(2, i, mod), arr[i])

print(total*pow(2, n, mod)%mod)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)
    c = list(geta(int))
    c.sort(reverse=True)
    mod = 10**9 + 7
    dp = [0] * (N + 1)

    base = 1
    for n in range(1, N + 1):
        dp[n] = (4 * dp[n - 1] + (n + 1) * base * c[n - 1]) % mod
        base = (4 * base) % mod
    print(dp[N])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)
    c = list(geta(int))
    c.sort(key=lambda x: -x)
    mod = 10**9 + 7
    dp = [0] * (N + 1)

    base = 1
    for n in range(1, N + 1):
        dp[n] = 4 * dp[n - 1] + (n + 1) * base * c[n - 1]
        base *= 4

        dp[n] %= mod
        base %= mod
    print(dp[N])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 0
mod = 10**9+7
for i,ai in enumerate(a):
  chk = pow(2,n-1-i,mod)+(n-1-i)*pow(2,max(0,n-2-i),mod)
  chk %= mod
  ans += chk*pow(2,i,mod)*ai
  ans %= mod
print(ans*pow(2,n,mod)%mod)

Submission status: Accepted

Solution code:
n=int(input())
c=sorted(list(map(int,input().split())))
#n=200000
#c=list(range(n))
mod=pow(10,9)+7
# T=000000..とおいて計算し最後に2^nをかける。
# 各コストCiごとにそれが何回足されるかを求める。
# 一番大きいコストc[-1]の係数は必ず1にするのが最適。同様に一番小さいコストc[0]は必要な係数の中で一番大きなものをかけるのがいい。
ans=0
for i,ci in enumerate(c):
  l=i
  r=n-i
  b=pow(2,r-1,mod)+(r-1)*pow(2,r-2,mod) if r>1 else 1
  b*=pow(2,l,mod)
  ans+=ci*b
  ans%=mod
ans*=pow(2,n,mod)
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
import itertools
import fractions
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
C=nl()
mod=10**9+7
n=0
C.sort()
two=[0]*(N+1)
two[0]=1
for i in range(N):
    two[i+1]=(two[i]*2)%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[i]
    now*=C[i]
    ans+=now
    ans%=mod

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

Submission status: Accepted

Solution code:
import numpy as np
MOD = 10**9 + 7

def plu(a,b):
    return (a + b)%MOD

plus = np.frompyfunc(plu,2,1)

n = int(input())
c = np.sort(np.array(input().split(),dtype = np.int64))
p = pow(2,2*n-2,MOD)
print(plus.reduce(np.mod(np.mod(p*c,MOD)*(n-np.arange(n)+1),MOD)))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15
from heapq import  heapify,heappop,heappush


def main():
    N = int(input())
    C = list(map(int,input().split()))
    C.sort()
    
    power = [1]
    for i in range(N):
        power.append(power[-1]*2%MOD)

    ans = 0
    for i,c in enumerate(C):
        ans += c*(power[N - 2]*power[N]*(N - i - 1))%MOD
        ans += c*(power[N - 1]*power[N])%MOD
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	C = list(reversed(sorted(getlist())))
	ans = 0
	for i in range(N):
		ans += pow(2, 2 * N - 2, con) * (i + 2) * C[i]
		ans %= con

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:

number=10**9+7

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    C = list(map(int, input().split()))
    C.append(INF) # 1-indexed
    C.sort(reverse = 1)

    res = 0
    for i in range(1, n + 1):
        res += (i + 1) * C[i]
        res %= MOD

    res *= pow(4, n - 1, MOD)
    res %= MOD
    print(res)
resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    C=list(map(int,input().split()))
    
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(N,MOD)
    
    def COM(n, k, MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    def modinv(a, mod):
        b,u,v = mod,1,0
        while b:
            t=a//b
            a-=t*b
            a,b=b,a
            u-=t*v
            u,v=v,u
        u%=mod
        if u < 0:
            u+=mod
        return u

    def modpow(n,k,MOD):
        if k<0:
            return pow(modinv(n,MOD),-k,MOD)
        else:
            return pow(n,k,MOD)
    
    C.sort(reverse=1)
    ans=0
    for i in range(N):
        ans+=(modpow(2,i,MOD)+i*modpow(2,i-1,MOD))*2*modpow(2,N-(i+1),MOD)*C[i]
        ans%=MOD
    ans*=pow(2,N-1,MOD)
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
cost = 0
for i in range(1, n+1):
  cost = (cost + a[i-1]*(i+1)) % 1000000007
for i in range(1, n):
  cost = cost * 4 % 1000000007
print(cost)

Submission status: Accepted

Solution code:
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
    #from math import gcd

    #inf = 10**17
    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()

Submission status: Accepted

Solution code:
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
    #from math import gcd

    #inf = 10**17
    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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 解説放送

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):
        # x:=係数.この位置の操作にかかるコストの総和を求める.
        # r:=xの右側にある要素数
        # (1<<r)個の状態を行として並べて,列で不一致数を確認すると,どの列も状態の半分が不一致.これがr列ある.
        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  # MOD忘れ

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 解説放送

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):
        # x:=係数.この位置の操作にかかるコストの総和を求める.
        # r:=xの右側にある要素数
        # (1<<r)個の状態を行として並べて,列で不一致数を確認すると,どの列も状態の半分が不一致.これがr列ある.
        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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
"""

Submission status: Accepted

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

Submission status: Accepted

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