edist' :: String -> Int
edist' (x:x':xs)
	| x == x'   = 1 + edist' xs
	| otherwise = edist' (x':xs)
edist' _ = 0

edist [x] k = k `div` 2
edist xs k = k * d + (k - 1) * m
	where
		dist = edist' (xs ++ xs)
		d = dist `div` 2
		m = dist `mod` 2

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