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

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

t = eval(input())



dp = [[0]*3 for i in range(n+1)]

# dp[i][今回の手]



for i in range(n):

    if t[i] == "r":

        dp[i+1][0] = max(dp[max(i+1-k, 0)][1] + p, dp[i+1][0])

        dp[i+1][0] = max(dp[max(i+1-k, 0)][2] + p, dp[i+1][0])

    if t[i] == "s":

        dp[i+1][1] = max(dp[max(i+1-k, 0)][0] + r, dp[i+1][1])

        dp[i+1][1] = max(dp[max(i+1-k, 0)][2] + r, dp[i+1][1])

    if t[i] == "p":

        dp[i+1][2] = max(dp[max(i+1-k, 0)][0] + s, dp[i+1][2])

        dp[i+1][2] = max(dp[max(i+1-k, 0)][1] + s, dp[i+1][2])

    dp[i+1][0] = max(dp[max(i+1-k, 0)][1], dp[i+1][0])

    dp[i+1][0] = max(dp[max(i+1-k, 0)][2], dp[i+1][0])

    dp[i+1][1] = max(dp[max(i+1-k, 0)][0], dp[i+1][1])

    dp[i+1][1] = max(dp[max(i+1-k, 0)][2], dp[i+1][1])

    dp[i+1][2] = max(dp[max(i+1-k, 0)][0], dp[i+1][2])

    dp[i+1][2] = max(dp[max(i+1-k, 0)][1], dp[i+1][2])



ans = 0

for i in range(k):

    ans += max(dp[n-i])

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

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

t = eval(input())



dp = [[0] * 3 for i in range(n + 1)]

for i in range(n):

    if i + 1 - k < 0:

        if t[i] == "r":

            dp[i + 1][0] = p

        if t[i] == "s":

            dp[i + 1][1] = r

        if t[i] == "p":

            dp[i + 1][2] = s

    else:

        if t[i] == "r":

            dp[i + 1][0] = p + max(dp[i + 1 - k][1], dp[i + 1 - k][2])

            dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])

            dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])

        if t[i] == "s":

            dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])

            dp[i + 1][1] = r + max(dp[i + 1 - k][2], dp[i + 1 - k][0])

            dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])

        if t[i] == "p":

            dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])

            dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])

            dp[i + 1][2] = s + max(dp[i + 1 - k][0], dp[i + 1 - k][1])

ans = 0

for i in range(k):

    ans += max(dp[-i - 1])

print(ans)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [[0] * 3 for i in range(n + 1)]
# dp[i][今回の手]
for i in range(n):
    if t[i] == "r":
        dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1] + p, dp[i + 1][0])
        dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2] + p, dp[i + 1][0])
    if t[i] == "s":
        dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0] + r, dp[i + 1][1])
        dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2] + r, dp[i + 1][1])
    if t[i] == "p":
        dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0] + s, dp[i + 1][2])
        dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1] + s, dp[i + 1][2])
    dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][0])
    dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][0])
    dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][1])
    dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][1])
    dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][2])
    dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][2])
ans = 0
for i in range(k):
    ans += max(dp[n - i])
print(ans)

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [[0] * 3 for i in range(n + 1)]
for i in range(n):
    if i + 1 - k < 0:
        if t[i] == "r":
            dp[i + 1][0] = p
        if t[i] == "s":
            dp[i + 1][1] = r
        if t[i] == "p":
            dp[i + 1][2] = s
    else:
        if t[i] == "r":
            dp[i + 1][0] = p + max(dp[i + 1 - k][1], dp[i + 1 - k][2])
            dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])
            dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])
        if t[i] == "s":
            dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])
            dp[i + 1][1] = r + max(dp[i + 1 - k][2], dp[i + 1 - k][0])
            dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])
        if t[i] == "p":
            dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])
            dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])
            dp[i + 1][2] = s + max(dp[i + 1 - k][0], dp[i + 1 - k][1])
ans = 0
for i in range(k):
    ans += max(dp[-i - 1])
print(ans)

-# dp[i][今回の手] -    if t[i] == "r": -        dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1] + p, dp[i + 1][0]) -        dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2] + p, dp[i + 1][0]) -    if t[i] == "s": -        dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0] + r, dp[i + 1][1]) -        dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2] + r, dp[i + 1][1]) -    if t[i] == "p": -        dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0] + s, dp[i + 1][2]) -        dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1] + s, dp[i + 1][2]) -    dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][0]) -    dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][0]) -    dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][1]) -    dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][1]) -    dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][2]) -    dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][2]) +    if i + 1 - k < 0: +        if t[i] == "r": +            dp[i + 1][0] = p +        if t[i] == "s": +            dp[i + 1][1] = r +        if t[i] == "p": +            dp[i + 1][2] = s +    else: +        if t[i] == "r": +            dp[i + 1][0] = p + max(dp[i + 1 - k][1], dp[i + 1 - k][2]) +            dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0]) +            dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1]) +        if t[i] == "s": +            dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2]) +            dp[i + 1][1] = r + max(dp[i + 1 - k][2], dp[i + 1 - k][0]) +            dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1]) +        if t[i] == "p": +            dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2]) +            dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0]) +            dp[i + 1][2] = s + max(dp[i + 1 - k][0], dp[i + 1 - k][1]) -    ans += max(dp[n - i]) +    ans += max(dp[-i - 1])