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

R, S, P = list(map(int, input().split()))  # R=0, S=1, P=2

T = eval(input())



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

s = [P, R, S]

hand = {'r': 0, 's': 1, 'p': 2}

H = [' '] * N



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

for sub in range(1, K + 1):

    i = sub

    while i <= N:

        h = hand[T[i - 1]]

        for j in range(3):

            score = s[j] if j == h else 0

            dp[i][j] = max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3]) + score

        i += K



ans = 0

for k in range(K):

    ans += max(dp[N - k])



print(ans)

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

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

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

T = eval(input())

hand = {'r': 'p', 's': 'r', 'p': 's'}



history = []

cnt = 0

for i, t in enumerate(T):

    if i < K:

        u = hand[t]

        flag = 1

    elif K <= i < N - K:

        l = i - K

        r = i + K

        if hand[t] == history[l]:

            u = T[r]

            flag = 0

        else:

            u = hand[t]

            flag = 1

    else:

        l = i - K

        if hand[t] == history[l]:

            u = t

            flag = 0

        else:

            u = hand[t]

            flag = 1

    cnt += score[u] * flag

    history.append(u)



print(cnt)

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))  # R=0, S=1, P=2
T = eval(input())
_score = {"r": P, "s": R, "p": S}
s = [P, R, S]
hand = {"r": 0, "s": 1, "p": 2}
H = [" "] * N
dp = [[0] * 3 for _ in range(N + 1)]
for sub in range(1, K + 1):
    i = sub
    while i <= N:
        h = hand[T[i - 1]]
        for j in range(3):
            score = s[j] if j == h else 0
            dp[i][j] = (
                max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3])
                + score
            )
        i += K
ans = 0
for k in range(K):
    ans += max(dp[N - k])
print(ans)

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
score = {"r": R, "s": S, "p": P}
T = eval(input())
hand = {"r": "p", "s": "r", "p": "s"}
history = []
cnt = 0
for i, t in enumerate(T):
    if i < K:
        u = hand[t]
        flag = 1
    elif K <= i < N - K:
        l = i - K
        r = i + K
        if hand[t] == history[l]:
            u = T[r]
            flag = 0
        else:
            u = hand[t]
            flag = 1
    else:
        l = i - K
        if hand[t] == history[l]:
            u = t
            flag = 0
        else:
            u = hand[t]
            flag = 1
    cnt += score[u] * flag
    history.append(u)
print(cnt)

-R, S, P = list(map(int, input().split()))  # R=0, S=1, P=2 +R, S, P = list(map(int, input().split())) +score = {"r": R, "s": S, "p": P} -_score = {"r": P, "s": R, "p": S} -s = [P, R, S] -hand = {"r": 0, "s": 1, "p": 2} -H = [" "] * N -dp = [[0] * 3 for _ in range(N + 1)] -for sub in range(1, K + 1): -    i = sub -    while i <= N: -        h = hand[T[i - 1]] -        for j in range(3): -            score = s[j] if j == h else 0 -            dp[i][j] = ( -                max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3]) -                + score -            ) -        i += K -ans = 0 -for k in range(K): -    ans += max(dp[N - k]) -print(ans) +hand = {"r": "p", "s": "r", "p": "s"} +history = [] +cnt = 0 +for i, t in enumerate(T): +    if i < K: +        u = hand[t] +        flag = 1 +    elif K <= i < N - K: +        l = i - K +        r = i + K +        if hand[t] == history[l]: +            u = T[r] +            flag = 0 +        else: +            u = hand[t] +            flag = 1 +    else: +        l = i - K +        if hand[t] == history[l]: +            u = t +            flag = 0 +        else: +            u = hand[t] +            flag = 1 +    cnt += score[u] * flag +    history.append(u) +print(cnt)