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

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

t = eval(input())



h = [''] * n

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

points = 0



for i, ti in enumerate(t):

    ci = c[ti]

    if i < k or h[i - k] != c[ti]:

        h[i] = ci

        points += eval(ci)

    else:

        p1, p2 = eval(ci), eval(h[i - k])

        if p1 > p2:

            h[i] = ci

            points -= p2

            points += p1

        else:

            h[i] = '*'





print(points)

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

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

t = eval(input())



h = [''] * n

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

points = 0



for i, ti in enumerate(t):

    ci = c[ti]

    if i < k or h[i - k] != c[ti]:

        h[i] = ci

        points += eval(ci)

    else:

        # p1, p2 = eval(ci), eval(h[i - k])

        # if p1 > p2:

        #     h[i] = ci

        #     points -= p2

        #     points += p1

        # else:

        h[i] = '*'





print(points)

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
h = [""] * n
c = {"r": "p", "s": "r", "p": "s"}
points = 0
for i, ti in enumerate(t):
    ci = c[ti]
    if i < k or h[i - k] != c[ti]:
        h[i] = ci
        points += eval(ci)
    else:
        p1, p2 = eval(ci), eval(h[i - k])
        if p1 > p2:
            h[i] = ci
            points -= p2
            points += p1
        else:
            h[i] = "*"
print(points)

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
h = [""] * n
c = {"r": "p", "s": "r", "p": "s"}
points = 0
for i, ti in enumerate(t):
    ci = c[ti]
    if i < k or h[i - k] != c[ti]:
        h[i] = ci
        points += eval(ci)
    else:
        # p1, p2 = eval(ci), eval(h[i - k])
        # if p1 > p2:
        #     h[i] = ci
        #     points -= p2
        #     points += p1
        # else:
        h[i] = "*"
print(points)

-        p1, p2 = eval(ci), eval(h[i - k]) -        if p1 > p2: -            h[i] = ci -            points -= p2 -            points += p1 -        else: -            h[i] = "*" +        # p1, p2 = eval(ci), eval(h[i - k]) +        # if p1 > p2: +        #     h[i] = ci +        #     points -= p2 +        #     points += p1 +        # else: +        h[i] = "*"