let f = function 'r' -> 'p' | 's' -> 'r' | _ -> 's'
let ans, n, k, t, g = Scanf.(scanf "%d %d %d %d %d" @@ fun n k r s p -> ref 0, n, k, Array.init n (fun _ -> scanf " %c" @@ fun c -> c), (function 'r' -> r | 's' -> s | _ -> p))
let _ = Array.iteri (fun i c -> if i < k || t.(i - k) <> c then ans := !ans + g (f c) else if i + k < n && c = t.(i + k) then t.(i) <- f c) t; Printf.printf "%d\n" !ans