Buggy python submission (verdict: Runtime Error):
# 各々の要素が何番目に何回数えられるかを考える。
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, n - 2, mod)
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Fixed submission:
# 各々の要素が何番目に何回数えられるかを考える。
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)

Buggy python submission (verdict: Runtime Error):
# 各々の要素が何番目に何回数えられるかを考える。
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 += pow(2, i - 1, mod) * (i + 2) * C[i] * pow(2, n - (i + 1), mod)
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Fixed submission:
# 各々の要素が何番目に何回数えられるかを考える。
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)

Buggy python submission (verdict: Runtime Error):
# 各々の要素が何番目に何回数えられるかを考える。
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, 0, -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 += pow(2, i - 1, mod) * (i + 2) * C[i] * pow(2, n - (i + 1), mod)
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Fixed submission:
# 各々の要素が何番目に何回数えられるかを考える。
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)

Buggy python submission (verdict: Runtime Error):
# 各々の要素が何番目に何回数えられるかを考える。
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, 0, -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 += pow(2, i - 1, mod) * (i + 2) * C[i] * pow(2, n - (i + 1), mod)
    ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Fixed submission:
# 各々の要素が何番目に何回数えられるかを考える。
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)

Buggy python submission (verdict: Time Limit Exceeded):
# 各々の要素が何番目に何回数えられるかを考える。
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, 0, -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):
    for a in range(i + 1):
        ans += comb(i, a) * (a + 1) * C[i] * pow(2, n - (i + 1), mod)
        ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Fixed submission:
# 各々の要素が何番目に何回数えられるかを考える。
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)

Buggy python submission (verdict: Time Limit Exceeded):
# 各々の要素が何番目に何回数えられるかを考える。
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, 0, -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):
    for k in range(n + 1):
        for a in range(i + 1):
            ans += comb(i, a) * (a + 1) * C[i] * comb(n - (i + 1), k - (a + 1))
            ans %= mod
ans *= pow(2, n, mod)
ans %= mod
print(ans)


Fixed submission:
# 各々の要素が何番目に何回数えられるかを考える。
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)