Buggy python submission (verdict: Time Limit Exceeded):
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

D = [pow(i, 2) for i in range(1, N + 2)]

ok = N
ng = 1
List = [-1 for i in range(N + 1)]
while abs(ok - ng) > 2:
  LR = [(ok - ng) // 3 + ng, 2 * (ok - ng) // 3 + ng]
  Ans = [0, 0]
  for j in range(2):
    if List[LR[j]] != -1:
      Ans[j] = List[LR[j]]
      continue
    least = 0
    Ans[j] = X * (N + LR[j])
    cnt = -1
    t = 0
    flag = False
    for i in x[::-1]:
      if flag:
        Ans[j] += (D[least + 1] - D[least]) * x[cnt]    
      else:
        Ans[j] += (D[0] + D[1]) * x[cnt]
      cnt -= 1
      t += 1
      if t == LR[j]:
        t = 0
        least += 1
        flag = True
    List[LR[j]] = Ans[j]
  if Ans[0] < Ans[1]:
    ok = LR[1]
  else:
    ng = LR[0]
 
FA = 1e20
for j in range(ng, ok + 1):
  if List[j] != -1:
    FA = min(FA, List[j])
    continue
  least = 0
  Ans = X * (N + j)
  cnt = -1
  t = 0
  flag = False
  for i in x[::-1]:
    if flag:
      Ans += (D[least + 1] - D[least]) * x[cnt]    
    else:
      Ans += (D[0] + D[1]) * x[cnt]
    cnt -= 1
    t += 1
    if t == j:
      t = 0
      least += 1
      flag = True
  FA = min(FA, Ans)
print(FA)

Fixed submission:
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

D = [pow(i, 2) for i in range(1, N + 2)]

ok = N
ng = 1
List = [-1 for i in range(N + 1)]
while abs(ok - ng) > 2:
  LR = [(ok - ng) // 3 + ng, 2 * (ok - ng) // 3 + ng]
  Ans = [0, 0]
  for j in range(2):
    if List[LR[j]] != -1:
      Ans[j] = List[LR[j]]
      continue
    least = 0
    Ans[j] = X * (N + LR[j])
    cnt = -1
    t = 0
    flag = False
    for i in x[::-1]:
      if flag:
        Ans[j] += (D[least + 1] - D[least]) * x[cnt]    
      else:
        Ans[j] += (D[0] + D[1]) * x[cnt]
      cnt -= 1
      t += 1
      if t == LR[j]:
        t = 0
        least += 1
        flag = True
    List[LR[j]] = Ans[j]
  if Ans[0] < Ans[1]:
    ok = LR[1]
  else:
    ng = LR[0]
 
FA = 1e20
for j in range(ng, ok + 1):
  if List[j] != -1:
    FA = min(FA, List[j])
    continue
  least = 0
  Ans = X * (N + j)
  cnt = -1
  t = 0
  flag = False
  for i in x[::-1]:
    if flag:
      Ans += (D[least + 1] - D[least]) * x[cnt]    
    else:
      Ans += (D[0] + D[1]) * x[cnt]
    cnt -= 1
    t += 1
    if t == j:
      t = 0
      least += 1
      flag = True
  FA = min(FA, Ans)
print(FA)

Buggy python submission (verdict: Time Limit Exceeded):
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

D = [pow(i, 2) for i in range(1, N + 2)]
L = [0] * N
DL = [0] * (N + 1)
t = 2
for i in range(N - 1, -1, -1):
  for j in range(t, N + 1):
    if (D[j] - D[j - 1] - 5) * x[i] > X:
      break
    t = j
  L[i] = t
  DL[t] += 1

least = 1
AD = [0] * (N + 1)

getNum = 0
for i in range(L[-1], N + 1):
  if DL[i] == 0:
    continue
  t = DL[i]
  for j in range(least, i):
    t -= (i - j) * AD[j]
    if t <= 0:
      break
  for j in range(DL[i]):
    if t >= 1:
      t -= i
      AD[1] += 1
      getNum += 1
    else:
      AD[least] -= 1
      AD[least + 1] += 1
      if AD[least] == 0:
        least += 1
FA = 1e20
for j in range(getNum, N + 1):
  least = 0
  Ans = X * (N + j)
  cnt = -1
  t = 0
  flag = False
  for i in x[::-1]:
    if flag:
      Ans += (D[least + 1] - D[least]) * x[cnt]    
    else:
      Ans += (D[0] + D[1]) * x[cnt]
    cnt -= 1
    t += 1
    if t == j:
      t = 0
      least += 1
      flag = True
    if Ans >= FA:
      break
  else:
    FA = Ans
    continue
print(FA)


Fixed submission:
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

D = [pow(i, 2) for i in range(1, N + 2)]

ok = N
ng = 1
List = [-1 for i in range(N + 1)]
while abs(ok - ng) > 2:
  LR = [(ok - ng) // 3 + ng, 2 * (ok - ng) // 3 + ng]
  Ans = [0, 0]
  for j in range(2):
    if List[LR[j]] != -1:
      Ans[j] = List[LR[j]]
      continue
    least = 0
    Ans[j] = X * (N + LR[j])
    cnt = -1
    t = 0
    flag = False
    for i in x[::-1]:
      if flag:
        Ans[j] += (D[least + 1] - D[least]) * x[cnt]    
      else:
        Ans[j] += (D[0] + D[1]) * x[cnt]
      cnt -= 1
      t += 1
      if t == LR[j]:
        t = 0
        least += 1
        flag = True
    List[LR[j]] = Ans[j]
  if Ans[0] < Ans[1]:
    ok = LR[1]
  else:
    ng = LR[0]
 
FA = 1e20
for j in range(ng, ok + 1):
  if List[j] != -1:
    FA = min(FA, List[j])
    continue
  least = 0
  Ans = X * (N + j)
  cnt = -1
  t = 0
  flag = False
  for i in x[::-1]:
    if flag:
      Ans += (D[least + 1] - D[least]) * x[cnt]    
    else:
      Ans += (D[0] + D[1]) * x[cnt]
    cnt -= 1
    t += 1
    if t == j:
      t = 0
      least += 1
      flag = True
  FA = min(FA, Ans)
print(FA)