let n, k, r, s, p, t = Scanf.scanf " %d %d %d %d %d %s" @@ fun a b c d e f -> a, b, c, d, e, f
let f = function 'r' -> p | 's' -> r | _ -> s
let ss = Array.init n (fun i -> f t.[i])
let _ = Array.(iteri (fun i s -> if i >= k && ss.(i - k) > 0 && t.[i] = t.[i - k] then ss.(i) <- 0) ss; fold_left (+) 0 ss) |> Printf.printf "%d\n"