main = do
  (n:t:xs) <- map read . words <$> getLine
  ps <- map read . words <$> getLine
  putStrLn . show $ solve ps t



solve ps k =
  let bins = binPlus ps
      len = length ps
      startd = 2 ^ (length bins - 1)
      bink = reverse $ intToBin k
      startk = 2 ^ (length bink - 1)
  in if k == 0 then sum ps else solve' bins len startd startk bink


solve' [] _ _ _ _ = 0
solve' (b:bins) len curd curk (k:bink)
  | curk > curd = curk * len * k + solve' (b:bins) len curd (curk `div` 2) bink
  | curk < curd = curd * b + solve' (bins) len (curd `div` 2) curk bink
  | otherwise =
      if k == 1 then
        curd * (max b (len-b)) + solve' bins len (curd `div` 2) (curk `div` 2)　bink
      else
        curd * b + solve' bins len (curd `div` 2) (curd `div` 2) bink

binPlus xs = reverse $ foldl adds [] $ map intToBin xs

intToBin n = inIntToBin n
  where
    inIntToBin 0 = []
    inIntToBin n = (n `mod` 2) : inIntToBin (n `div` 2)

adds [] ys = ys
adds (xs) [] = xs
adds (x:xs) (y:ys) = (x+y) : (adds xs ys)
