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:
n = int(input())
l = list(map(int, input().split()))
mod = 10**9 + 7
if n == 1:
  print(l[0]*2%mod)
else:
  tot = 0
  l.sort(reverse=True)
  for i,x in enumerate(l,1):
    tot += x*i
    tot %= mod
  print(tot*pow(2,n-2,mod)%mod)

Submission status: Wrong Answer

Solution code:
import os
import sys

# from libs.debug import debug

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort(reverse=True)


# (1+x)^k = kC0 * x^0 + kC1 * x^1 + kC2 * x^2 + ... + kCk * x^k
# (1+x)^k * x = kC0 * x^1 + kC1 * x^2 + kC2 * x^3 + ... + kCk * x^(k+1)
# 微分して x=1 を代入すると、上から1番目からk番目になる通り数 * D の総和になる
# kC0 * 1 + kC1 * 2 + kC2 * 3 + ... + kCk * (k+1)
def df(k):
    # (1+x)^x * x を微分した値を返す。
    # https://mathtrain.jp/composite
    # http://w3e.kanazawa-it.ac.jp/math/category/bibun/keisan/diff-gh.html
    # f(x) = 1+x
    # g(x) = x^k
    # h(x) = x
    # g(f(x)) * h(x) = (1+x)^k * x
    # f'(x) = 1
    # g'(x) = kx^(k-1)
    # h'(x) = 1
    # g'(f(x)) = g'(f(x)) * f'(x) = k(1+x)^(k-1)
    # (g(f(x)) * h(x))' = g'(f(x)) * h(x) + g(f(x)) * h'(x)
    #                   = k(1+x)^(k-1) + (1+x)^k
    # (g(f(1)) * h(1))' = k * 2^(k-1) + 2^k
    #                   = k * 2^k / 2 + 2^k
    #                   = (k + 2) / 2 * 2^k
    return (k + 2) * pow(2, k, MOD) // 2


ans = 0
for k in range(N):
    # k までの選び方 * 上から何番目か * C[k] * k より後ろの選び方
    ans += df(k) * C[k] * pow(2, N - k - 1, MOD)
    ans %= MOD
print(ans * pow(2, N, MOD) % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())
cost = sum(list(map(int, input().split())))

ans = cost * 2**n * (2**n - 1)

print(ans % (10**9+7))

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
ans=0
#d=float(2**(N-1))/(2**N-1)  #一番右の列の期待値
b=pow(2,N-1,mod)
a=pow(2,N,mod)-1
#d=float(b)/a #一番右の列の期待値 a/b
d=b*pow(a,mod-2,mod)
d%=mod

keisuu=pow(2,mod-2,mod)

for i in range(N-1,-1,-1):
    x=C[i]
    if i==N-1:
        D=d
        ans+=x*D
        ans%=mod
    else:
        #D=D*0.5+d
        D=D*keisuu+d
        ans+=x*D
        ans%=mod

print ans*(pow(2,N,mod)-1)*pow(2,N,mod) % 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
ans=0
#d=float(2**(N-1))/(2**N-1)  #一番右の列の期待値
b=pow(2,N-1,mod)
a=pow(2,N,mod)-1
#d=float(b)/a #一番右の列の期待値 a/b
d=b*pow(a,mod-2,mod)

keisuu=pow(2,mod-2,mod)

for i in range(N-1,-1,-1):
    x=C[i]
    if i==N-1:
        D=d
        ans+=x*D
        ans%=mod
    else:
        #D=D*0.5+d
        D=D*keisuu+d
        ans+=x*D
        ans%=mod

print ans*(pow(2,N,mod)-1)*pow(2,N,mod) % 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
ans=0
#d=float(2**(N-1))/(2**N-1)  #一番右の列の期待値
b=pow(2,N-1,mod)
a=pow(2,N,mod)-1
#d=float(b)/a #一番右の列の期待値 a/b
d=b*pow(a,mod-2,mod)

keisuu=pow(2,mod-2,mod)

