import Control.Applicative import Data.List (sortBy) import Data.Int readInts :: IO [Int64] readInts = map read . words <$> getLine main = do [n, v] <- readInts cs <- readInts let comp (x,y) (x',y') = compare (x*y') (x'*y) total = sum cs cs' = sortBy comp $ zip (scanl1 (+) cs) [1..] f 0 _ = 0 f x ((a,b):ys) = a * (x `div` b) + f (x `mod` b) ys in print $ if v < n then total else total + f (v-n) cs'