main = do
    text <- getLine 
    num <- getLine 
    let num_i = read num :: Int
    let (firstNum, firstCheck) = check text False
    if num_i == 1
         then putStrLn $ show firstNum
         else putStrLn $ show $ mainSecond text firstCheck firstNum num_i


mainSecond :: [Char] -> Bool -> Int -> Int -> Int
mainSecond text firstCheck firstNum num = if secondCheck == True
            then firstNum * (num - halfNum) + secondNum * halfNum
            else firstNum + secondNum * (num - 1)
    where
        lastCheck = (text !! 0 == text !! (length text  -1))
        (secondNum, secondCheck) = if firstCheck == False && lastCheck 
            then check text True
            else check text False
        halfNum = div num 2


check :: [Char] -> Bool -> (Int, Bool)
check word skip 
    | skip == True = checkLoop word wordlen 1 False 1
    | otherwise = checkLoop word wordlen 0 False 0
    where wordlen = length word

checkLoop :: [Char] -> Int -> Int -> Bool -> Int-> (Int, Bool)
checkLoop word wordlen index last lastNum
    | (index + 2) >= wordlen = (thisNum, thisCheck)
    | otherwise =  checkLoop word wordlen (index + 1) thisCheck thisNum
    where thisCheck = if last == True 
                then False 
                else checkIndex word index
          thisNum = if thisCheck == True 
                    then 1 + lastNum
                    else lastNum

checkIndex :: [Char] -> Int -> Bool
checkIndex word index = if word1 == word2
                        then True
                        else False
    where 
        word1 = word !! index 
        word2 = word !! (index + 1)