# ABC149 D

si = lambda: eval(input())

ni = lambda: int(eval(input()))

nm = lambda: list(map(int, input().split()))

nl = lambda: list(map(int, input().split()))

n,k=nm()

r,s,p=nm()

t=si()

l=[[] for i in range(k)]

ans=0



for i in range(n):

    j=(i+1)%k

    l[j].append(t[i:i+1])



same_flg=False

for ll in l:

    cur_str=''

    for lll in ll:

        if cur_str=='':

            if lll=='p':

                ans+=s

            elif lll=='r':

                ans+=p

            elif lll=='s':

                ans+=r 

            cur_str=lll

            same_flg=True

            continue



        if lll==cur_str:

            # 足さない

            cur_str=lll

            if same_flg==True:

                same_flg=False

            elif same_flg==False:

                if lll=='p':

                    ans+=s

                elif lll=='r':

                    ans+=p

                elif lll=='s':

                    ans+=r 

                same_flg=True

            pass

        else:

            if lll=='p':

                ans+=s

            elif lll=='r':

                ans+=p

            elif lll=='s':

                ans+=r

            cur_str=lll

            same_flg=True

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

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

t=eval(input())

ans=0

S=""



for i in range(n):

  if i-k>=0:

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

      if t[i]=="r":

        if S[i-k]=="p":

          S+="r"

        elif S[i-k]=="r":

          S+="p"

          ans+=p

      elif t[i]=="s":

        if S[i-k]=="r":

          S+="s"

        elif S[i-k]=="s":

          S+="r"

          ans+=r

      elif t[i]=="p":

        if S[i-k]=="s":

          S+="p"

        elif S[i-k]=="p":

          S+="s"

          ans+=s

      continue

  if t[i]=="r":

    ans+=p

    S+="p"

  elif t[i]=="s":

    ans+=r

    S+="r"

  elif t[i]=="p":

    ans+=s

    S+="s"

print(ans)
# ABC149 D
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n, k = nm()
r, s, p = nm()
t = si()
l = [[] for i in range(k)]
ans = 0
for i in range(n):
    j = (i + 1) % k
    l[j].append(t[i : i + 1])
same_flg = False
for ll in l:
    cur_str = ""
    for lll in ll:
        if cur_str == "":
            if lll == "p":
                ans += s
            elif lll == "r":
                ans += p
            elif lll == "s":
                ans += r
            cur_str = lll
            same_flg = True
            continue
        if lll == cur_str:
            # 足さない
            cur_str = lll
            if same_flg == True:
                same_flg = False
            elif same_flg == False:
                if lll == "p":
                    ans += s
                elif lll == "r":
                    ans += p
                elif lll == "s":
                    ans += r
                same_flg = True
            pass
        else:
            if lll == "p":
                ans += s
            elif lll == "r":
                ans += p
            elif lll == "s":
                ans += r
            cur_str = lll
            same_flg = True
print(ans)

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

-# ABC149 D -si = lambda: eval(input()) -ni = lambda: int(eval(input())) -nm = lambda: list(map(int, input().split())) -nl = lambda: list(map(int, input().split())) -n, k = nm() -r, s, p = nm() -t = si() -l = [[] for i in range(k)] +n, k = list(map(int, input().split())) +r, s, p = list(map(int, input().split())) +t = eval(input()) +S = "" -    j = (i + 1) % k -    l[j].append(t[i : i + 1]) -same_flg = False -for ll in l: -    cur_str = "" -    for lll in ll: -        if cur_str == "": -            if lll == "p": -                ans += s -            elif lll == "r": -                ans += p -            elif lll == "s": -                ans += r -            cur_str = lll -            same_flg = True +    if i - k >= 0: +        if t[i] == t[i - k]: +            if t[i] == "r": +                if S[i - k] == "p": +                    S += "r" +                elif S[i - k] == "r": +                    S += "p" +                    ans += p +            elif t[i] == "s": +                if S[i - k] == "r": +                    S += "s" +                elif S[i - k] == "s": +                    S += "r" +                    ans += r +            elif t[i] == "p": +                if S[i - k] == "s": +                    S += "p" +                elif S[i - k] == "p": +                    S += "s" +                    ans += s -        if lll == cur_str: -            # 足さない -            cur_str = lll -            if same_flg == True: -                same_flg = False -            elif same_flg == False: -                if lll == "p": -                    ans += s -                elif lll == "r": -                    ans += p -                elif lll == "s": -                    ans += r -                same_flg = True -            pass -        else: -            if lll == "p": -                ans += s -            elif lll == "r": -                ans += p -            elif lll == "s": -                ans += r -            cur_str = lll -            same_flg = True +    if t[i] == "r": +        ans += p +        S += "p" +    elif t[i] == "s": +        ans += r +        S += "r" +    elif t[i] == "p": +        ans += s +        S += "s"