import numpy as np

def solve(n, k, r, s, p, t):

    dp = np.zeros((n, 3), dtype=int)

    win_hand_mapping = {

        "r": "p",

        "s": "r",

        "p": "s"

    }

    score_mapping = {

        "r": r,

        "s": s,

        "p": p

    }

    hand_index_mapping = {

        "r": 0,

        "s": 1,

        "p": 2

    }

    legal_hands_mapping = {

        i: [j for j in range(3) if i!=j] for i in range(3)

    }

    for i0 in range(k):

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

            win_hand = win_hand_mapping[t[i]]

            win_hand_index = hand_index_mapping[win_hand]

            win_hand_score = score_mapping[win_hand]

            for current in range(3):

                point = (current == win_hand_index) * win_hand_score

                if i < k:

                    dp[i][current] = max(dp[i][current], point)

                else:

                    for before in legal_hands_mapping[current]:

                        dp[i][current] = max(dp[i][current], dp[i-k][before] + point)

    return np.max(dp, axis=1)[-k:].sum()



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

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

t = eval(input())

print((solve(n, k, r, s, p, t)))
"""

References

----------

https://atcoder.jp/contests/abc149/submissions/9219652

"""

def solve(n, k, r, s, p, t):

    score = 0

    mapping = {"r": p, "s": r, "p": s}

    t = list(t)

    for i in range(k):

        score += mapping[t[i]]

    for i in range(k, n):

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

            t[i] = "x"

        else:

            score += mapping[t[i]]

    return score



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

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

t = eval(input())

print((solve(n, k, r, s, p, t)))
import numpy as np


def solve(n, k, r, s, p, t):
    dp = np.zeros((n, 3), dtype=int)
    win_hand_mapping = {"r": "p", "s": "r", "p": "s"}
    score_mapping = {"r": r, "s": s, "p": p}
    hand_index_mapping = {"r": 0, "s": 1, "p": 2}
    legal_hands_mapping = {i: [j for j in range(3) if i != j] for i in range(3)}
    for i0 in range(k):
        for i in range(i0, n, k):
            win_hand = win_hand_mapping[t[i]]
            win_hand_index = hand_index_mapping[win_hand]
            win_hand_score = score_mapping[win_hand]
            for current in range(3):
                point = (current == win_hand_index) * win_hand_score
                if i < k:
                    dp[i][current] = max(dp[i][current], point)
                else:
                    for before in legal_hands_mapping[current]:
                        dp[i][current] = max(dp[i][current], dp[i - k][before] + point)
    return np.max(dp, axis=1)[-k:].sum()


n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
print((solve(n, k, r, s, p, t)))

"""
References
----------
https://atcoder.jp/contests/abc149/submissions/9219652
"""


def solve(n, k, r, s, p, t):
    score = 0
    mapping = {"r": p, "s": r, "p": s}
    t = list(t)
    for i in range(k):
        score += mapping[t[i]]
    for i in range(k, n):
        if t[i] == t[i - k]:
            t[i] = "x"
        else:
            score += mapping[t[i]]
    return score


n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
print((solve(n, k, r, s, p, t)))

-import numpy as np +""" +References +https://atcoder.jp/contests/abc149/submissions/9219652 +""" -    dp = np.zeros((n, 3), dtype=int) -    win_hand_mapping = {"r": "p", "s": "r", "p": "s"} -    score_mapping = {"r": r, "s": s, "p": p} -    hand_index_mapping = {"r": 0, "s": 1, "p": 2} -    legal_hands_mapping = {i: [j for j in range(3) if i != j] for i in range(3)} -    for i0 in range(k): -        for i in range(i0, n, k): -            win_hand = win_hand_mapping[t[i]] -            win_hand_index = hand_index_mapping[win_hand] -            win_hand_score = score_mapping[win_hand] -            for current in range(3): -                point = (current == win_hand_index) * win_hand_score -                if i < k: -                    dp[i][current] = max(dp[i][current], point) -                else: -                    for before in legal_hands_mapping[current]: -                        dp[i][current] = max(dp[i][current], dp[i - k][before] + point) -    return np.max(dp, axis=1)[-k:].sum() +    score = 0 +    mapping = {"r": p, "s": r, "p": s} +    t = list(t) +    for i in range(k): +        score += mapping[t[i]] +    for i in range(k, n): +        if t[i] == t[i - k]: +            t[i] = "x" +        else: +            score += mapping[t[i]] +    return score