solve :: String -> Int -> Int
solve s k = f (s ++ [head s]) * k
  where
    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