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: Time Limit Exceeded

Solution code:
MOD = 10**9+7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
cnt = 0
a, b = 2**(n-1), 0 if n <= 1 else 2**(n-2)
for i, x in enumerate(c):
    cnt += (a + b*i) * x

print(cnt * (2 ** n % MOD) % MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
cnt = 0
pt = [2**i for i in range(n+1)]

for i, x in enumerate(c):
    r = n-i-1
    cnt += (pt[i] + (0 if i <= 0 else pt[i-1]) * i) * pt[r] * x
    cnt %= MOD

print(cnt * (pt[n] % MOD) % MOD)

Submission status: Time Limit Exceeded

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

for i, x in enumerate(c):
    r = n-i-1
    cnt += (2**i + int(2**(i-1)) * i) * (2**r) * x
    cnt %= MOD

print(cnt * (2**n % MOD) % MOD)

Submission status: Time Limit Exceeded

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

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

mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod

ans=0

for i in range(N):
    l=i
    r=N-i-1
    keisu=N-i
    for k in range(1,keisu+1):
        ans+=2**l*ncr(r,k-1)*k*C[i]

print (ans*2**N)%mod

Submission status: Time Limit Exceeded

Solution code:
# 解説放送を見た
# https://youtu.be/9MphwmIsO7Q?t=5738

def main():
    mod = 10 ** 9 + 7

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

    c.sort()

    pw = [1 << j for j in range(n + 1)]

    ret = 0
    for l, x in enumerate(c):
        r = n - 1 - l  # lxr
        ret = (ret + x * pw[l] * (pw[r] + pw[r - 1] * r)) % mod

    ret = ret * pw[n] % mod

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
N = int(input())
C = list(map(int, input().split()))
C.sort()
MOD = 1000000007
ans = 0
if N == 1:
  ans = C[0]*2 % MOD
else:
  for i in range(N):
    for j in range(i,N):
      ans = (ans + 2**(i+N)*(N-j)*C[i]*factorial(N-i-1)//(factorial(N-j-1)*factorial(j-i))) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7


def modFact(n):
    global MOD
    if n == 1:
        return 1
    else:
        return (n * modFact(n - 1)) % MOD


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


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

mod2 = [0] * (N + 1)
mod2[0] = 1
x = 1
for i in range(N):
    mod2[i + 1] = x = (x * 2) % MOD

ans = 0
for i, c in enumerate(C):
    c %= MOD
    N_ = N - i - 1
    for j in range(0, N_ + 1):
        ans += mod2[N_] * mod2[i + 1] * mod2[i] * c * (j + 1) * modFacts[N_] * invs[N_ - j] * invs[j]
        ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
M=1000000007
N=int(input())
C=sorted(map(int,input().split()),reverse=True)
def pow(x,p):
  if(p==0):
    return 1;
  if(p%2):
    a=pow(x,p-1)%M;
    return x*a%M
  else:
    a=pow(x,p//2)%M
    return a*a%M
ans=0;
for k in range(N):
  ans=(ans+(C[k]*((pow(2,2*N-2)*k)%M+pow(2,2*N-1)))%M)%M
print(ans)

Submission status: Time Limit Exceeded

Solution code:
div = (10**9) + 7

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

c = sorted(c, reverse=True)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
print(dp[-1]*(2*p) % mod)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
print(dp[-1]*(2**n) % mod)

Submission status: Time Limit Exceeded

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
for i, c in enumerate(c_ls):
    res += (2 ** (n - 2) * (i + 2)) * c % MOD
    res %= MOD
res = res * (2 ** n) % MOD
print(int(res))

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

ans = 0

if N != 1:
    heapq.heapify(C)
    for i in range(N):
        c = heapq.heappop(C)
        ans += c * (N + 1 - i) * (2 ** (N - 2))
        ans %= 10 ** 9 + 7
    ans *= 2 ** N
else:
    ans = C[0] * 2

ans %= 10 ** 9 + 7

print(ans)

Submission status: Time Limit Exceeded

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
for i, c in enumerate(c_ls):
    res += (2 ** (n - 2) * (i+2)) * c % MOD
    res %= MOD
res = res * (2**n) % MOD
print(int(res))

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import factorial
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
for i, c in enumerate(c_ls):
    res += (2 ** (n - 1) + 2 ** (n - 2) * i) * c
    res %= MOD
res = res * (2**n) % MOD
print(int(res))

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import factorial
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
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(int(res))

Submission status: Time Limit Exceeded

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

C.sort()

ans = 0

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

ans %= 10 ** 9 + 7

print(ans)

Submission status: Time Limit Exceeded

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) % mod
    pattern += 2 ** (n-2)
    pattern %= mod
    ans %= mod

print(ans*(2**n) % mod)

Submission status: Time Limit Exceeded

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) % mod
    pattern += 2 ** (n-2)
    ans %= mod

print(ans*(2**n) % mod)

Submission status: Time Limit Exceeded

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 = sum([
  (c_i % 1000000007) * (((2 + i) * pow_k(2, 2 * n - 2)) % 1000000007 if n != 1 else 2) 
  for i, c_i 
  in enumerate(c)
]) % 1000000007 

print(ans)

Submission status: Time Limit Exceeded

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 if n != 1 else 2
  ans += c_i2 * p
  ans %= 1000000007

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
c=list(map(int,input().split()))
c.sort(reverse=1)
d=2**(n-2)
m=10**9+7
ans=0
k=1
for x in c:
  x=int(x%m)
  ans+=x*(k+1)*d
  ans%=m
  k+=1
ans=(int(ans)%m*(2**n))%m

print(int(ans))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import factorial
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)

