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

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

t = eval(input())

win = ['x' for i in range(n)]

ans = 0

if t[0] == 'r':

    win[0] = 'p'

elif t[0] == 's':

    win[0] = 'r'

else:

    win[0] = 's'

for i in range(1,n):

    if t[i] == 'r':

        win[i] = 'p'

    elif t[i] == 's':

        win[i] = 'r'

    else:

        win[i] = 's'

for i in range(k,n):

    if win[i-k] == win[i] and win[i-k] != 'x':

        win[i] = 'x'

for i in range(n):

    if win[i] == 'r':

        ans += r

    elif win[i] == 's':

        ans += s

    elif win[i] == 'p':

        ans += p

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

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

t = [i for i in eval(input())]

ans = 0

for i in range(n):

    if t[i] == 'r':

        tmp = p

        ans += p

    elif t[i] == 's':

        tmp = r

        ans += r

    elif t[i] == 'p':

        tmp = s

        ans += s

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

        ans -= tmp

        t[i] = 'X'

print(ans)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
win = ["x" for i in range(n)]
ans = 0
if t[0] == "r":
    win[0] = "p"
elif t[0] == "s":
    win[0] = "r"
else:
    win[0] = "s"
for i in range(1, n):
    if t[i] == "r":
        win[i] = "p"
    elif t[i] == "s":
        win[i] = "r"
    else:
        win[i] = "s"
for i in range(k, n):
    if win[i - k] == win[i] and win[i - k] != "x":
        win[i] = "x"
for i in range(n):
    if win[i] == "r":
        ans += r
    elif win[i] == "s":
        ans += s
    elif win[i] == "p":
        ans += p
print(ans)

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

-t = eval(input()) -win = ["x" for i in range(n)] +t = [i for i in eval(input())] -if t[0] == "r": -    win[0] = "p" -elif t[0] == "s": -    win[0] = "r" -else: -    win[0] = "s" -for i in range(1, n): +for i in range(n): -        win[i] = "p" +        tmp = p +        ans += p -        win[i] = "r" -    else: -        win[i] = "s" -for i in range(k, n): -    if win[i - k] == win[i] and win[i - k] != "x": -        win[i] = "x" -for i in range(n): -    if win[i] == "r": +        tmp = r -    elif win[i] == "s": +    elif t[i] == "p": +        tmp = s -    elif win[i] == "p": -        ans += p +    if k <= i and t[i - k] == t[i]: +        ans -= tmp +        t[i] = "X"