main = do
  [_,e] <- map read . words <$> getLine
  xs <- reverse . map read . words <$> getLine
  print $ start e xs
  
start e []     = 0
start e (x:xs) = x + e + select e 1 x xs


select e k pos [] = pos * (k + 1) ^ 2 + e
select e k pos (x:xs) = min suteniiku sutenai
  where
    suteniiku = select e k pos [] + start e (x:xs)
    sutenai = (pos - x) * (k + 1) ^ 2 + e + select e (k+1) x xs  