import Control.Applicative newtype Parser a = Parser { parse :: String -> [(a, String)]} instance Functor Parser where fmap f p = Parser $ \str -> [(f x, xs) | (x, xs) <- parse p str] instance Applicative Parser where pure x = Parser $ \str -> [(x, str)] p <*> x = Parser $ \str -> [ (f x, rest') | (f, rest) <- parse p str, (x, rest') <- parse x rest ] instance Alternative Parser where empty = Parser $ \str -> [] p <|> q = Parser $ \str -> case parse p str of [] -> parse q str result -> result satisfy :: (Char -> Bool) -> Parser Char satisfy pred = Parser $ \str -> case str of (x:xs) | pred x -> [(x, xs)] _ -> [] next = satisfy (const True) char c = satisfy (==c) string "" = pure "" string (x:xs) = char x *> string xs *> pure (x:xs) miin = string "mi" *> many (char '-') *> char 'n' main = do str <- getContents let ((x,xs):rest) = parse (many miin) str in print $ length x