let () = Scanf.scanf "%d %d\n%d %d %d\n%s" @@ fun n k r s p t ->
  let dp =
    Array.init (n + k) @@ fun _ ->
      Array.make 3 0 in
  for i = 0 to n - 1 do
    dp.(i + k).(0) <-
      max dp.(i).(1) dp.(i).(2)
      + if t.[i] = 's' then r else 0;
    dp.(i + k).(1) <-
      max dp.(i).(0) dp.(i).(2)
      + if t.[i] = 'p' then s else 0;
    dp.(i + k).(2) <-
      max dp.(i).(0) dp.(i).(1)
      + if t.[i] = 'r' then p else 0;
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init k @@ fun i ->
    Array.fold_left max min_int dp.(n + i)
