N, K = list(map(int, input().split()))

R, S, P = list(map(int, input().split()))

T = eval(input())



def janken(s):

  if s == "r":

    return P

  if s == "s":

    return R

  if s == "p":

    return S



answer = 0

for i in range(K):

  j = 0

  flag = 0

  while i + K * j < N:

    if j == 0:

      answer += janken(T[i + K * j])

    else:

      if T[i + K * j] != T[i + K * (j - 1)] or flag == 1:

        answer += janken(T[i + K * j])

        flag = 0

      else:

        flag = 1

    #print(T[i + K * j], answer)

    j += 1

print(answer)
def win(t):

  if t == "g":

    return "p"

  if t == "c":

    return "g"

  if t == "p":

    return "c"



N, K = list(map(int, input().split()))

G, C, P = list(map(int, input().split()))

T = input().replace("r", "g").replace("s", "c")



point = {"g": G, "c": C, "p": P}



check = [None] * (N + K)

answer = 0

for i in range(N):

  w = win(T[i])

  if check[i] != w:

    answer += point[w]

    check[i + K] = w

    

print(answer)
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())


def janken(s):
    if s == "r":
        return P
    if s == "s":
        return R
    if s == "p":
        return S


answer = 0
for i in range(K):
    j = 0
    flag = 0
    while i + K * j < N:
        if j == 0:
            answer += janken(T[i + K * j])
        else:
            if T[i + K * j] != T[i + K * (j - 1)] or flag == 1:
                answer += janken(T[i + K * j])
                flag = 0
            else:
                flag = 1
        # print(T[i + K * j], answer)
        j += 1
print(answer)

def win(t):
    if t == "g":
        return "p"
    if t == "c":
        return "g"
    if t == "p":
        return "c"


N, K = list(map(int, input().split()))
G, C, P = list(map(int, input().split()))
T = input().replace("r", "g").replace("s", "c")
point = {"g": G, "c": C, "p": P}
check = [None] * (N + K)
answer = 0
for i in range(N):
    w = win(T[i])
    if check[i] != w:
        answer += point[w]
        check[i + K] = w
print(answer)

-N, K = list(map(int, input().split())) -R, S, P = list(map(int, input().split())) -T = eval(input()) +def win(t): +    if t == "g": +        return "p" +    if t == "c": +        return "g" +    if t == "p": +        return "c" -def janken(s): -    if s == "r": -        return P -    if s == "s": -        return R -    if s == "p": -        return S - - +N, K = list(map(int, input().split())) +G, C, P = list(map(int, input().split())) +T = input().replace("r", "g").replace("s", "c") +point = {"g": G, "c": C, "p": P} +check = [None] * (N + K) -for i in range(K): -    j = 0 -    flag = 0 -    while i + K * j < N: -        if j == 0: -            answer += janken(T[i + K * j]) -        else: -            if T[i + K * j] != T[i + K * (j - 1)] or flag == 1: -                answer += janken(T[i + K * j]) -                flag = 0 -            else: -                flag = 1 -        # print(T[i + K * j], answer) -        j += 1 +for i in range(N): +    w = win(T[i]) +    if check[i] != w: +        answer += point[w] +        check[i + K] = w