let s = read_line ()
let k = Scanf.sscanf (read_line ()) "%d" @@ fun k -> k

let s_len = String.length s

let f () = 
  let change = Array.make s_len 0 in
  for i = 1 to s_len - 1 do
    if s.[i] = s.[i - 1] && change.(i - 1) = 0 then change.(i) <- 1
  done;
  Array.fold_left (+) 0 change * k + if s.[0] = s.[s_len - 1]  && change.(s_len - 1) = 0 then k / 2 else 0

let () =
  Printf.printf "%d\n" @@ match s_len with
    | 1 -> k / 2
    | 2 -> if s.[0] = s.[1] then k else 0
    | _ -> f ()