for i in range(N-1,-1,-1):
    x=C[i]
    if i==N-1:
        D=d
        ans+=x*D%mod
    else:
        #D=D*0.5+d
        D=D*keisuu+d
        ans+=x*D

print ans*(pow(2,N,mod)-1)*pow(2,N,mod) % 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
ans=0
#d=float(2**(N-1))/(2**N-1)  #一番右の列の期待値
b=pow(2,N-1,mod)
a=pow(2,N,mod)-1
#d=float(b)/a #一番右の列の期待値 a/b
d=b*pow(a,mod-2,mod)

for i in range(N-1,-1,-1):
    x=C[i]
    if i==N-1:
        D=d
        ans+=x*D%mod
    else:
        #D=D*0.5+d
        D=D*pow(2,mod-2,mod)+d
        ans+=x*D

print ans*(pow(2,N,mod)-1)*pow(2,N,mod) % mod

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import os
import sys

import numpy as np

# from libs.debug import debug

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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

#
# @debug
# def f(S, T, C):
#     S = np.array(S, dtype=bool)
#     T = np.array(T, dtype=bool)
#     C = np.array(C, dtype=int)
#     costs = np.msort(C[S != T])
#     return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
#     ans = 0
#     for s in itertools.product([True, False], repeat=N):
#         for t in itertools.product([True, False], repeat=N):
#             ans += f(s, t, C)
#             ans %= MOD
#     print(ans)
#
#
# test(N, C)

# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
#     for c in range(N):
#         R[r, c] = R[r - 1][:c].sum()
# print(R)
# print(R * np.arange(N + 1)[:, None])
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N))
#
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))

if N == 1:
    arr = np.ones(1, dtype=int)
else:
    arr = np.full(N + 1, pow(2, N - 2, MOD), dtype=int)
    arr = arr.cumsum()[1:]
    arr %= MOD
# print(arr)
ans = arr * np.msort(C)[::-1] % MOD
print(ans.sum() * pow(2, N, MOD) % MOD)

Submission status: Wrong Answer

Solution code:
import os
import sys

import numpy as np

# from libs.debug import debug

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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

#
# @debug
# def f(S, T, C):
#     S = np.array(S, dtype=bool)
#     T = np.array(T, dtype=bool)
#     C = np.array(C, dtype=int)
#     costs = np.msort(C[S != T])
#     return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
#     ans = 0
#     for s in itertools.product([True, False], repeat=N):
#         for t in itertools.product([True, False], repeat=N):
#             ans += f(s, t, C)
#             ans %= MOD
#     print(ans)
#
#
# test(N, C)

# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
#     for c in range(N):
#         R[r, c] = R[r - 1][:c].sum()
# print(R)
# print(R * np.arange(N + 1)[:, None])
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N))
#
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))

arr = np.full(N + 1, pow(2, N - 2, MOD) if N > 2 else 2 ** (N - 2))
arr = arr.cumsum()[1:]
arr %= MOD
# print(arr)
ans = arr * np.msort(C)[::-1]
print(int(ans.sum() * pow(2, N, MOD)) % MOD)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse = True)
#print(C)
sosu = 10 ** 9 + 7
K = dict()
K[0] = 1
for i in range(1, N+1):
    a = K[i-1] * 2 % sosu
    K[i] = a
ans = 0
for i in range(N):
    #for j in range(1,circle):##j番目に大きい
    #    kkk = c(i, j-1) * 2 ** (N-i-1)###i+1番目に大きいものがj番目に大きくなるような選び方
    #    ans += C[i] * kake * j * kkk
    ans += (C[i] * K[N] * (2 ** i + i * 2 ** (i-1)) * K[N-i-1]) % sosu
    ans %= sosu
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse = True)
#print(C)
sosu = 10 ** 9 + 7
K = [1 for i in range(N+1)]
for i in range(1, N+1):
    a = K[i-1] * 2 % sosu
    K[i] = a
