n, k = list(map(int, input().split()))

r, s, p = list(map(int, input().split()))

t = eval(input())



dp = [0] * n

commands = [""] * n



for i in range(n):

    if t[i] == "r":

        commands[i] = "p"

        dp[i] = p

    elif t[i] == "s":

        commands[i] = "r"

        dp[i] = r

    elif t[i] == "p":

        commands[i] = "s"

        dp[i] = s



    if k <= i:

        if commands[i] == commands[i-k]:

            commands[i] = ""

            dp[i] = 0



print((sum(dp)))
"""

r > p

s > r

p > s

"""

n, k = list(map(int, input().split()))

r, s, p = list(map(int, input().split()))

t = eval(input())



ans = 0

hand = [""] * n



for i in range(n):

    if i < k:

        if t[i] == "r":

            ans += p

            hand[i] = "p"

        elif t[i] == "s":

            ans += r

            hand[i] = "r"

        elif t[i] == "p":

            ans += s

            hand[i] = "s"

    else:

        if t[i] == "r":

            if hand[i-k] != "p":

                ans += p

                hand[i] = "p"

            else:

                hand[i] = "?"

        elif t[i] == "s":

            if hand[i-k] != "r":

                ans += r

                hand[i] = "r"

            else:

                hand[i] = "?"

        elif t[i] == "p":

            if hand[i-k] != "s":

                ans += s

                hand[i] = "s"

            else:

                hand[i] = "?"

print(ans)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [0] * n
commands = [""] * n
for i in range(n):
    if t[i] == "r":
        commands[i] = "p"
        dp[i] = p
    elif t[i] == "s":
        commands[i] = "r"
        dp[i] = r
    elif t[i] == "p":
        commands[i] = "s"
        dp[i] = s
    if k <= i:
        if commands[i] == commands[i - k]:
            commands[i] = ""
            dp[i] = 0
print((sum(dp)))

"""
r > p
s > r
p > s
"""
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
ans = 0
hand = [""] * n
for i in range(n):
    if i < k:
        if t[i] == "r":
            ans += p
            hand[i] = "p"
        elif t[i] == "s":
            ans += r
            hand[i] = "r"
        elif t[i] == "p":
            ans += s
            hand[i] = "s"
    else:
        if t[i] == "r":
            if hand[i - k] != "p":
                ans += p
                hand[i] = "p"
            else:
                hand[i] = "?"
        elif t[i] == "s":
            if hand[i - k] != "r":
                ans += r
                hand[i] = "r"
            else:
                hand[i] = "?"
        elif t[i] == "p":
            if hand[i - k] != "s":
                ans += s
                hand[i] = "s"
            else:
                hand[i] = "?"
print(ans)

+""" +r > p +s > r +p > s +""" -dp = [0] * n -commands = [""] * n +ans = 0 +hand = [""] * n -    if t[i] == "r": -        commands[i] = "p" -        dp[i] = p -    elif t[i] == "s": -        commands[i] = "r" -        dp[i] = r -    elif t[i] == "p": -        commands[i] = "s" -        dp[i] = s -    if k <= i: -        if commands[i] == commands[i - k]: -            commands[i] = "" -            dp[i] = 0 -print((sum(dp))) +    if i < k: +        if t[i] == "r": +            ans += p +            hand[i] = "p" +        elif t[i] == "s": +            ans += r +            hand[i] = "r" +        elif t[i] == "p": +            ans += s +            hand[i] = "s" +    else: +        if t[i] == "r": +            if hand[i - k] != "p": +                ans += p +                hand[i] = "p" +            else: +                hand[i] = "?" +        elif t[i] == "s": +            if hand[i - k] != "r": +                ans += r +                hand[i] = "r" +            else: +                hand[i] = "?" +        elif t[i] == "p": +            if hand[i - k] != "s": +                ans += s +                hand[i] = "s" +            else: +                hand[i] = "?" +print(ans)