from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,pprint,fractions

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,k = inpl()

R,S,P = inpl()

a = eval(input())

res = 0

for rem in range(k):

    dp = [[0]*3 for _ in range(len(list(range(rem,n,k)))+1)]

    for i,j in enumerate(range(rem,n,k)):

        for x in range(3):

            pls = 0

            if x == 0 and a[j] == 's':

                pls += R

            if x == 1 and a[j] == 'p':

                pls += S

            if x == 2 and a[j] == 'r':

                pls += P

            for y in range(3):

                if x == y: continue

                dp[i+1][x] = max(dp[i][y]+pls, dp[i+1][x])

    # print(dp)

    res += max(dp[-1])

print(res)
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,copy

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,k = inpl()

R,S,P = inpl()

t = list(eval(input()))

di = {'r':P, 's':R, 'p':S}

res = 0

ch = True

for i in range(k):

    for j in range(i,n,k):

        if j > i and t[j] == t[j-k] and ch:

            ch = False

            continue

        res += di[t[j]]

        ch = True

        # print(i,j)

        # print(res)

print(res)
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, pprint, fractions

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, k = inpl()
R, S, P = inpl()
a = eval(input())
res = 0
for rem in range(k):
    dp = [[0] * 3 for _ in range(len(list(range(rem, n, k))) + 1)]
    for i, j in enumerate(range(rem, n, k)):
        for x in range(3):
            pls = 0
            if x == 0 and a[j] == "s":
                pls += R
            if x == 1 and a[j] == "p":
                pls += S
            if x == 2 and a[j] == "r":
                pls += P
            for y in range(3):
                if x == y:
                    continue
                dp[i + 1][x] = max(dp[i][y] + pls, dp[i + 1][x])
    # print(dp)
    res += max(dp[-1])
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, copy

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, k = inpl()
R, S, P = inpl()
t = list(eval(input()))
di = {"r": P, "s": R, "p": S}
res = 0
ch = True
for i in range(k):
    for j in range(i, n, k):
        if j > i and t[j] == t[j - k] and ch:
            ch = False
            continue
        res += di[t[j]]
        ch = True
        # print(i,j)
        # print(res)
print(res)

-import sys, bisect, math, itertools, pprint, fractions +import sys, bisect, math, itertools, fractions, copy -a = eval(input()) +t = list(eval(input())) +di = {"r": P, "s": R, "p": S} -for rem in range(k): -    dp = [[0] * 3 for _ in range(len(list(range(rem, n, k))) + 1)] -    for i, j in enumerate(range(rem, n, k)): -        for x in range(3): -            pls = 0 -            if x == 0 and a[j] == "s": -                pls += R -            if x == 1 and a[j] == "p": -                pls += S -            if x == 2 and a[j] == "r": -                pls += P -            for y in range(3): -                if x == y: -                    continue -                dp[i + 1][x] = max(dp[i][y] + pls, dp[i + 1][x]) -    # print(dp) -    res += max(dp[-1]) +ch = True +for i in range(k): +    for j in range(i, n, k): +        if j > i and t[j] == t[j - k] and ch: +            ch = False +            continue +        res += di[t[j]] +        ch = True +        # print(i,j) +        # print(res)