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

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

t=eval(input())

ss=[""]*k

ans=0

for i in range(n):ss[i%k]+=t[i]

for t in ss:

  m=len(t)

  dp=[[0,0,0]for _ in range(m)]

  #rsp

  if t[0]=="r":dp[0]=[0,0,p]

  elif t[0]=="s":dp[0]=[r,0,0]

  else:dp[0]=[0,s,0]

  for i in range(1,m):

    dp[i]=[max(dp[i-1][1],dp[i-1][2]),max(dp[i-1][0],dp[i-1][2]),max(dp[i-1][0],dp[i-1][1])]

    if t[i]=="r":

      dp[i][2]+=p

    if t[i]=="s":dp[i][0]+=r

    if t[i]=="p":dp[i][1]+=s

  ans+=max(dp[-1])

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

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

t=eval(input())

x=list(t)

ans=0

for i in range(n):

  if x[i]=="r":x[i]="p"

  elif x[i]=="p":x[i]="s"

  else:x[i]="r"

for i in range(k):

  if x[i]=="r":ans+=r

  elif x[i]=="p":ans+=p

  else:ans+=s

for i in range(k,n):

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

    x[i]="-"

    continue

  if x[i]=="r":ans+=r

  elif x[i]=="p":ans+=p

  else:ans+=s

print(ans)
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
ss = [""] * k
ans = 0
for i in range(n):
    ss[i % k] += t[i]
for t in ss:
    m = len(t)
    dp = [[0, 0, 0] for _ in range(m)]
    # rsp
    if t[0] == "r":
        dp[0] = [0, 0, p]
    elif t[0] == "s":
        dp[0] = [r, 0, 0]
    else:
        dp[0] = [0, s, 0]
    for i in range(1, m):
        dp[i] = [
            max(dp[i - 1][1], dp[i - 1][2]),
            max(dp[i - 1][0], dp[i - 1][2]),
            max(dp[i - 1][0], dp[i - 1][1]),
        ]
        if t[i] == "r":
            dp[i][2] += p
        if t[i] == "s":
            dp[i][0] += r
        if t[i] == "p":
            dp[i][1] += s
    ans += max(dp[-1])
print(ans)

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

-ss = [""] * k +x = list(t) -    ss[i % k] += t[i] -for t in ss: -    m = len(t) -    dp = [[0, 0, 0] for _ in range(m)] -    # rsp -    if t[0] == "r": -        dp[0] = [0, 0, p] -    elif t[0] == "s": -        dp[0] = [r, 0, 0] +    if x[i] == "r": +        x[i] = "p" +    elif x[i] == "p": +        x[i] = "s" -        dp[0] = [0, s, 0] -    for i in range(1, m): -        dp[i] = [ -            max(dp[i - 1][1], dp[i - 1][2]), -            max(dp[i - 1][0], dp[i - 1][2]), -            max(dp[i - 1][0], dp[i - 1][1]), -        ] -        if t[i] == "r": -            dp[i][2] += p -        if t[i] == "s": -            dp[i][0] += r -        if t[i] == "p": -            dp[i][1] += s -    ans += max(dp[-1]) +        x[i] = "r" +for i in range(k): +    if x[i] == "r": +        ans += r +    elif x[i] == "p": +        ans += p +    else: +        ans += s +for i in range(k, n): +    if x[i] == x[i - k]: +        x[i] = "-" +        continue +    if x[i] == "r": +        ans += r +    elif x[i] == "p": +        ans += p +    else: +        ans += s