edist' :: Char -> String -> (Int, Bool)
edist' h (x:[]) = (0, h == x)
edist' h (x:x':[])
	| x == x'   = (1, False)
	| otherwise = (0, h == x')
edist' h (x:x':xs)
	| x == x'   = let (n, l) = edist' h xs in (n + 1, l)
	| otherwise = edist' h (x':xs)

looped xs = head xs == last xs

edist :: String -> Int -> Int
edist xs k = k * n + if l then k - 1 else 0
	where (n, l) = edist' (head xs) xs

main :: IO ()
main = do
	xs <- getLine
	k <- readLn
	print $ edist xs k
