Scanf.scanf "%s %d" (fun s k ->
    let n = String.length s in
    let check p s =
        let rec loop i p acc =
            if i = n then acc, p else
                if s.[i] = p then loop (i + 1) '@' (acc + 1) else
                                  loop (i + 1) s.[i] acc
        in
        loop 0 p 0
    in
    let a1, p = check '@' s in
    let a2, _ = check p   s in
    Printf.printf "%d\n" @@ a1 + a2 * (k - 1)
)