let k, t, ss = Scanf.scanf "%d %d %d %d %d %s" @@ fun n k r s p t -> k, t, Array.init n (fun i -> match t.[i] with 'r' -> p | 's' -> r | _ -> s)
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"