res = 0
for i in range(n-1, -1, -1):
    hoge = sum([nCr(i, j) * j * 2 ** (n - i - 1) for j in range(1,i+1)])
    res += (2 ** (n - 1) + hoge) * c_ls[i]
    res %= MOD
res = res * (2**n) % MOD
print(res)

Submission status: Time Limit Exceeded

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()
heapq.heapify(clst)
res=0
q=2**(n-1)+(n-1)*2**(n-2)
for i in range(n):
  h=heapq.heappop(clst)
  res+=h*q
  q-=2**(n-2)
print(2**n*res % mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
c=list(map(int,input().split()))
c.sort(reverse=1)
d=2**(n-2)
m=10**9+7
ans=0
k=1
for x in c:
  ans+=x*(k+1)*d
  ans%=m
  k+=1
ans=(int(ans)%m*(2**n))%m

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
MOD=10**9+7

N=int(input())
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
for i in range(N):
  out+=(pow(2, N-1)+pow(2, N-2)*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))

Submission status: Time Limit Exceeded

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

k = [(c_i  * (pow_k(2, 2 * n - 1) + i * pow_k(2, 2 * n - 2))) % 1000000007 for i, c_i in enumerate(c)]
ans = 0
for k_i in k:
  ans += k_i
  ans %= 1000000007 
print(ans)

Submission status: Time Limit Exceeded

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

amari = 10**9+7

res = 0

for i in range(2 ** N):
    b = 1
    for j in range(N):
        if(i>>j) & 1:
            res += C[j] * b
            res %= amari
            b += 1

for i in range(N):
    res *= 2
    res %= amari

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

amari = 10**9+7

res = 0

for i in range(2 ** N):
    a = []
    for j in range(N):
        if(i>>j) & 1:
            a.append(j)

    b = len(a)

    for j in range(b):
        res += C[a[j]] * b
        res %= amari
        b -= 1

for i in range(N):
    res *= 2
    res %= amari

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
clist = list(map(int, input().split()))
clist=sorted(clist)
answer=0
kihon=2**(n-1)
tas=2**(n-2)
for i in range(n):
    answer+=clist[-i-1]*(kihon)
    kihon+=tas

