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

ro, sc ,pa = list(map(int,input().split()))

a = eval(input())

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

scores = {'r':ro,'s':sc,'p':pa}

can_lelect = 'rsp'

select = ['' for _ in range(n)]

cant = [[] for _ in range(n)]

left = 0

cur = k

for i in range(k):

    need = dict[a[i]]

    select[i] = need

while cur < n:

    need_cur = dict[a[cur]]

    need_left = dict[a[left]]

    if select[left] == '':

        select[left] = need_left

    if need_cur == select[left] :

        if select[left] != need_left:

            cant[left].append(need_cur)

            for v in can_lelect:

                if v not in cant[left]:

                    select[left] = v

                    break

            select[cur] = need_cur

        else:

            cant[cur].append(need_cur)

            right = cur+k

            if right < n:

                need_right = dict[a[right]]

                cant[cur].append(need_right)

            for v in can_lelect:

                if  v not in cant[cur]:

                    select[cur] = v

                    break

    else:

        select[cur] = need_cur

    left+=1

    cur +=1

total = 0

for i in range(n):

    c = select[i]

    if c == dict[a[i]]:

        total+=scores[c]

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

ro, sc ,pa = list(map(int,input().split()))

a = eval(input())

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

scores = {'r':ro,'s':sc,'p':pa}

can_lelect = 'rsp'

select = ['' for _ in range(n)]

cant = [[] for _ in range(n)]

left = 0

cur = k

for i in range(k):

    need = dict[a[i]]

    select[i] = need

while cur < n:

    need_cur = dict[a[cur]]

    need_left = dict[a[left]]

    if select[left] == '':

        select[left] = need_left

    if need_cur == select[left] :

        if select[left] != need_left:

            cant[left].append(need_cur)

            for v in can_lelect:

                if v not in cant[left]:

                    select[left] = v

                    break

            select[cur] = need_cur

        else:

            cant[cur].append(need_cur)

            for v in can_lelect:

                if  v not in cant[cur]:

                    select[cur] = v

                    break

    else:

        select[cur] = need_cur

    left+=1

    cur +=1

total = 0

for i in range(n):

    c = select[i]

    if c == dict[a[i]]:

        total+=scores[c]

print(total)
n, k = list(map(int, input().split()))
ro, sc, pa = list(map(int, input().split()))
a = eval(input())
dict = {"r": "p", "s": "r", "p": "s"}
scores = {"r": ro, "s": sc, "p": pa}
can_lelect = "rsp"
select = ["" for _ in range(n)]
cant = [[] for _ in range(n)]
left = 0
cur = k
for i in range(k):
    need = dict[a[i]]
    select[i] = need
while cur < n:
    need_cur = dict[a[cur]]
    need_left = dict[a[left]]
    if select[left] == "":
        select[left] = need_left
    if need_cur == select[left]:
        if select[left] != need_left:
            cant[left].append(need_cur)
            for v in can_lelect:
                if v not in cant[left]:
                    select[left] = v
                    break
            select[cur] = need_cur
        else:
            cant[cur].append(need_cur)
            right = cur + k
            if right < n:
                need_right = dict[a[right]]
                cant[cur].append(need_right)
            for v in can_lelect:
                if v not in cant[cur]:
                    select[cur] = v
                    break
    else:
        select[cur] = need_cur
    left += 1
    cur += 1
total = 0
for i in range(n):
    c = select[i]
    if c == dict[a[i]]:
        total += scores[c]
print(total)

n, k = list(map(int, input().split()))
ro, sc, pa = list(map(int, input().split()))
a = eval(input())
dict = {"r": "p", "s": "r", "p": "s"}
scores = {"r": ro, "s": sc, "p": pa}
can_lelect = "rsp"
select = ["" for _ in range(n)]
cant = [[] for _ in range(n)]
left = 0
cur = k
for i in range(k):
    need = dict[a[i]]
    select[i] = need
while cur < n:
    need_cur = dict[a[cur]]
    need_left = dict[a[left]]
    if select[left] == "":
        select[left] = need_left
    if need_cur == select[left]:
        if select[left] != need_left:
            cant[left].append(need_cur)
            for v in can_lelect:
                if v not in cant[left]:
                    select[left] = v
                    break
            select[cur] = need_cur
        else:
            cant[cur].append(need_cur)
            for v in can_lelect:
                if v not in cant[cur]:
                    select[cur] = v
                    break
    else:
        select[cur] = need_cur
    left += 1
    cur += 1
total = 0
for i in range(n):
    c = select[i]
    if c == dict[a[i]]:
        total += scores[c]
print(total)

-            right = cur + k -            if right < n: -                need_right = dict[a[right]] -                cant[cur].append(need_right)