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

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

t=eval(input())



ans=0

win=[]

for tt in t:

 if tt=='r':

  win+='p'

  ans+=P

 elif tt=='s':

  win+='r'

  ans+=R

 else:

  win+='s'

  ans+=S



for i in range(k):

 l=win[i::k]

# print(l)

 for j in range(1,len(l)):

  if l[j]==l[j-1]:

   if l[j]=='p':

    ans-=P

   elif l[j]=='r':

    ans-=R

   else:

    ans-=S

   l[j]='z'



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

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

t=eval(input())



v=[]

ans=0

for i in t:

  if i=='r':

    v.append('p')

    ans+=P

  if i=='s':

    v.append('r')

    ans+=R

  if i=='p':

    v.append('s')

    ans+=S



for i in range(k,n):

  if v[i]==v[i-k]:

    if v[i]=='r':

      ans-=R

    if v[i]=='s':

      ans-=S

    if v[i]=='p':

      ans-=P



    v[i]='?'



print(ans)
n, k = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
t = eval(input())
ans = 0
win = []
for tt in t:
    if tt == "r":
        win += "p"
        ans += P
    elif tt == "s":
        win += "r"
        ans += R
    else:
        win += "s"
        ans += S
for i in range(k):
    l = win[i::k]
    # print(l)
    for j in range(1, len(l)):
        if l[j] == l[j - 1]:
            if l[j] == "p":
                ans -= P
            elif l[j] == "r":
                ans -= R
            else:
                ans -= S
            l[j] = "z"
print(ans)

n, k = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
t = eval(input())
v = []
ans = 0
for i in t:
    if i == "r":
        v.append("p")
        ans += P
    if i == "s":
        v.append("r")
        ans += R
    if i == "p":
        v.append("s")
        ans += S
for i in range(k, n):
    if v[i] == v[i - k]:
        if v[i] == "r":
            ans -= R
        if v[i] == "s":
            ans -= S
        if v[i] == "p":
            ans -= P
        v[i] = "?"
print(ans)

+v = [] -win = [] -for tt in t: -    if tt == "r": -        win += "p" +for i in t: +    if i == "r": +        v.append("p") -    elif tt == "s": -        win += "r" +    if i == "s": +        v.append("r") -    else: -        win += "s" +    if i == "p": +        v.append("s") -for i in range(k): -    l = win[i::k] -    # print(l) -    for j in range(1, len(l)): -        if l[j] == l[j - 1]: -            if l[j] == "p": -                ans -= P -            elif l[j] == "r": -                ans -= R -            else: -                ans -= S -            l[j] = "z" +for i in range(k, n): +    if v[i] == v[i - k]: +        if v[i] == "r": +            ans -= R +        if v[i] == "s": +            ans -= S +        if v[i] == "p": +            ans -= P +        v[i] = "?"