import Data.List (inits, tails) main :: IO () main = do input <- map (map (read @Int) . words) . lines <$> getContents let safePair a b = 1 <= b - a && b - a <= 3 let safeRep l = all (uncurry safePair) (zip l (tail l)) || all (uncurry (flip safePair)) (zip l (tail l)) print $ sum [fromEnum (safeRep l) | l <- input] let dampened l = l : zipWith (++) (inits l) (tail (tails l)) let safeRep' l = any safeRep (dampened l) print $ sum [fromEnum (safeRep' l) | l <- input]