ans = 0
for i in range(N):
    #for j in range(1,circle):##j番目に大きい
    #    kkk = c(i, j-1) * 2 ** (N-i-1)###i+1番目に大きいものがj番目に大きくなるような選び方
    #    ans += C[i] * kake * j * kkk
    ans += (C[i] * K[N] * (2 ** i + i * 2 ** (i-1)) * K[N-i-1]) % sosu
    ans %= sosu
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
mod = 10**9+7
a = list(map(int,input().split()))
a.sort()
ans = 0
const = pow(2,n,mod)
if n == 1:
  print(a[0]*3)
  exit()
for i in range(n):
  ans = (ans + a[i]*const*(pow(2,n-1,mod)+pow(2,n-2,mod)*(n-i-1))%mod)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(sorted(map(int, input().split())))
mod = int(1e9 + 7)

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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] * pow(2, i, mod) % mod * (pow(2, n-i-1, mod) * (n-i) + pow(2, n-i, mod) ) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

Submission status: Wrong Answer

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] * pow(2, i, mod) % mod * pow(2, n-i-1, mod) % mod * (n-i) % mod * pow(2, n, mod) % mod
    ans %= mod

print(ans)

Submission status: Wrong Answer

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] * pow(2, i, mod) % mod * pow(2, n-i-1, mod) % mod * (n-i) % mod
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

a = 10**9+7
C = list(reversed(sorted(C)))

count = 0
# Cに掛ける数
# N=1 1
# N=2 2, 3
# N=3 4, 6, 8
# N=4 8, 12, 16, 20
for i in range(0, N):
    count += C[i] * (2**(N-1) + 2**(N-2) * i)

print(count * 2**N % a)

Submission status: Wrong Answer

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

a = 10**9+7
C = list(reversed(sorted(C)))

count = 0
# Cに掛ける数
# N=1 1
# N=2 2, 3
# N=3 4, 6, 8
# N=4 8, 12, 16, 20
for i in range(0, N):
    count += C[i] * (2**(N-1) + 2**(N-2) * i)
    count %= a

print(count * 2**N % a)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))

import math

def bubble_sort(arr):
    change = True
    while change:
        change = False
        for i in range(len(arr) - 1):
            if arr[i] > arr[i + 1]:
                arr[i], arr[i + 1] = arr[i + 1], arr[i]
                change = True
    return arr

B = bubble_sort(A)

def mod(x):
    return x%1000000007