answer=(answer*(2**n))%(10**9+7)
print(answer)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *C = map(int, read().split())

    C.sort()

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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,MOD)
  L.append(temp)
  
L.reverse()
ans = 0
for i in range(N):
  ans = (ans + L[i]*pow(2,i,MOD)*C[i])%MOD
#ans = ans%MOD
print(ans*pow(2,N,MOD)%MOD)

Submission status: Accepted

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はソートしておく，後ろから使う．

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

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

変更時のD：j+1

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

"""

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

  

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
*c,=map(int,input().split())
c=sorted(c)[::-1]
mod=10**9+7
ans=0
for i,x in enumerate(c,1):
  d=i*pow(2,i-1,mod)
  if i>1:d-=(i-1)*pow(2,i-2,mod)
  d*=pow(2,n-i,mod)*x%mod
  ans+=d%mod
  ans%=mod
ans*=pow(2,n,mod)
print(ans%mod)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
nmax = 2*10**5+1
mod = 10**9+7
fac = [1]*nmax
finv = [1]*nmax
inv = [1]*nmax
def ncr_pre():
    for i in range(2,nmax):
        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 ncr(n,r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fac[n]* (finv[r] * finv[n-r] %mod) %mod
n = ni()
C = lma();C.sort()
ans = 0
for i in range(1,n+1):
    c = C[i-1]
    ans += c*pow(4,i-1,mod)*pow(2,n-i,mod)*pow(2,n-i,mod)*(n-i+2)
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:

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

ans = 0
num = pow(2,n-1,MOD)
inc = pow(2,n-2,MOD)
for i in range(n):
    ans += num*cl[i]
    ans%=MOD
    num += inc
    num%=MOD

ans *= pow(2,n,MOD)
ans%=MOD
print(ans)

Submission status: Accepted

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

def main():
    n = int(input())
    c = list(map(int, input().split()))
    mod = pow(10, 9) + 7
    
    c.sort(reverse=True)
    
    ans = 0
    
    for i in range(n):
        ans += (i+2) * c[i]
        ans %= mod
    
    ans *= pow(2, n*2-2, mod)
    ans %= mod
    
    print(ans)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
M=10**9+7
N=int(input())
print(pow(4,N-1,M)*sum([C*(N-i+1)%M for i,C in enumerate(sorted(map(int,input().split())))])%M)

Submission status: Accepted

Solution code:
MOD=10**9+7
N=int(input())
C=sorted(map(int,input().split()))
p=pow(4,N-1,MOD)
ans=0

for i in range(N):
    res=p*C[i]*(N-i+1)
    ans=(ans+res)%MOD
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    cs = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    cs.sort()
    p2=[pow(2,i,mod) for i in range(N+1)]
    ans=0

    x=2*p2[N-1]**2%mod
    y=4*p2[N-2]**2%mod

    for i,c in enumerate(cs):
        if i<(N-1):
            ans+=y*c%mod*(N-1-i)
            ans%=mod
        ans+=x*c
        ans%=mod
    print(ans)
        


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

# 基本戦略:コストが一番高いものを一番最後に変更する
for i, c in enumerate(C):
    now = pow_list[N - i - 1]
    tot = 0
    # コストがi番目に大きい値は、最後からi番目に変更を行うので
    # 左からi-bitまでに何個1が立ったかで加算回数が決まる
    if i >= 1:
        tot = pow_list[i] + i * pow_list[i - 1]
    else:
        tot = pow_list[i]
    ans += (tot * now * c) % MOD
    ans %= MOD
print(ans * base % MOD)

Submission status: Accepted

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)

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

Submission status: Accepted

Solution code:
mod=10**9+7
def A001792(n):
  if n>1:
    return (n+1)*pow(2,n-2,mod)
  else:
    return 1

nn=int(input())
C=list(map(int, input().split()))
C.sort(reverse=True)
mod=10**9+7
ans=0
for i in range(nn):
  ans+=pow(2,nn-i-1,mod)*A001792(i+1)*C[i]
  ans %=mod
ans = ans*pow(2,nn,mod)
ans %=mod
print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7
n = int(input())
# frac = [1]*(n+1)
# finv = [1]*(n+1)
# for i in range(n):
#     frac[i+1] = (i+1)*frac[i]%mod
# finv[-1] = pow(frac[-1],mod-2,mod)
# for i in range(1,n+1):
#     finv[n-i] = finv[n-i+1]*(n-i+1)%mod
# def nCr(n,r):
#     if n<0 or r<0 or n<r: return 0
#     r = min(r,n-r)
#     return frac[n]*finv[n-r]*finv[r]%mod
C = list(map(int,input().split()))
C.sort(reverse = True)
ans = 0

for i,c in enumerate(C):
    ans += c*(i+2)
ans *= pow(4,n-1,mod)
print(ans%mod)

Submission status: Accepted

Solution code:
N = int(input())
C = sorted(map(int, input().split()))
mod = 10**9+7
# そのビットが異なる確率 * それ以上のビットが立っている数の期待値 * c
ans = 0
for i, c in enumerate(C[::-1], 2):
    ans += i * c
ans %= mod
ans = ans * pow(2, 2*N-2, mod) % mod
print(ans)

Submission status: Accepted

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

mod = 1000000007

ret = 0
for i in range(n):
    ret = (ret + (i + 2) * c[n - i - 1]) % mod

for i in range(n - 1):
    ret = (ret * 4) % mod

print(ret)

Submission status: Accepted

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*pow(4,k,MOD)*c + 4*dp2
        dp1 = 4*dp1 + ndp2 - 2*dp2
        dp2 = ndp2
        dp1 %= MOD
        dp2 %= MOD

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

Solution code:
MOD = 10**9+7
N = int(input())
C = list(map(int, input().split()))
C.sort(reverse=True)
print((pow(4,N-1,MOD)*sum((i+2)*C[i] for i in range(N)))%MOD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 各々の要素が何番目に何回数えられるかを考える。
import sys

input = sys.stdin.buffer.readline

n = int(input())
C = list(map(int, input().split()))
C.sort(reverse=True)
mod = 10 ** 9 + 7
N = n + 5
bikkuri = [0] * N
bikkuri[0] = 1
gyaku = [0] * N
for i in range(1, N):
    bikkuri[i] = (i * bikkuri[i - 1]) % mod
gyaku[N - 1] = pow(bikkuri[N - 1], mod - 2, mod)
for i in range(N - 1, -1, -1):
    gyaku[i - 1] = (gyaku[i] * i) % mod


def comb(n, r):
    if r < 0 or n - r < 0:
        return 0
    return (bikkuri[n] * gyaku[r] * gyaku[n - r]) % mod


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

Submission status: Accepted

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-i-1
    ans+=(p[x]+x*p[x-1])*c[i]*p[i]
    ans%=mod
print(ans*p[n]%mod)

Submission status: Accepted

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

B = [0 for _ in range(N+1)]#2べきmod
B[0] = 1
for i in range(1,N+1):
  B[i] = B[i-1] * 2
  B[i] %= MOD  

C.sort()

ans = 0
for n in range(1,N+1):
  ans += C[n-1] * ((N-n) * B[N-n-1] + B[N-n]) * B[n-1]
  ans %=  MOD
  
ans *= B[N]
ans %= MOD

print(ans)

"""
D = [0 for _ in range(N)]#累積和
D[0] = C[0]
for i in range(1,N):
  D[i] = D[i-1] + C[i]
print(C)

  
ans = 0
for j in range(1,N+1):
  ans += D[j-1] * B[j-1]  
  print(D[j-1] * B[j-1]  
  
"""