# coding: utf-8

# Your code here!

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

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

l=list(eval(input()))

play=[]



def point(hand):

    if hand=="r":

        return ["p",P]

    elif hand=="s":

        return ["r",R]

    else:

        return ["s",S]



ans=0

for i in range(N)[::-1]:

    if len(play)>=K:

        if point(l[i])[0]==play[-K]:

            if i-K>=0:

                temp=point(l[i-K])[0]

                for item in ["r","s","p"]:

                    if item!=play[-K] and item!=temp:

                        play.append(item)

                        break

            else:

                for item in ["r","s","p"]:

                    if item!=play[-K]:

                        play.append(item)

                        break

        else:

            play.append(point(l[i])[0])

            ans+=point(l[i])[1]

            

    else:

        play.append(point(l[i])[0])

        ans+=point(l[i])[1]

#print(play[::-1])

print(ans)
# coding: utf-8

# Your code here!

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

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

point=[R,S,P]

T=eval(input())



myhand=[]

for item in T:

    if item == "r":

        myhand.append("p")

    elif item == "s":

        myhand.append("r")

    else:

        myhand.append("s")



for i in range(N-K):

    if myhand[i]==myhand[i+K]:

        myhand[i+K]="-"

    

print((myhand.count("r")*R+myhand.count("s")*S+myhand.count("p")*P))









# coding: utf-8
# Your code here!
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
l = list(eval(input()))
play = []


def point(hand):
    if hand == "r":
        return ["p", P]
    elif hand == "s":
        return ["r", R]
    else:
        return ["s", S]


ans = 0
for i in range(N)[::-1]:
    if len(play) >= K:
        if point(l[i])[0] == play[-K]:
            if i - K >= 0:
                temp = point(l[i - K])[0]
                for item in ["r", "s", "p"]:
                    if item != play[-K] and item != temp:
                        play.append(item)
                        break
            else:
                for item in ["r", "s", "p"]:
                    if item != play[-K]:
                        play.append(item)
                        break
        else:
            play.append(point(l[i])[0])
            ans += point(l[i])[1]
    else:
        play.append(point(l[i])[0])
        ans += point(l[i])[1]
# print(play[::-1])
print(ans)

# coding: utf-8
# Your code here!
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
point = [R, S, P]
T = eval(input())
myhand = []
for item in T:
    if item == "r":
        myhand.append("p")
    elif item == "s":
        myhand.append("r")
    else:
        myhand.append("s")
for i in range(N - K):
    if myhand[i] == myhand[i + K]:
        myhand[i + K] = "-"
print((myhand.count("r") * R + myhand.count("s") * S + myhand.count("p") * P))

-l = list(eval(input())) -play = [] - - -def point(hand): -    if hand == "r": -        return ["p", P] -    elif hand == "s": -        return ["r", R] +point = [R, S, P] +T = eval(input()) +myhand = [] +for item in T: +    if item == "r": +        myhand.append("p") +    elif item == "s": +        myhand.append("r") -        return ["s", S] - - -ans = 0 -for i in range(N)[::-1]: -    if len(play) >= K: -        if point(l[i])[0] == play[-K]: -            if i - K >= 0: -                temp = point(l[i - K])[0] -                for item in ["r", "s", "p"]: -                    if item != play[-K] and item != temp: -                        play.append(item) -                        break -            else: -                for item in ["r", "s", "p"]: -                    if item != play[-K]: -                        play.append(item) -                        break -        else: -            play.append(point(l[i])[0]) -            ans += point(l[i])[1] -    else: -        play.append(point(l[i])[0]) -        ans += point(l[i])[1] -# print(play[::-1]) -print(ans) +        myhand.append("s") +for i in range(N - K): +    if myhand[i] == myhand[i + K]: +        myhand[i + K] = "-" +print((myhand.count("r") * R + myhand.count("s") * S + myhand.count("p") * P))