import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (group)

main :: IO ()
main = do
  s <- getLine :: IO String
  (k : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    gs = map ((,) <$> head <*> length) . group $ s
    n | l == 1 = f (lh * k)
      | ch == cl = let ls = init . tail . map snd $ gs in f lh + g ls * k + f (lh + ll) * (pred k) + f ll
      | otherwise = (g . map snd $ gs) * k
      where
        l = length gs
        (ch, lh) = head gs
        (cl, ll) = last gs
  print n

f :: Int -> Int
f = (`div` 2)

g :: [Int] -> Int
g = sum . map f

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
