n, k = tuple(map(int, input().split(' ')))

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

t = (eval(input()))

def char2int(c):

    if c == 'r':

        return p

    elif c == 's':

        return r

    else:

        return s

st = {i:t[i] for i in range(k)}

ans1 = sum(map(char2int, t[:k]))

ans2 = 0

for i in range(k, n):

    h = t[i]

    m = i%k

    if st[m] != h:

        ans2 += char2int(h)

        st[m] = h

    else:

        st[m] = 'any' 

print((ans1 + ans2))
n, k = tuple(map(int, input().split(' ')))

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

t = (eval(input()))

point = {'r':p, 's':r, 'p':s, 'any':0}

st = {i:t[i] for i in range(k)}

ans1 = sum([point[x] for x in t[:k]])

ans2 = 0

for i in range(k, n):

    h = t[i]

    m = i%k

    if st[m] != h:

        ans2 += point[h]

        st[m] = h

    else:

        st[m] = 'any' 

print((ans1 + ans2))
n, k = tuple(map(int, input().split(" ")))
r, s, p = tuple(map(int, input().split(" ")))
t = eval(input())


def char2int(c):
    if c == "r":
        return p
    elif c == "s":
        return r
    else:
        return s


st = {i: t[i] for i in range(k)}
ans1 = sum(map(char2int, t[:k]))
ans2 = 0
for i in range(k, n):
    h = t[i]
    m = i % k
    if st[m] != h:
        ans2 += char2int(h)
        st[m] = h
    else:
        st[m] = "any"
print((ans1 + ans2))

n, k = tuple(map(int, input().split(" ")))
r, s, p = tuple(map(int, input().split(" ")))
t = eval(input())
point = {"r": p, "s": r, "p": s, "any": 0}
st = {i: t[i] for i in range(k)}
ans1 = sum([point[x] for x in t[:k]])
ans2 = 0
for i in range(k, n):
    h = t[i]
    m = i % k
    if st[m] != h:
        ans2 += point[h]
        st[m] = h
    else:
        st[m] = "any"
print((ans1 + ans2))

- - -def char2int(c): -    if c == "r": -        return p -    elif c == "s": -        return r -    else: -        return s - - +point = {"r": p, "s": r, "p": s, "any": 0} -ans1 = sum(map(char2int, t[:k])) +ans1 = sum([point[x] for x in t[:k]]) -        ans2 += char2int(h) +        ans2 += point[h]