let s = stdin.ReadLine()
let n = s |> Seq.length
let k = stdin.ReadLine() |> int64
let rec f i c l p n =
    if i=n then p+l/2 |> int64
    elif s.[i]=c then f (i+1) c (l+1) p n
    else f (i+1) (s.[i]) 1 (p+l/2) n
let g =
    if s.[0]=s.[n-1] && s.[n-2]<>s.[n-1] then (f 1 (s.[0]) 1 0 (n-1))*k+k-1L
    else (f 1 (s.[0]) 1 0 n)*k
g |> stdout.WriteLine