let s = stdin.ReadLine()
let k = stdin.ReadLine() |> int64

// 出現回数リストを作る
let f1 (count, before, chunkList) next = 
    match before with 
    | '#' -> 1, next, chunkList // 初期処理
    | x  when x=next -> count+1, next, chunkList
    | _ -> 1, next, (before,count)::chunkList

let appearranceList, (headS, headC), (lastS, lastC) = (s+"#").ToCharArray() |> Seq.fold f1 (0, '#', []) |> fun (_, _, list) -> list |> List.rev, list.Head, list |> List.rev |> List.head

// 端が同じ文字の場合は特殊処理
match appearranceList.Length, headS = lastS with
| 1, _ -> appearranceList |> List.head |> fun (_, i) -> int64 i * k / 2L
| _, false -> appearranceList |> Seq.sumBy (fun (_, i) -> int64 i / 2L) |> (*) k 
| _, true -> 
    appearranceList |> List.tail |> List.rev |> List.tail |> fun x -> (headS, headC + lastC) :: x |> Seq.sumBy (fun (_, i) -> int64 i / 2L) |> (*) (k-1L) //端を除く出現回数
    |>(+) (appearranceList |> Seq.sumBy (fun (_, i) -> int64 i / 2L)) //端の出現回数 
|> stdout.WriteLine