solve :: String -> Int -> Int
solve s k
  | even k    = f ss * (k `div` 2)
  | otherwise = f ss * (k `div` 2) + f ((last s):s)
  where
    ss = (concat . replicate 2) 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