n, k = gets.split.map(&:to_i)
R, S, P = gets.split.map(&:to_i)
table = Hash["s", R, "p", S, "r", P]
win_pattern = Hash["s", "r", "p", "s", "r", "p"]
t = gets.chomp.split("")
score = 0
hands = []

puts table["s"]