import qualified Data.ByteString.Lazy.Char8 as C import qualified Data.HashMap.Strict as M counter :: C.ByteString -> M.HashMap Char Int counter = C.foldr counter' M.empty where counter' x m | M.member x m = M.adjust (+ 1) x m | otherwise = M.insert x 1 m countTrees :: C.ByteString -> Int countTrees s = minimum [t, r, div e 2] where ctr = counter s t = M.lookupDefault 0 't' ctr r = M.lookupDefault 0 'r' ctr e = M.lookupDefault 0 'e' ctr main :: IO () main = print . countTrees =<< C.getContents