main :: IO () main = interact $ show . solve . map read . words solve :: [Int] -> Int solve [vegi, meet, n, total] | n > meet = 0 | otherwise = if i * n > meet then meet `div` n else i where i = length $ filter (<= total) $ map (* (n + 1)) [1..vegi]