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

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

T=eval(input())

G=[[] for n in range(K)]



for n in range(N):

  G[n%K].append(T[n])



cnt=0

for g in G:

  r,s,p=True,True,True

  for g2 in g:

    if g2=='r':

      if p:

        p=False

        r,s=True,True

        cnt+=P

      else:

        r,s,p=True,True,True

    if g2=='s':

      if r:

        r=False

        p,s=True,True

        cnt+=R

      else:

        r,s,p=True,True,True

    if g2=='p':

      if s:

        s=False

        r,p=True,True

        cnt+=S

      else:

        r,s,p=True,True,True



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

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

T=eval(input())



ans=0

chk=[0]*N

for n in range(N):

  c=T[n]

  if n>=K and T[n-K]==c and chk[n-K]==0:

    chk[n]=1 # not used

    continue

  if c=='r':

    ans+=P

  elif c=='s':

    ans+=R

  else:

    ans+=S



print(ans)
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
G = [[] for n in range(K)]
for n in range(N):
    G[n % K].append(T[n])
cnt = 0
for g in G:
    r, s, p = True, True, True
    for g2 in g:
        if g2 == "r":
            if p:
                p = False
                r, s = True, True
                cnt += P
            else:
                r, s, p = True, True, True
        if g2 == "s":
            if r:
                r = False
                p, s = True, True
                cnt += R
            else:
                r, s, p = True, True, True
        if g2 == "p":
            if s:
                s = False
                r, p = True, True
                cnt += S
            else:
                r, s, p = True, True, True
print(cnt)

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = eval(input())
ans = 0
chk = [0] * N
for n in range(N):
    c = T[n]
    if n >= K and T[n - K] == c and chk[n - K] == 0:
        chk[n] = 1  # not used
        continue
    if c == "r":
        ans += P
    elif c == "s":
        ans += R
    else:
        ans += S
print(ans)

-G = [[] for n in range(K)] +ans = 0 +chk = [0] * N -    G[n % K].append(T[n]) -cnt = 0 -for g in G: -    r, s, p = True, True, True -    for g2 in g: -        if g2 == "r": -            if p: -                p = False -                r, s = True, True -                cnt += P -            else: -                r, s, p = True, True, True -        if g2 == "s": -            if r: -                r = False -                p, s = True, True -                cnt += R -            else: -                r, s, p = True, True, True -        if g2 == "p": -            if s: -                s = False -                r, p = True, True -                cnt += S -            else: -                r, s, p = True, True, True -print(cnt) +    c = T[n] +    if n >= K and T[n - K] == c and chk[n - K] == 0: +        chk[n] = 1  # not used +        continue +    if c == "r": +        ans += P +    elif c == "s": +        ans += R +    else: +        ans += S +print(ans)