allSame xs = all (uncurry (==)) $ zip xs $ tail xs

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

edist xs k
	| allSame xs = (k * length xs) `div` 2
	| otherwise  = 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
