from collections import deque,Counter



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

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

T = eval(input())



T = T.translate(str.maketrans({'r': 'p', 's': 'r','p': 's'}))

cnt = Counter(T)

dic = {"r":R, "s":S, "p":P}



ans = cnt["r"]*R + cnt["s"]*S +cnt["p"]*P

checked = []

for i in range(N-K+1):

    if i%K in checked:

        continue

    else:

        j = i

        tmp = 0

        while j <len(T):

            if tmp == T[j]:

                ans -= dic[T[j]]

                tmp = 0

            else:

                tmp = T[j]

            j += K

        checked.append(i%K)



print(ans)



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

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

T = eval(input())



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



ans = 0

for i in range(K):

    j = i

    tmp = ""

    while j <N:

        if tmp != T[j]:

            ans += score[T[j]]

            tmp = T[j]

        else:

            tmp = ""

        j += K



print(ans)



from collections import deque, Counter

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
T = T.translate(str.maketrans({"r": "p", "s": "r", "p": "s"}))
cnt = Counter(T)
dic = {"r": R, "s": S, "p": P}
ans = cnt["r"] * R + cnt["s"] * S + cnt["p"] * P
checked = []
for i in range(N - K + 1):
    if i % K in checked:
        continue
    else:
        j = i
        tmp = 0
        while j < len(T):
            if tmp == T[j]:
                ans -= dic[T[j]]
                tmp = 0
            else:
                tmp = T[j]
            j += K
        checked.append(i % K)
print(ans)

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

-from collections import deque, Counter - -T = T.translate(str.maketrans({"r": "p", "s": "r", "p": "s"})) -cnt = Counter(T) -dic = {"r": R, "s": S, "p": P} -ans = cnt["r"] * R + cnt["s"] * S + cnt["p"] * P -checked = [] -for i in range(N - K + 1): -    if i % K in checked: -        continue -    else: -        j = i -        tmp = 0 -        while j < len(T): -            if tmp == T[j]: -                ans -= dic[T[j]] -                tmp = 0 -            else: -                tmp = T[j] -            j += K -        checked.append(i % K) +score = {"s": R, "p": S, "r": P} +ans = 0 +for i in range(K): +    j = i +    tmp = "" +    while j < N: +        if tmp != T[j]: +            ans += score[T[j]] +            tmp = T[j] +        else: +            tmp = "" +        j += K