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

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

T = [i for i in eval(input())]

my_T = []

result = 0



for i in T:

  if i == "r":

    my_T.append("p")

  elif i == "s":

    my_T.append("r")

  elif i == "p":

    my_T.append("s")



for i in range(K, N):

      if my_T[i] == my_T[i-K]:

            if i+K < N:

                  if my_T[i+K] == "r":

                        my_T[i] = "s"

                  elif my_T[i+K] == "s":

                        my_T[i] = "p"

                  elif my_T[i+K] == "p":

                        my_T[i] = "r"

            else:

                  if my_T[i-K] == "r":

                        my_T[i] = "s"

                  elif my_T[i-K] == "s":

                        my_T[i] = "p"

                  elif my_T[i-K] == "p":

                        my_T[i] = "r"

      else:

        if my_T[i] == "r":

              result += R

        elif my_T[i] == "s":

              result += S

        elif my_T[i] == "p":

              result += P



for i in range(K):

      if my_T[i] == "r":

            result += R

      elif my_T[i] == "s":

            result += S

      elif my_T[i] == "p":

            result += P





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

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

T = [i for i in eval(input())]

result = 0



score = {"r": P, "s": R, "p": S}

for i in range(K):

      result += score[T[i]]

for i in range(K, N):

      if T[i] == T[i-K]:

            T[i] = ""

            continue

      else:

            result += score[T[i]]



print(result)
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in eval(input())]
my_T = []
result = 0
for i in T:
    if i == "r":
        my_T.append("p")
    elif i == "s":
        my_T.append("r")
    elif i == "p":
        my_T.append("s")
for i in range(K, N):
    if my_T[i] == my_T[i - K]:
        if i + K < N:
            if my_T[i + K] == "r":
                my_T[i] = "s"
            elif my_T[i + K] == "s":
                my_T[i] = "p"
            elif my_T[i + K] == "p":
                my_T[i] = "r"
        else:
            if my_T[i - K] == "r":
                my_T[i] = "s"
            elif my_T[i - K] == "s":
                my_T[i] = "p"
            elif my_T[i - K] == "p":
                my_T[i] = "r"
    else:
        if my_T[i] == "r":
            result += R
        elif my_T[i] == "s":
            result += S
        elif my_T[i] == "p":
            result += P
for i in range(K):
    if my_T[i] == "r":
        result += R
    elif my_T[i] == "s":
        result += S
    elif my_T[i] == "p":
        result += P
print(result)

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in eval(input())]
result = 0
score = {"r": P, "s": R, "p": S}
for i in range(K):
    result += score[T[i]]
for i in range(K, N):
    if T[i] == T[i - K]:
        T[i] = ""
        continue
    else:
        result += score[T[i]]
print(result)

-my_T = [] -for i in T: -    if i == "r": -        my_T.append("p") -    elif i == "s": -        my_T.append("r") -    elif i == "p": -        my_T.append("s") +score = {"r": P, "s": R, "p": S} +for i in range(K): +    result += score[T[i]] -    if my_T[i] == my_T[i - K]: -        if i + K < N: -            if my_T[i + K] == "r": -                my_T[i] = "s" -            elif my_T[i + K] == "s": -                my_T[i] = "p" -            elif my_T[i + K] == "p": -                my_T[i] = "r" -        else: -            if my_T[i - K] == "r": -                my_T[i] = "s" -            elif my_T[i - K] == "s": -                my_T[i] = "p" -            elif my_T[i - K] == "p": -                my_T[i] = "r" +    if T[i] == T[i - K]: +        T[i] = "" +        continue -        if my_T[i] == "r": -            result += R -        elif my_T[i] == "s": -            result += S -        elif my_T[i] == "p": -            result += P -for i in range(K): -    if my_T[i] == "r": -        result += R -    elif my_T[i] == "s": -        result += S -    elif my_T[i] == "p": -        result += P +        result += score[T[i]]