solve :: String -> Int -> Int
solve s k
  | even n    = f s * k
  | otherwise = let (d,r) = k `divMod` 2
                   in (f s * 2 + 1) * d + r * f s
  where
    n = length s
    f []  = 0
    f [_] = 0
    f (x1:x2:xs)
      | x1 == x2  = 1 + f xs
      | otherwise = f (x2:xs)

main :: IO ()
main = do
    s <- getLine
    k <- readLn :: IO Int
    print $ solve s k