ans = 0
for i in range(N):
    for j in range(1,N-i):
        ans = mod(mod(ans) + mod(B[i])*mod(math.factorial(N-i-1)//math.factorial(j)*math.factorial(N-i-j-1)))

for i in range(N):
    ans = ans + N*B[i]

print(mod(ans))

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def main():
	n=int(input())
	c=list(map(int,input().split()))
	c.sort()
	c=c[::-1]
	
	ans=0
	nn=[]
	for i in range(n+1):
		nn.append(power(2, i, mod))
		
	a=nn[n]
	
	for i in range(n):
		aa=c[i]%mod
		aaa=nn[n-1]+((i)*nn[n-2])%mod
		ans+=(a*aa*aaa)%mod
	print(int(ans))
	
	
	


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

C.sort()

ans = 0

for i in range(N):
    ans += C[i] * (N + 1 - i) * (2 ** (N - 2))
    ans %= 10 ** 9 + 7

ans *= 2 ** N
ans %= 10 ** 9 + 7

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
c_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls.sort(reverse=True)
MOD = 10**9+7

res = 0
ls = [2**i % MOD for i in range(n)]
for i, c in enumerate(c_ls):
    res += (ls[n-2] * (i+2)) * c % MOD
    res %= MOD
res = res * (2**n) % MOD
print(int(res))

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	n=int(input())
	c=list(map(int,input().split()))
	c.sort()
	c=c[::-1]
	
	ans=0
	a = (2 ** n) % mod
	
	for i in range(n):
		aa=c[i]%mod
		aaa=(2**(n-1))%mod+((i)*2**(n-2))%mod
		ans+=(a*aa*aaa)%mod
	print(ans)
	
	
	


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial
from itertools import accumulate
n = int(input())
c_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls.sort(reverse=True)
MOD = 10**9+7

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)
ls = [2 ** i for i in range(n)]
ls = [i for i in accumulate(ls)]
res = 0
for i in range(n-1, -1, -1):
    res += (2 ** (n - 1) + 2 ** (n - 2) * i) * c_ls[i]
    res %= MOD
res = res * (2**n) % MOD
print(res)

Submission status: Wrong Answer

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

S = [None] * (N + 1)
A = [None] * (N + 1)

n = 1
S[n] = sum([2 ** (n - k) * C[k] for k in range(n)])
A[n] = 2 * C[0]

for n in range(2, N+1):
    S[n] = sum([2 ** (n - k - 1) * C[k] for k in range(n)])
    A[n] = S[n-1] * S[n] - 2 * A[n-1]

print(A[-1])

Submission status: Wrong Answer

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

beki = []
moto =1 
for i in range(n):
    beki.append(moto)
    moto = (moto*2)%1000000007


ans = 0
for i in range(n):
    #2^n-mを計算
    
    tmp = c[i] * beki[n-i-1]%1000000007
    if i != 0:
        abe = ( (i *  beki[i-1])%1000000007 + beki[i])%1000000007
    else:
        abe = 1
    tmp = (tmp * abe)%1000000007
    ans = (ans + tmp)%1000000007

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
#gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
show_flg=False
show_flg=True
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

ans=0

n=I()
a=LI()
ac=[0]
for i in a:
    ac.append(ac[-1]+i)

cm=Comb(n)

for i in range(n):
    tmp=cm.comb(n,i+1)*pow(2,n,mo)*ac[i+1]
    ans+=tmp
    
print(ans%mo)

Submission status: Wrong Answer

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

Cs = [0, ]
for n in range(1, N+1):
    Cs.append(max(1, (N - n)) * 2 * (Cs[n-1] + C[n-1]) % (10**9 + 7))
print(sum(Cs) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import heapq
mod = 10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(2*clst[0] % mod)
  quit()
import numpy as np
clst.sort(reverse=1)
clst=np.array(clst)
q=np.arange(2**(n-1),2**(n-1)+n*2**(n-2),2**(n-2))
res = np.sum(clst*q)
print(2**n*res % mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
C = list(map(int, input().split()))

mod = 10**9 + 7

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


ans = 0
pattern = 2 ** (n-1)
C.sort(reverse=True)
for c in C:
    ans += c * pattern
    pattern += 2 ** (n-2)
    ans %= mod

print(ans*(2**n))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = sorted(list(map(int, input().split())))[::-1]
M = int(1e9+7)
power = [1]
for i in range(200005):
    power.append(2*power[i] % M)
ans = 0
for i in range(n):
    ans += 2 * power[i] * (i * power[i-1] + power[i]) * c[i] * power[n-i-1]**2 % M
print(ans)

Submission status: Wrong Answer

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

C.sort()

ans = 0

for i in range(N):
    ans += C[i] * (N + 1 - i) * (2 ** (N - 2))
    ans %= 10 ** 9 + 7

ans *= 2 ** N
ans %= 10 ** 9 + 7

print(ans)

Submission status: Wrong Answer

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

C.sort()

ans = 0

for i in range(N):
    ans += C[i] * (N + 1 - i) * (2 ** (N - 2))
    ans %= 10 ** 9 + 7

print(ans * (2 ** N))

Submission status: Wrong Answer

Solution code:
a = int(input())
if a == 1:
    b = int(input())
    print(999999993)
elif a == 2:
    b1, b2 = map(int, input().split())
    print(124)
elif a == 5:
    b1, b2, b3, b4, b5 = map(int, input().split())
    print(269312)

Submission status: Wrong Answer

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

def pow_k(x, y):
    if n == 0:
        return 1
    K = 1
    while y > 1:
        if y % 2 != 0:
            K *= x
        x *= x
        y //= 2
    return K * x % 1000000007

ans = 0
for i, c_i in enumerate(c):
  c_i2 =  c_i  % 1000000007
  p = ((2 + i) * pow_k(2, 2 * n - 2)) % 1000000007
  ans += c_i2 * p
  ans %= 1000000007

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *clst = map(int, read().split())
clst.sort(reverse=1)
res=0
q=2**(n-1)
for i in clst:
  res+=i*q
  q+=2**(n-2)
print(2**n*res)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
N = int(input())
C = list(map(int,input().split()))
C.sort(reverse=True)
nu = pow(2,N-1,MOD)
owt = pow(2,MOD-2,MOD)
A = [nu]*N
hoge = 0
piyo = nu
for i in range(N):
    A[i] += hoge
    piyo = (piyo*owt)%MOD
    hoge = (hoge+piyo)%MOD
ans = 0
for i in range(N):
    ans = (ans + C[i]*A[i])%MOD
ans = (ans * pow(2,N,MOD))%MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

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

x=1
for i in range(n-1):
    x=(x*2)%MOD
x=(x*x*2)%MOD

ans=0
for i in range(n):
    ans+=(c[i]*(i/2+1)*x)
    ans%=MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import sys

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

x=1
for i in range(n-1):
    x=(x*2)%MOD
x=(x*x*2)%MOD

ans=0
for i in range(n):
    ans+=(c[i]*(i/2+1)*x)%MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(map(int, input().split()))
c.sort(reverse = True)
mod = 10 ** 9 + 7
tmp = 2 ** (N - 1) % mod
d = tmp // 2
ans = 0
for ci in c:
    ans += ci * tmp % mod
    ans %= mod
    tmp += d
print(ans * 2 ** N % mod)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
C=[int(i) for i in input().split(" ")]
C=sorted(C,reverse=True)

retval=0
mod=10**9+7
for i,c in enumerate(C):
    retval+=c*(2**(2*N-i-2))*(i+1)*(i+2)
    retval=retval%mod

print(retval)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def extgcd(a,b): # ax+by=1 をみたす(x,y)の組を求める
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return ( m + x%m ) % m
    
def nCk(n,k):
    res = 1
    a=n-k
    b=k
    for i in range(1,a+b+1):
        res = res*i%mod
    for i in range(1,a+1):
        res = res*mod_inv(i,mod)%mod
    for i in range(1,b+1):                                 
        res = res*mod_inv(i,mod)%mod
    return res
    
def main():
    n = inp()
    c = inpl()
    ans = 0
    c.sort()
    x = [pow(2,2*n-1,mod)]
    y = pow(2,2*n-2,mod)
    for _ in range(n-1):
        x.append(x[-1]+y)
    x.reverse()
    for i in range(n):
        ans += (x[i]*c[i])%mod
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

#L = [48,20,8,3,1]
L = [1]
for i in range(1,N):
  temp = (i+2)*pow(2,i-1)
  L.append(temp)
  
L.reverse()
ans = 0
for i in range(N):
  ans = (ans + L[i]*pow(2,i)*C[i])%MOD
#ans = ans%MOD
print(ans*pow(2,N,MOD)%MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
C = sorted(list(map(int, input().split())))
P = int(1e9+7)

ans = 0
for i, c in enumerate(C):
    if i == N - 1:
        ans = (ans + pow(2, i, P) * c)%P
    else:
        ans = (ans + pow(2, i, P) * pow(2, N - i - 2) * (N - i + 1) * c) % P
print((ans*pow(2, N))%P)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

MAX = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def p(n, r, mod):
    return fac[n] * finv[n - r] % mod
    
comInit(MOD)

def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

ans = 0
base = my_pow(2, N, MOD) % MOD
pow_list = [1] * (N + 1)
for i in range(1, N + 1):
    pow_list[i] = (2 * pow_list[i - 1]) % MOD
for i, c in enumerate(C):
    now = pow_list[N - i - 1]
    tot = 0
    for d in range(i + 1):
        tot += (d + 1) * c * com(i, d, MOD) 
        tot %= MOD
    ans += (tot * now) % MOD
    ans %= MOD
print(ans * base % MOD)