import Data.List
main = do
    s <- group <$> getLine
    k <- readLn
    let h = head s
        l = last s
        inner = sum $ map (\g -> (length g) `div` 2) s
        inter | head h /= head l = 0
              | otherwise = lh `div` 2 + ll `div` 2 - (lh+ll) `div` 2
              where lh = length h
                    ll = length l
    print $ (inner * k) - (inter * (k-1))