module Main where import Input main :: IO () main = do input <- head <$> getInput 4 let (low', high') = fmap tail (span (/= '-') input) (low, high) = (read low', read high') :: (Int, Int) rdigits 0 = [] rdigits n = n `mod` 10 : rdigits (n `div` 10) rdigitpairs n = let l = rdigits n in zip l (tail l) has2digit n = any (uncurry (==)) (rdigitpairs n) nondecrease n = all (uncurry (>=)) (rdigitpairs n) acceptable n = has2digit n && nondecrease n print (length (filter acceptable [low..high])) let has2digit' [] = False has2digit' (a:b:c:xs) | a == b, b == c = has2digit' (dropWhile (== a) xs) has2digit' (a:b:_) | a == b = True has2digit' (_:xs) = has2digit' xs acceptable' n = has2digit' (rdigits n) && nondecrease n print (length (filter acceptable' [low..high]))