n, k = gets.split.map(&:to_i)
all_hands = ["r", "s", "p"]
score = Hash[all_hands.zip(gets.split.map(&:to_i))]
seq = gets.chomp
win = { "r" => "p", "s" => "r", "p" => "s" }

log = []
earned = 0
seq.chars.each.with_index do |h, i|
  w = win[h]
  if i - k < 0 || log[i - k] != w
    earned += score[w]
    log << w
  else
    if i + k <= n - 1 && h != win[seq[i + k]]
      log << h
    else
      log << (all_hands - [w, h]).first
    end
  end
end

puts earned
