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

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

t = eval(input())

ans = 0

ans_list = [0 for i in range(n)]



for i in range(len(t)):

  if t[i] == 'r':

    if (t[i-k] != 'r') | (ans_list[i-k] == 0):

      ans_list[i] = 1

      ans += p

    else:

      ans_list[i] = 0

      ans += 0

  if t[i] == 's':

    if (t[i-k] != 's') | (ans_list[i-k] == 0):

      ans_list[i] = 1

      ans += r

    else:

      ans_list[i] = 0

      ans += 0

  if t[i] == 'p':

    if (t[i-k] != 'p') | (ans_list[i-k] == 0):

      ans_list[i] = 1

      ans += s

    else:

      ans_list[i] = 0

      ans += 0

      

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

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

t = eval(input())

point = 0

win = [0 for i in range(len(t))]



for i in range(len(t)):

  if t[i] == 'r':

    if (t[i-k] != 'r') or (win[i-k] != 1):

      point += p

      win[i] = 1



  if t[i] == 's':

    if (t[i-k] != 's') or (win[i-k] != 1):

      point += r

      win[i] = 1

    

  if t[i] == 'p':

    if (t[i-k] != 'p') or (win[i-k] != 1):

      point += s

      win[i] = 1



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

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

-ans = 0 -ans_list = [0 for i in range(n)] +point = 0 +win = [0 for i in range(len(t))] -        if (t[i - k] != "r") | (ans_list[i - k] == 0): -            ans_list[i] = 1 -            ans += p -        else: -            ans_list[i] = 0 -            ans += 0 +        if (t[i - k] != "r") or (win[i - k] != 1): +            point += p +            win[i] = 1 -        if (t[i - k] != "s") | (ans_list[i - k] == 0): -            ans_list[i] = 1 -            ans += r -        else: -            ans_list[i] = 0 -            ans += 0 +        if (t[i - k] != "s") or (win[i - k] != 1): +            point += r +            win[i] = 1 -        if (t[i - k] != "p") | (ans_list[i - k] == 0): -            ans_list[i] = 1 -            ans += s -        else: -            ans_list[i] = 0 -            ans += 0 -print(ans) +        if (t[i - k] != "p") or (win[i - k] != 1): +            point += s +            win[i] = 1 +print(point)