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: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
Sは全部0と仮定して良い，最後に2^N倍
Cはソートしておく，後ろから使う．

各C[i]ごとに見るか，そうしたら，それが何番目かによって寄与が決まる
i桁目なので左に(i-1)桁あるけど，これは通り数にしか関与しない
右側にN-i=a桁分ある．a桁のうちj桁1があるとして，寄与がj*C[i]

通り数：
右：a個からj個えらぶ=aCj
左：0でも1でも置ける=2^(i-1)

i,jの2つのΣで考えると，j側は結局Σ(j * (N-i)Cj)
N-i=aとすればj=0~aでΣ(j * aCj) = a * pow(2,a-1) = (N-i) * pow(2,a-1)

"""

def main():
    mod=10**9+7
    N=I()
    C=LI()
    C.sort()
    ans=0
    
    def calc(ii):
        aaa=(N-ii)
        temp = C[ii]*aaa*pow(2,ii,mod)*aaa*pow(2,aaa,mod)
        return temp%mod
    
    for i in range(N):
        ans=(ans+calc(i))%mod
        
        
    print(ans)

  

main()

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7

def solve(C):
    N = len(C)
    C.sort()

    dp1 = 0
    dp2 = 0
    for k,c in enumerate(C):
        ndp2 = 2*(4**k)*c + 4*dp2
        dp1 = 4*dp1 + ndp2 - 2*dp2
        dp2 = ndp2

    return dp1

def naive(C):
    from itertools import product
    N = len(C)
    C.sort()
    s = 0
    for a in product(range(2),repeat=N):
        for b in product(range(2),repeat=N):
            pop = 1
            for x,y,c in zip(a,b,reversed(C)):
                if x != y:
                    s += c*pop
                    pop += 1
    return s

if __name__ == '__main__':
    N = int(input())
    C = list(map(int,input().split()))
    print(solve(C))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n=int(input())
c=sorted(list(map(int,input().split())))
mod=10**9+7
#2のx乗を前計算(mod)(0~N-1)
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):
    b=bisect_left(c,c[i])
    x=n-b-1
    ans+=(p[x]+x*p[x-1])*c[i]*p[b]
    ans%=mod
print(ans*p[n]%mod)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n=int(input())
c=sorted(list(map(int,input().split())))
mod=10**9+7
#2のx乗を前計算(mod)(0~N-1)
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):
    x=n-bisect_left(c,c[i])-1
    ans+=(p[x]+x*p[x-1])*c[i]*p[i]
    ans%=mod
print(ans*p[n]%mod)

Submission status: Wrong Answer

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

n, s, M = int(input()), sorted(list(map(int, input().split())), reverse = True), int(1e9) + 7
print(sum([(2 ** (n-1) * s[0]) % M] + [(2 ** (n-1-i)) % M * ((2 ** i) % M + (2 ** (i-1)) % M * i) * s[i] for i in range(1, n)]) * ((2 ** n) % M))

Submission status: Wrong Answer

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

n, s = int(input()), sorted(list(map(int, input().split())), reverse = True)
print(sum([2 ** (n-1) * s[0]] + [2 ** (n-1-i) * (2 ** i + 2 ** (i-1) * i) * s[i] for i in range(1, n)]) * (2 ** n))

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
C=list(set(map(int,input().split())))
C_sorted=sorted(C)
MOD=10**9+7
def LC(X):
  k=0
  for j in range(len(X)):
    k+=(len(X)-j)*X[j]
  return k

def f(D):
  Comb=[]
  for pair in itertools.combinations(C_sorted,D):
    Comb.append(pair)
  Sum_D=0
  for i in range(len(Comb)):
    Sum_D+=LC(Comb[i])%MOD
  return Sum_D

t=0
for D in range(1,N+1):
  t+=f(D)%MOD
print(t%MOD)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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):
    bp = [0]
    mod = 10**9 + 7
    for i in range(N+1):
        bp.append(bp[-1] + (1<<i))

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

    return ans % mod




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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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(p*c*(n-np.arange(n)+1),MOD)))

Submission status: Wrong Answer

Solution code:
import numpy as np
MOD=10**9+7
n=int(input())
c=np.sort(np.array(input().split(),dtype=np.int64))
p=pow(2,2*n-2,MOD)
print(np.sum(np.mod(p*c*(n-np.arange(n)+1),MOD)))

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
import math
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq

def combinations(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)
 
def lcm(a, b):
	return a // gcd(a, b) * b

# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))



# n = II()
# p = tuple(MI())
# q = tuple(MI())

# l = list(permutations(list(range(1,n+1))))
# print(abs(l.index(p)-l.index(q)))

 
# N, M = MI()
# A = LI()
# A = [a//2 for a in A]


# while A[0] % 2 == 0:
# 	for i in range(N):
# 		if A[i] % 2 != 0:
# 			print(0)
# 			exit()
# 		A[i] //= 2
# 	M //= 2

# for i in range(N):
# 	if A[i] % 2 == 0:
# 		print(0)
# 		exit()
 
# tmp_lcm = 1
# for i in range(N):
# 	tmp_lcm = lcm(tmp_lcm, A[i])
# 	if M < tmp_lcm:
# 		print(0)
# 		exit()
 
# print((M // tmp_lcm + 1) // 2)


N = II()
C = LI()

ans = 0
# for c in C:
# 	for i in range(1,N+1):
# 		ans += 4**(N-1) * (i+1) *c
# 		ans %= mod
	# ans %= mod
	# ans += (2**N) * c * (2**(N-1)-1)
	# ans %= mod

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

Submission status: Wrong Answer

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)
        r = pow(2, n-i-1, mod) + (n-i-1)*pow(2, n-i-2)
        res += b*c[i]*l*r % mod
    print(int(res))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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: Wrong Answer

Solution code:
N=int(input())
C=list(map(int,input().split()))
C.sort()
s=0
P=10**9+7
for i in range(len(C)-1):
    c=C[i]
    z=N-1-i
    s+=(c*(z*pow(2,z-1,P)+pow(2,z,P)))%P
s+=(N*C[N-1])%P
print((s*pow(2,N,P))%P)

Submission status: Wrong Answer

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()
answer *= pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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)])
if N < 10 ** 4:
    answer = (C * two_power % MOD).sum() * 2 ** N
else:
    answer = (C * two_power % MOD).sum() * pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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)])
if N > 10 ** 4:
    answer = (C * two_power % MOD).sum() * 2 ** N
else:
    answer = (C * two_power % MOD).sum() * pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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)])
if N > 10 ** 5:
    answer = (C * two_power % MOD).sum() * 2 ** N
else:
    answer = (C * two_power % MOD).sum() * pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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() * pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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, N-1, MOD) for i in range(N)])
answer = (C * two_power % MOD).sum() * pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7
# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
N = ir()
C = np.array(lr())
C.sort()
two_power = np.array([(1+N-i) * pow(2, (N-2), MOD) if N-2 >= 0 else 1 for i in range(N)])
answer = (C * two_power % MOD).sum() * pow(2, N, MOD)
print(answer%MOD)

Submission status: Wrong Answer

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

####################################### 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())
cost = input().split()
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]))

Submission status: Wrong Answer

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

# functions
def add(x, y) : return (x + y) % mod
def mul(x, y) : return x * y % mod
def prepare() :
    for i in range(1, maxN):
        pow[i] = mul(pow[i - 1], 2)
# main
prepare()
n = int(input())
cost = input().split()
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, mul(pow[i - 1], mul(n - i, mul(int(cost[i - 1]), pow[n - i - 1]))))
    ans = add(ans, cur)
print(mul(ans, pow[n]))

Submission status: Wrong Answer

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)*p%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: Wrong Answer

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(po,co)
print((co * po) % mod)

Submission status: Wrong Answer

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
print(ans)

Submission status: Wrong Answer

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

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([2**i * (2**(N-i-1) + ((N-i-1) * 2**(N-i-1) // 2)) for i in range(N)])
answer = (C * two_power).sum() * 2**N
print(answer%MOD)
# 10

Submission status: Wrong Answer

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)
for i in range(n):
    r=n-i-1
    l=i
    if r>0:
        ans+=(2**r+2**(r-1)*r)*2**l*2**n*c[i]
    else:
        ans+=2**l*2**n*c[i]

print(ans)

Submission status: Wrong Answer

Solution code:
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]* 2**(N-2) * (N+1-ind)
    ans %= mod
print(ans*2**N %mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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]
#  print(m)
  m = m*p2[N+i]%MOD
  ans += m
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import itertools

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

# Cを昇順にソートしておく
C.sort()

# （C_iの個数×C_iのコスト）の総和×2**Nを求める
sum = 0
for i in range(N):
	sum += (N + 1 - i) * C[i]
sum *= 2 ** (N - 2)
sum *= 2 ** N

# 10**9 + 7で割った余りを求めて出力
print(sum % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
# import math
# import fractions
# import numpy as np

# MOD = 10 ** 9 + 7

# ゼロ埋め
# list = [0] * N

# 二次元配列
# [[inf, inf, inf], [inf, inf, inf]]
# dp = [[float('inf')] * (H + 1) for i in range(N + 1)]

def solve(N, A):
    A.sort()
    two = [0] * (N + 1)
    for i in range(N + 1):
        two[i] = 2 ** i

    ans = 0
    for i in range(N):
        l = i
        r = N-i-1
        now = two[r]
        if r != 0:
            now += two[r-1] * r
        now *= two[l]
        now *= A[i]
        ans += now
    
    ans *= two[N]

    return ans

    return 0

# S = input()
N = int(input())
# H, N = map(int, input().split())
A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

print(solve(N, A))

Submission status: Wrong Answer

Solution code:
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-1,mod)*(1+(n-i-1)/2)*arr[i]
  ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
print(arr)
ans=0
for i in range(n):
  ans+=pow(2,2*n-1,mod)*(1+(n-i-1)/2)*arr[i]
  ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
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)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
print(arr)
ans=0
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)

Submission status: Wrong Answer

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

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

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

#D：係数の配列の作成
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)

#Ci*Diを最小にするため、最小のCiに最大のDiを掛けるため、降順ソートする
D.sort(reverse=True)

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

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

print ans%mod

Submission status: Wrong Answer

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

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

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

#D：係数の配列の作成
for i in range(N):
    if i==0:
        D.append(d0)
    else:
        D.append( ( (2*D[-1]-d0)*pow(2,mod-2,mod)+d0 )%mod )

#Ci*Diを最小にするため、最小のCiに最大のDiを掛けるため、降順ソートする
D.sort(reverse=True)

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

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

print ans%mod

Submission status: Wrong Answer

Solution code:
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]*(i+2) % mod
ans *= 4**(N-1)
ans % mod
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 in range(N):
    if (i)%2==0:
        #print("ue",C[i])
        n=((i+2)//2)*mpow(2,i)%mod
    else:
        #print("sita",C[i])
        n=(((i+1+2)//2)*mpow(2,i)-(((i+1+2)//2)-1))%mod
    count+=n*C[i]* (2**(N-i-1))
    count%=mod
count=count*mpow(2,N)%mod
print(count)

Submission status: Wrong Answer

Solution code:
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 in range(N):
    if (i)%2==0:
        #print("ue",C[i])
        n=((i+2)//2)*mpow(2,i)
    else:
        #print("sita",C[i])
        n=((i+1+2)//2)*mpow(2,i)-(((i+1+2)//2)-1)
    count+=n*C[i]* (2**(N-i-1))
    count%=mod
count=count*mpow(2,N)%mod
print(count)

Submission status: Wrong Answer

Solution code:
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+1) * c[i]
  ans %= mod
ans *= two[2*n - 2]
print(ans%mod)

Submission status: Wrong Answer

Solution code:
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
    f=f*4%mod
ans = ans*(f//4)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()
d = 10**9+7
cost = 1
res = 0

temp_n = N
for i, c in enumerate(list_c) :
  #cost = (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))
  cost = 1

  while(True) :
    if(temp_n < 34) :
      cost *= int((2 ** (temp_n+temp_n-2) * (N-i+1)) * c) % d
      cost = cost % d
      break
    else :
      cost *= int(2 ** (32+32)) % d
      cost = cost % d
      temp_n -= 32
  
  #cost = (2 ** (N + N - 2) * (N-i+1)) * c
  res += cost
  if(res > d) :
    res = res%d
print(res % (d))

Submission status: Wrong Answer

Solution code:
N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()
d = 10**9+7
cost = 1
res = 0

temp_n = N
for i, c in enumerate(list_c) :
  #cost = (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))
  cost = 1

  while(True) :
    if(temp_n < 32) :
      cost *= int((2 ** (temp_n+temp_n-2) * (N-i+1)) * c) % d
      cost = cost % d
      break
    else :
      cost *= int(2 ** (32+32)) % d
      cost = cost % d
      temp_n -= 32
  
  #cost = (2 ** (N + N - 2) * (N-i+1)) * c
  res += cost
  if(res > d) :
    res = res%d
print(res % (d))

Submission status: Wrong Answer

Solution code:
N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()
d = 10**9+7
cost = 1
res = 0

temp_n = N
for i, c in enumerate(list_c) :
  #cost = (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))
  while(True) :
    cost = 1
    if(temp_n < 32) :
      cost *= int((2 ** (temp_n+temp_n-2) * (N-i+1)) * c) % d
      cost = cost % d
      break
    else :
      cost *= int(2 ** (32+32)) % d
      cost = cost % d
      temp_n -= 32
  
  #cost = (2 ** (N + N - 2) * (N-i+1)) * c
  res += cost
  if(res > d) :
    res = res%d
print(res % (d))

Submission status: Wrong Answer

Solution code:
N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()
d = 10**9+7
cost = 1
res = 0

temp_n = N
for i, c in enumerate(list_c) :
  #cost = (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))
  while(True) :
    cost = 1
    if(temp_n < 32) :
      cost *= int((2 ** (temp_n+temp_n-2) * (N-i+1)) * c) % d
      cost = cost % d
      break
    else :
      cost *= int((2 ** (32+32) * (N-i+1)) * c) % d
      cost = cost % d
      temp_n -= 32
  
  #cost = (2 ** (N + N - 2) * (N-i+1)) * c
  res += cost
  if(res > d) :
    res = res%d
print(res % (d))

Submission status: Wrong Answer

Solution code:
N = int(input())
list_c = list(map(int, input().split(" ")))
list_c.sort()
d = 10**9+7
cost = 1
res = 0

temp_n = N
for i, c in enumerate(list_c) :
  #cost = (2 ** (N+i)) * c * (2**(N-i-2) * (N-i-1) + (2**(N-i-1)))
  while(True) :
    cost = 1
    if(temp_n < 32) :
      cost *= int((2 ** (temp_n+temp_n-2) * (N-i+1)) * c) % d
      print(cost)
      cost = cost % d
      break
    else :
      cost *= int((2 ** (32+32) * (N-i+1)) * c) % d
      print(cost)
      cost = cost % d
      temp_n -= 32
  
  #cost = (2 ** (N + N - 2) * (N-i+1)) * c
  print(cost)
  res += cost
  if(res > d) :
    res = res%d
print(res % (d))