• + 0 comments

    Haskell:

    module Main where
    
    solve :: String -> Int -> Int
    solve ss n =
        let
            l = length ss
            c = length $ filter (== 'a') ss
            (m, r) = n `divMod` l
            d = length $ filter (== 'a') $ take r ss
         in
            m * c + d
    
    main :: IO ()
    main = do
        ss <- getLine :: IO String
        n <- readLn :: IO Int
        print $ solve ss n