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

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

t = [i for i in eval(input())]

ans = 0

rsp = {"r": 0, "s": 0, "p": 0}

for i in range(n):

    if t[i] == "r":

        ans += p

    elif t[i] == "s":

        ans += r

    else:

        ans += s

    if i >= k and t[i] == t[i-k]:

        rsp[t[i]] += 1

        t[i] = "o"

mi = int(rsp["r"] * p + rsp["s"] * r + rsp["p"] * s)

print((ans-mi))
n, k = list(map(int, input().split()))

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

t = [i for i in eval(input())]

ans = 0

for i in range(n):

    if i >= k and t[i] == t[i-k]:

        t[i] = "o"

        continue

    if t[i] == "r":

        ans += p

    elif t[i] == "s":

        ans += r

    else:

        ans += s

print(ans)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = [i for i in eval(input())]
ans = 0
rsp = {"r": 0, "s": 0, "p": 0}
for i in range(n):
    if t[i] == "r":
        ans += p
    elif t[i] == "s":
        ans += r
    else:
        ans += s
    if i >= k and t[i] == t[i - k]:
        rsp[t[i]] += 1
        t[i] = "o"
mi = int(rsp["r"] * p + rsp["s"] * r + rsp["p"] * s)
print((ans - mi))

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = [i for i in eval(input())]
ans = 0
for i in range(n):
    if i >= k and t[i] == t[i - k]:
        t[i] = "o"
        continue
    if t[i] == "r":
        ans += p
    elif t[i] == "s":
        ans += r
    else:
        ans += s
print(ans)

-rsp = {"r": 0, "s": 0, "p": 0} +    if i >= k and t[i] == t[i - k]: +        t[i] = "o" +        continue -    if i >= k and t[i] == t[i - k]: -        rsp[t[i]] += 1 -        t[i] = "o" -mi = int(rsp["r"] * p + rsp["s"] * r + rsp["p"] * s) -print((ans - mi)) +print(ans)