N, K = list(map(int, input().split())) #N回ジャンケン, K回前と同じ手を出せない

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

T = eval(input())



t_k = [[] for i in range(K)]



for i in range(N):

    t_k[i%K].append(T[i])



hand = ['r', 's', 'p']

ans = 0

for i_k in t_k:

    n = len(i_k)

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

    cnt = 1

    for s in i_k:

        a = hand.index(s) #相手の手

        if a==0:

            point = [0, 0, P]

        elif a==1:

            point = [R, 0, 0]

        else:

            point = [0, S, 0]

        dp[cnt][0] = max(dp[cnt-1][1]+point[0], dp[cnt-1][2]+point[0])

        dp[cnt][1] = max(dp[cnt-1][0]+point[1], dp[cnt-1][2]+point[1])

        dp[cnt][2] = max(dp[cnt-1][0]+point[2], dp[cnt-1][1]+point[2])

        cnt += 1

    ans += max(dp[n])





print(ans)


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

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

T = eval(input())



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



ans = 0

for r in range(K):

    i = r

    p = '' #一個前の文字

    while i<N:

        if T[i] == p:

            p = ''

        else:

            ans += score[T[i]]

            p = T[i]

        i += K



print(ans)
N, K = list(map(int, input().split()))  # N回ジャンケン, K回前と同じ手を出せない
R, S, P = list(map(int, input().split()))
T = eval(input())
t_k = [[] for i in range(K)]
for i in range(N):
    t_k[i % K].append(T[i])
hand = ["r", "s", "p"]
ans = 0
for i_k in t_k:
    n = len(i_k)
    dp = [[0, 0, 0] for i in range(n + 1)]
    cnt = 1
    for s in i_k:
        a = hand.index(s)  # 相手の手
        if a == 0:
            point = [0, 0, P]
        elif a == 1:
            point = [R, 0, 0]
        else:
            point = [0, S, 0]
        dp[cnt][0] = max(dp[cnt - 1][1] + point[0], dp[cnt - 1][2] + point[0])
        dp[cnt][1] = max(dp[cnt - 1][0] + point[1], dp[cnt - 1][2] + point[1])
        dp[cnt][2] = max(dp[cnt - 1][0] + point[2], dp[cnt - 1][1] + point[2])
        cnt += 1
    ans += max(dp[n])
print(ans)

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
score = {"r": P, "s": R, "p": S}
ans = 0
for r in range(K):
    i = r
    p = ""  # 一個前の文字
    while i < N:
        if T[i] == p:
            p = ""
        else:
            ans += score[T[i]]
            p = T[i]
        i += K
print(ans)

-N, K = list(map(int, input().split()))  # N回ジャンケン, K回前と同じ手を出せない +N, K = list(map(int, input().split())) -t_k = [[] for i in range(K)] -for i in range(N): -    t_k[i % K].append(T[i]) -hand = ["r", "s", "p"] +score = {"r": P, "s": R, "p": S} -for i_k in t_k: -    n = len(i_k) -    dp = [[0, 0, 0] for i in range(n + 1)] -    cnt = 1 -    for s in i_k: -        a = hand.index(s)  # 相手の手 -        if a == 0: -            point = [0, 0, P] -        elif a == 1: -            point = [R, 0, 0] +for r in range(K): +    i = r +    p = ""  # 一個前の文字 +    while i < N: +        if T[i] == p: +            p = "" -            point = [0, S, 0] -        dp[cnt][0] = max(dp[cnt - 1][1] + point[0], dp[cnt - 1][2] + point[0]) -        dp[cnt][1] = max(dp[cnt - 1][0] + point[1], dp[cnt - 1][2] + point[1]) -        dp[cnt][2] = max(dp[cnt - 1][0] + point[2], dp[cnt - 1][1] + point[2]) -        cnt += 1 -    ans += max(dp[n]) +            ans += score[T[i]] +            p = T[i] +        i += K