import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fromIntegral . fst . fromJust . BS.readInteger

readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine

getString = readString <$> BS.getLine

calc :: String -> Int
calc [] = 0
calc [c'] = 0
calc s
  | c' == c'' = 1 + calc s''
  | otherwise = calc s'
  where
    c' = head s
    s' = tail s
    c'' = head s'
    s'' = tail s'

main = do
  [s] <- getString
  k <- getInt
  if (length s) == 1
    then print $ k `div` 2
    else do
      let d = calc (s ++ s)
      if even k
        then print $ d * (k `div` 2)
        else print $ d * (k `div` 2) + calc s
