n, k = list(map(int, input().split()))

r, s, p = list(map(int, input().split()))

T = eval(input())

hand = ('r', 's', 'p')



def rps(hero, villain):

    hero = hand.index(hero)

    villain = hand.index(villain)

    result = hero - villain

    if result % 3 == 0 or result % 3 == 1:

        return 0

    else:

        return 1



if_rock, if_scissors, if_paper = ([0]*k for _ in range(3))

for i in range(n):

        tmp_r = rps('r', T[i]) * r + max(if_scissors[i%k], if_paper[i%k])

        tmp_s = rps('s', T[i]) * s + max(if_rock[i%k], if_paper[i%k])

        tmp_p = rps('p', T[i]) * p + max(if_rock[i%k], if_scissors[i%k])

        if_rock[i%k] = tmp_r

        if_scissors[i%k] = tmp_s

        if_paper[i%k] = tmp_p



maxpoint = 0

for i in range(k):

    maxpoint += max(if_rock[i], if_scissors[i], if_paper[i])

print(maxpoint)
n, k = list(map(int, input().split()))

r, s, p = list(map(int, input().split()))

T = list(eval(input()))



for i in range(k, n):

    if T[i] == T[i-k]:

        T[i] = 'x'



points = 0

for i in range(n):

    if T[i] == 'r':

        points += p

    elif T[i] == 's':

        points += r

    elif T[i] == 'p':

        points += s



print(points)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
T = eval(input())
hand = ("r", "s", "p")


def rps(hero, villain):
    hero = hand.index(hero)
    villain = hand.index(villain)
    result = hero - villain
    if result % 3 == 0 or result % 3 == 1:
        return 0
    else:
        return 1


if_rock, if_scissors, if_paper = ([0] * k for _ in range(3))
for i in range(n):
    tmp_r = rps("r", T[i]) * r + max(if_scissors[i % k], if_paper[i % k])
    tmp_s = rps("s", T[i]) * s + max(if_rock[i % k], if_paper[i % k])
    tmp_p = rps("p", T[i]) * p + max(if_rock[i % k], if_scissors[i % k])
    if_rock[i % k] = tmp_r
    if_scissors[i % k] = tmp_s
    if_paper[i % k] = tmp_p
maxpoint = 0
for i in range(k):
    maxpoint += max(if_rock[i], if_scissors[i], if_paper[i])
print(maxpoint)

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
T = list(eval(input()))
for i in range(k, n):
    if T[i] == T[i - k]:
        T[i] = "x"
points = 0
for i in range(n):
    if T[i] == "r":
        points += p
    elif T[i] == "s":
        points += r
    elif T[i] == "p":
        points += s
print(points)

-T = eval(input()) -hand = ("r", "s", "p") - - -def rps(hero, villain): -    hero = hand.index(hero) -    villain = hand.index(villain) -    result = hero - villain -    if result % 3 == 0 or result % 3 == 1: -        return 0 -    else: -        return 1 - - -if_rock, if_scissors, if_paper = ([0] * k for _ in range(3)) +T = list(eval(input())) +for i in range(k, n): +    if T[i] == T[i - k]: +        T[i] = "x" +points = 0 -    tmp_r = rps("r", T[i]) * r + max(if_scissors[i % k], if_paper[i % k]) -    tmp_s = rps("s", T[i]) * s + max(if_rock[i % k], if_paper[i % k]) -    tmp_p = rps("p", T[i]) * p + max(if_rock[i % k], if_scissors[i % k]) -    if_rock[i % k] = tmp_r -    if_scissors[i % k] = tmp_s -    if_paper[i % k] = tmp_p -maxpoint = 0 -for i in range(k): -    maxpoint += max(if_rock[i], if_scissors[i], if_paper[i]) -print(maxpoint) +    if T[i] == "r": +        points += p +    elif T[i] == "s": +        points += r +    elif T[i] == "p": +        points += s +print(points)