from collections import Counter, deque



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

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

t = eval(input())

con = Counter(t)

ans = con['r'] * p + con['s'] * r + con['p'] * s

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

for i in range(k):

    target = list(t[i::k])

    hp = 0

    count = 1

    for j in range(len(target)):

        hn = target[j]

        if hn == hp:

            count += 1

        elif count > 1:

            ans -= count // 2 * dic[hp]

            count = 1

        hp = hn

    else:

        ans -= count // 2 * dic[hp]

print(ans)

def main():

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

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

    t = eval(input())

    hand = ['r', 's', 'p']

    score = [p, r, s]

    dic_score = dict(list(zip(hand, score)))

    win = [0] * n

    ans = 0

    for i in range(k):

        ans += dic_score[t[i]]

        win[i] = 1

    for i in range(k, n):

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

            continue

        ans += dic_score[t[i]]

        win[i] = 1

    print(ans)





if __name__ == '__main__':

    main()

from collections import Counter, deque

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
con = Counter(t)
ans = con["r"] * p + con["s"] * r + con["p"] * s
dic = {"r": p, "s": r, "p": s}
for i in range(k):
    target = list(t[i::k])
    hp = 0
    count = 1
    for j in range(len(target)):
        hn = target[j]
        if hn == hp:
            count += 1
        elif count > 1:
            ans -= count // 2 * dic[hp]
            count = 1
        hp = hn
    else:
        ans -= count // 2 * dic[hp]
print(ans)

def main():
    n, k = list(map(int, input().split()))
    r, s, p = list(map(int, input().split()))
    t = eval(input())
    hand = ["r", "s", "p"]
    score = [p, r, s]
    dic_score = dict(list(zip(hand, score)))
    win = [0] * n
    ans = 0
    for i in range(k):
        ans += dic_score[t[i]]
        win[i] = 1
    for i in range(k, n):
        if t[i] == t[i - k] and win[i - k]:
            continue
        ans += dic_score[t[i]]
        win[i] = 1
    print(ans)


if __name__ == "__main__":
    main()

-from collections import Counter, deque +def main(): +    n, k = list(map(int, input().split())) +    r, s, p = list(map(int, input().split())) +    t = eval(input()) +    hand = ["r", "s", "p"] +    score = [p, r, s] +    dic_score = dict(list(zip(hand, score))) +    win = [0] * n +    ans = 0 +    for i in range(k): +        ans += dic_score[t[i]] +        win[i] = 1 +    for i in range(k, n): +        if t[i] == t[i - k] and win[i - k]: +            continue +        ans += dic_score[t[i]] +        win[i] = 1 +    print(ans) -n, k = list(map(int, input().split())) -r, s, p = list(map(int, input().split())) -t = eval(input()) -con = Counter(t) -ans = con["r"] * p + con["s"] * r + con["p"] * s -dic = {"r": p, "s": r, "p": s} -for i in range(k): -    target = list(t[i::k]) -    hp = 0 -    count = 1 -    for j in range(len(target)): -        hn = target[j] -        if hn == hp: -            count += 1 -        elif count > 1: -            ans -= count // 2 * dic[hp] -            count = 1 -        hp = hn -    else: -        ans -= count // 2 * dic[hp] -print(ans) + +if __name__ == "__main__": +    main()