def calc(l):

    n = len(l)

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

    

    for i in range(n):

        if l[i]=='r':

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

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

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

        elif l[i]=='s':

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

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

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

        else:

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

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

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

    

    return max(dp[n])



N, K = list(map(int, input().split()))

R, S, P = list(map(int, input().split()))

T = eval(input())

ans = 0



for i in range(K):

    l = []

    j = i

    

    for j in range(i, N, K):

        l.append(T[j])

    

    ans += calc(l)



print(ans)
import sys

input = sys.stdin.readline



N, K = list(map(int, input().split()))

R, S, P = list(map(int, input().split()))

T = list(eval(input()))

score = {'r': P, 's': R, 'p': S}

ans = 0



for i in range(N):

    if i<K:

        ans += score[T[i]]

    else:

        if T[i]!=T[i-K]:

            ans += score[T[i]]

        else:

            T[i] = '?'

            

print(ans)
def calc(l):
    n = len(l)
    dp = [[0] * 3 for _ in range(n + 1)]
    for i in range(n):
        if l[i] == "r":
            dp[i + 1][0] = max(dp[i][1], dp[i][2])
            dp[i + 1][1] = max(dp[i][0], dp[i][2])
            dp[i + 1][2] = max(dp[i][0], dp[i][1]) + P
        elif l[i] == "s":
            dp[i + 1][0] = max(dp[i][1], dp[i][2]) + R
            dp[i + 1][1] = max(dp[i][0], dp[i][2])
            dp[i + 1][2] = max(dp[i][0], dp[i][1])
        else:
            dp[i + 1][0] = max(dp[i][1], dp[i][2])
            dp[i + 1][1] = max(dp[i][0], dp[i][2]) + S
            dp[i + 1][2] = max(dp[i][0], dp[i][1])
    return max(dp[n])


N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
ans = 0
for i in range(K):
    l = []
    j = i
    for j in range(i, N, K):
        l.append(T[j])
    ans += calc(l)
print(ans)

import sys

input = sys.stdin.readline
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
score = {"r": P, "s": R, "p": S}
ans = 0
for i in range(N):
    if i < K:
        ans += score[T[i]]
    else:
        if T[i] != T[i - K]:
            ans += score[T[i]]
        else:
            T[i] = "?"
print(ans)

-def calc(l): -    n = len(l) -    dp = [[0] * 3 for _ in range(n + 1)] -    for i in range(n): -        if l[i] == "r": -            dp[i + 1][0] = max(dp[i][1], dp[i][2]) -            dp[i + 1][1] = max(dp[i][0], dp[i][2]) -            dp[i + 1][2] = max(dp[i][0], dp[i][1]) + P -        elif l[i] == "s": -            dp[i + 1][0] = max(dp[i][1], dp[i][2]) + R -            dp[i + 1][1] = max(dp[i][0], dp[i][2]) -            dp[i + 1][2] = max(dp[i][0], dp[i][1]) -        else: -            dp[i + 1][0] = max(dp[i][1], dp[i][2]) -            dp[i + 1][1] = max(dp[i][0], dp[i][2]) + S -            dp[i + 1][2] = max(dp[i][0], dp[i][1]) -    return max(dp[n]) +import sys - +input = sys.stdin.readline -T = eval(input()) +T = list(eval(input())) +score = {"r": P, "s": R, "p": S} -for i in range(K): -    l = [] -    j = i -    for j in range(i, N, K): -        l.append(T[j]) -    ans += calc(l) +for i in range(N): +    if i < K: +        ans += score[T[i]] +    else: +        if T[i] != T[i - K]: +            ans += score[T[i]] +        else: +            T[i] = "?"