import qualified Data.IntMap.Strict as Map main :: IO () main = do s0 <- map (read @Int) . words <$> getContents let splitHalf n = let nd = length (show n) in if even nd then Just $ n `quotRem` (10 ^ (nd `quot` 2)) else Nothing let blink = Map.fromListWith (+) . concatMap (\(n, c) -> if n == 0 then [(1, c)] else case splitHalf n of Just (n1, n2) -> [(n1, c), (n2, c)] Nothing -> [(n * 2024, c)]) . Map.assocs print $ sum . Map.elems $ iterate blink (Map.fromList (map (,1::Int) s0)) !! 25 print $ sum . Map.elems $ iterate blink (Map.fromList (map (,1) s0)) !! 75