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

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

t=list(eval(input()))

ans=0



for i in range(0,n):

  if t[i]=="r":

    ans+=p

  elif t[i]=="s":

    ans+=r

  elif t[i]=="p":

    ans+=s



for i in range(0,n-k):

  if t[i]==t[i+k]:

    t[i+k]="M"

    if t[i]=="r":

      ans-=p

    elif t[i]=="s":

      ans-=r

    elif t[i]=="p":

      ans-=s   

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

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

t=list(eval(input()))

ans=0



for i in range(n):

  if i<k:

    if t[i]=="r":

      ans+=p

    elif t[i]=="s":

      ans+=r

    elif t[i]=="p":

      ans+=s

  else:

    if t[i]=="r" and t[i-k]!=t[i]:

      ans+=p

    elif t[i]=="s" and t[i-k]!=t[i]:

      ans+=r

    elif t[i]=="p" and t[i-k]!=t[i]:

      ans+=s

    else:

      t[i]="X"

    

print(ans)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = list(eval(input()))
ans = 0
for i in range(0, n):
    if t[i] == "r":
        ans += p
    elif t[i] == "s":
        ans += r
    elif t[i] == "p":
        ans += s
for i in range(0, n - k):
    if t[i] == t[i + k]:
        t[i + k] = "M"
        if t[i] == "r":
            ans -= p
        elif t[i] == "s":
            ans -= r
        elif t[i] == "p":
            ans -= s
print(ans)

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = list(eval(input()))
ans = 0
for i in range(n):
    if i < k:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        elif t[i] == "p":
            ans += s
    else:
        if t[i] == "r" and t[i - k] != t[i]:
            ans += p
        elif t[i] == "s" and t[i - k] != t[i]:
            ans += r
        elif t[i] == "p" and t[i - k] != t[i]:
            ans += s
        else:
            t[i] = "X"
print(ans)

-for i in range(0, n): -    if t[i] == "r": -        ans += p -    elif t[i] == "s": -        ans += r -    elif t[i] == "p": -        ans += s -for i in range(0, n - k): -    if t[i] == t[i + k]: -        t[i + k] = "M" +for i in range(n): +    if i < k: -            ans -= p +            ans += p -            ans -= r +            ans += r -            ans -= s +            ans += s +    else: +        if t[i] == "r" and t[i - k] != t[i]: +            ans += p +        elif t[i] == "s" and t[i - k] != t[i]: +            ans += r +        elif t[i] == "p" and t[i - k] != t[i]: +            ans += s +        else: +            t[i] = "X"