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

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()
# N-2がマイナスになる時に注意、一番右は2**(N-1)
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)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

# テスト用コード
# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()
# N-2がマイナスになる時に注意、一番右は2**(N-1)
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)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

# テスト用コード
# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()
# N-2がマイナスになる時に注意、一番右は2**(N-1)
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)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()
# N-2がマイナスになる時に注意、一番右は2**(N-1)
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
####################################### Define
mod = int(1e9 + 7)
maxN = int(2e5 + 100)
pow = [1] * maxN
cost = []

####################################### Functions
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)
####################################### Main
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
'''

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
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', '')


#mint
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()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
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)]

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

######Combination######
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

######Factorization######
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

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

#############
# Main Code #
#############

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    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): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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')

#solve
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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 2のべき乗は先に計算しておく
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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