import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

solve :: Int -> Int -> [Int] -> Int
solve n bigX xs = cost n bigX rs d0
  where
    rs = reverse xs
    d0 = if n <= 2 then 1
         else if cost n bigX rs 1 < cost n bigX rs 2 then 1
              else search n bigX rs 1 (n-1)

cost :: Int -> Int -> [Int] -> Int -> Int
cost n bigX rs d = bigX * (n + d)
                   + (sum $ zipWith (*) (5 : [5,7..]) (gsumA d n rs))

-- gsum d rs = gsumA d (length rs) rs

gsumA :: Int -> Int -> [Int] -> [Int]
gsumA d k rs | k <= d = [sum rs]
             | otherwise = (sum rs1) : gsumA d (k-d) rs2
  where (rs1, rs2) = splitAt d rs

search :: Int -> Int -> [Int] -> Int -> Int -> Int
search n bigX rs low high
  | high == low + 1 = high
  | theCost mid < theCost (mid+1) = search n bigX rs low mid
  | otherwise                     = search n bigX rs mid high
  where
    theCost d = cost n bigX rs d
    mid = (low + high) `div` 2

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

tmain :: B.ByteString -> Int
tmain cont =
  let n : bigx : xs = bsReadInts cont
  in solve n bigx xs

main = putStrLn . show . tmain =<< B.getContents
