f :: Int -> Int -> [Int] f from to = [x | x <- [from .. to], isDiv3 x || has3 x] where isDiv3 = (== 0) . (`mod` 3) has3 = elem '3' . show main :: IO () main = getLine >>= (\[a, b] -> mapM_ print (f a b)) . map read . words