Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from math import ceil

# 位置xにあるゴミをi番目に拾うときの、追加コスト
def E(i, x):
    if i > 2:
        return (2 * i + 1) * x
    else:
        return 5 * x

N, X = map(int, input().split())
xs = list(map(int, input().split()))

accXs = [0] + list(accumulate(reversed(xs)))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X
    for i in range(1, ceil(N / k) + 1):
        # i番目に拾うゴミについて、まとめて計算する
        cost += E(i, accXs[min(N, i * k)] - accXs[(i - 1) * k])
    ans = min(ans, cost)

print(ans)


Fixed submission:
from itertools import accumulate
from math import ceil

N, X = map(int, input().split())
xs = list(map(int, input().split()))

accXs = [0] + list(accumulate(reversed(xs)))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X

    # i番目に拾うゴミについて、追加コストをまとめて計算する
    cost += 5 * (accXs[k] - accXs[0])

    m = ceil(N / k)
    for i in range(2, m):
        cost += (2 * i + 1) * (accXs[i * k] - accXs[(i - 1) * k])

    cost += (2 * m + 1) * (accXs[N] - accXs[(m - 1) * k])

    ans = min(ans, cost)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil

# 位置xにあるゴミをi番目に拾うときの、追加コスト
def E(i, x):
    if i > 2:
        return (2 * i + 1) * x
    else:
        return 5 * x

N, X = map(int, input().split())
xs = list(map(int, input().split()))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X
    for i, x in enumerate(reversed(xs), 1):
        # 1台あたりのゴミ数は、できるだけ少なくしたい
        cost += E(ceil(i / k), x)
    ans = min(ans, cost)

print(ans)


Fixed submission:
from itertools import accumulate
from math import ceil

N, X = map(int, input().split())
xs = list(map(int, input().split()))

accXs = [0] + list(accumulate(reversed(xs)))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X

    # i番目に拾うゴミについて、追加コストをまとめて計算する
    cost += 5 * (accXs[k] - accXs[0])

    m = ceil(N / k)
    for i in range(2, m):
        cost += (2 * i + 1) * (accXs[i * k] - accXs[(i - 1) * k])

    cost += (2 * m + 1) * (accXs[N] - accXs[(m - 1) * k])

    ans = min(ans, cost)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil

INF = float('inf')

def minAB(x, y):
    return x if x <= y else y


N, X = map(int, input().split())
xs = list(map(int, input().split()))

maxGs = [ceil(X / (2 * x)) for x in xs]

cost0 = 5 * sum(xs) + 2 * N * X

dp2 = {(1, tuple([0, 1] + [0] * (N - 1))): cost0}
for x, maxG in zip(reversed(xs[:-1]), reversed(maxGs[:-1])):
    dp1 = {}
    for (iMin, nums), cost in dp2.items():
        # 帰り道に便乗しない場合
        num2s = list(nums)
        num2s[1] += 1
        num2s = tuple(num2s)
        dp1[(1, num2s)] = minAB(dp1.get((1, num2s), INF), cost)

        # 帰り道に便乗する場合
        if iMin <= maxG:
            iMin0 = iMin
            nums = list(nums)
            nums[iMin] -= 1
            nums[iMin + 1] += 1
            nums = tuple(nums)
            if nums[iMin] == 0:
                iMin += 1
            dp1[(iMin, nums)] = minAB(dp1.get((iMin, nums), INF), cost - X + (2 * iMin0 - 2) * x)

    dp2 = dp1

print(min(dp2.values()))


Fixed submission:
from itertools import accumulate
from math import ceil

N, X = map(int, input().split())
xs = list(map(int, input().split()))

accXs = [0] + list(accumulate(reversed(xs)))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X

    # i番目に拾うゴミについて、追加コストをまとめて計算する
    cost += 5 * (accXs[k] - accXs[0])

    m = ceil(N / k)
    for i in range(2, m):
        cost += (2 * i + 1) * (accXs[i * k] - accXs[(i - 1) * k])

    cost += (2 * m + 1) * (accXs[N] - accXs[(m - 1) * k])

    ans = min(ans, cost)

print(ans)