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

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

T = input().strip()





def pon(computer, mine):

    if computer == 'r' and mine == 2: return P

    if computer == 's' and mine == 0: return R

    if computer == 'p' and mine == 1: return S

    return 0





dp = [[0 for _ in range(3)] for _ in range(N+10)]



ans = 0

for st in range(K):

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

        for j in range(3):

            for k in range(3):

                if j == k:

                    continue

                if i+1-K >= 0:

                    dp[i+1][k] = max(dp[i+1][k], dp[i+1-K][j] + pon(T[i], k))

                else:

                    dp[i+1][k] = max(dp[i+1][k], pon(T[i], 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[i][ｊ]:=i番目までで、最後にｊを出したときの点数の最大値

dp = [[-10**9]*3for i in range(n+k)]

for i in range(k):

    dp[i][0],dp[i][1],dp[i][2] = 0,0,0

    

    

 

for i in range(k):

    for j in range(n//k+3):

        if i > n-1:continue

        if t[i] == "r":

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

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

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

        

        elif t[i] == "s":

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

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

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

        

        elif t[i] == "p":

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

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

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

        i += k

ans = 0    

for i in range(n,n+k):

    ans += max(dp[i])

print(ans)

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input().strip()


def pon(computer, mine):
    if computer == "r" and mine == 2:
        return P
    if computer == "s" and mine == 0:
        return R
    if computer == "p" and mine == 1:
        return S
    return 0


dp = [[0 for _ in range(3)] for _ in range(N + 10)]
ans = 0
for st in range(K):
    for i in range(st, N, K):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                if i + 1 - K >= 0:
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i + 1 - K][j] + pon(T[i], k))
                else:
                    dp[i + 1][k] = max(dp[i + 1][k], pon(T[i], 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[i][ｊ]:=i番目までで、最後にｊを出したときの点数の最大値
dp = [[-(10**9)] * 3 for i in range(n + k)]
for i in range(k):
    dp[i][0], dp[i][1], dp[i][2] = 0, 0, 0
for i in range(k):
    for j in range(n // k + 3):
        if i > n - 1:
            continue
        if t[i] == "r":
            dp[i + k][0] = max(dp[i][1], dp[i][2])
            dp[i + k][1] = max(dp[i][0], dp[i][2])
            dp[i + k][2] = max(dp[i][0] + p, dp[i][1] + p)
        elif t[i] == "s":
            dp[i + k][0] = max(dp[i][1] + r, dp[i][2] + r)
            dp[i + k][1] = max(dp[i][0], dp[i][2])
            dp[i + k][2] = max(dp[i][0], dp[i][1])
        elif t[i] == "p":
            dp[i + k][0] = max(dp[i][1], dp[i][2])
            dp[i + k][1] = max(dp[i][0] + s, dp[i][2] + s)
            dp[i + k][2] = max(dp[i][0], dp[i][1])
        i += k
ans = 0
for i in range(n, n + k):
    ans += max(dp[i])
print(ans)

-N, K = list(map(int, input().split())) -R, S, P = list(map(int, input().split())) -T = input().strip() - - -def pon(computer, mine): -    if computer == "r" and mine == 2: -        return P -    if computer == "s" and mine == 0: -        return R -    if computer == "p" and mine == 1: -        return S -    return 0 - - -dp = [[0 for _ in range(3)] for _ in range(N + 10)] +n, k = list(map(int, input().split())) +r, s, p = list(map(int, input().split())) +t = eval(input()) +# dp[i][ｊ]:=i番目までで、最後にｊを出したときの点数の最大値 +dp = [[-(10**9)] * 3 for i in range(n + k)] +for i in range(k): +    dp[i][0], dp[i][1], dp[i][2] = 0, 0, 0 +for i in range(k): +    for j in range(n // k + 3): +        if i > n - 1: +            continue +        if t[i] == "r": +            dp[i + k][0] = max(dp[i][1], dp[i][2]) +            dp[i + k][1] = max(dp[i][0], dp[i][2]) +            dp[i + k][2] = max(dp[i][0] + p, dp[i][1] + p) +        elif t[i] == "s": +            dp[i + k][0] = max(dp[i][1] + r, dp[i][2] + r) +            dp[i + k][1] = max(dp[i][0], dp[i][2]) +            dp[i + k][2] = max(dp[i][0], dp[i][1]) +        elif t[i] == "p": +            dp[i + k][0] = max(dp[i][1], dp[i][2]) +            dp[i + k][1] = max(dp[i][0] + s, dp[i][2] + s) +            dp[i + k][2] = max(dp[i][0], dp[i][1]) +        i += k -for st in range(K): -    for i in range(st, N, K): -        for j in range(3): -            for k in range(3): -                if j == k: -                    continue -                if i + 1 - K >= 0: -                    dp[i + 1][k] = max(dp[i + 1][k], dp[i + 1 - K][j] + pon(T[i], k)) -                else: -                    dp[i + 1][k] = max(dp[i + 1][k], pon(T[i], k)) -    ans += max(dp[i + 1]) +for i in range(n, n + k): +    ans += max(dp[i])