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

x=list(map(int,input().split()))

t=eval(input())

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

for i in range(n):

    if t[i]=="r":

        y[i%k].append(2)

    elif t[i]=="s":

        y[i%k].append(0)

    else:

        y[i%k].append(1)



def groupby(a):

    a2=[[a[0],1]]

    for i in range(1,len(a)):

        if a2[-1][0]==a[i]:

            a2[-1][1]+=1

        else:

            a2.append([a[i],1])

    return a2

c=0

for i in range(k):

    z=groupby(y[i])

    l=len(z)

    for j in range(l):

        c+=(x[z[j][0]]*((z[j][1]+1)//2))

print(c)

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

dp=[[0,0,0] for i in range(n)]

janken=list(map(int,input().split( )))

t=[0 if i=="r" else 1 if i=="s" else 2 for i in eval(input())]

#直後の手を見て決める

for i in range(n):

    if i<k:

        for j in range(3):

            if (j+1)%3==t[i]:

                dp[i][j]=janken[j]

    else:

        #更新

        for j in range(3):

            #遷移の元

            for l in range(3):

                if j!=l:

                    if (j+1)%3==t[i]:

                        dp[i][j]=max(dp[i][j],janken[j]+dp[i-k][l])

                    else:

                        dp[i][j]=max(dp[i][j],dp[i-k][l])

ans=0

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

    ans+=max(dp[i])

print(ans)
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
t = eval(input())
y = [[] for i in range(k)]
for i in range(n):
    if t[i] == "r":
        y[i % k].append(2)
    elif t[i] == "s":
        y[i % k].append(0)
    else:
        y[i % k].append(1)


def groupby(a):
    a2 = [[a[0], 1]]
    for i in range(1, len(a)):
        if a2[-1][0] == a[i]:
            a2[-1][1] += 1
        else:
            a2.append([a[i], 1])
    return a2


c = 0
for i in range(k):
    z = groupby(y[i])
    l = len(z)
    for j in range(l):
        c += x[z[j][0]] * ((z[j][1] + 1) // 2)
print(c)

n, k = list(map(int, input().split()))
dp = [[0, 0, 0] for i in range(n)]
janken = list(map(int, input().split()))
t = [0 if i == "r" else 1 if i == "s" else 2 for i in eval(input())]
# 直後の手を見て決める
for i in range(n):
    if i < k:
        for j in range(3):
            if (j + 1) % 3 == t[i]:
                dp[i][j] = janken[j]
    else:
        # 更新
        for j in range(3):
            # 遷移の元
            for l in range(3):
                if j != l:
                    if (j + 1) % 3 == t[i]:
                        dp[i][j] = max(dp[i][j], janken[j] + dp[i - k][l])
                    else:
                        dp[i][j] = max(dp[i][j], dp[i - k][l])
ans = 0
for i in range(n - k, n):
    ans += max(dp[i])
print(ans)

-x = list(map(int, input().split())) -t = eval(input()) -y = [[] for i in range(k)] +dp = [[0, 0, 0] for i in range(n)] +janken = list(map(int, input().split())) +t = [0 if i == "r" else 1 if i == "s" else 2 for i in eval(input())] +# 直後の手を見て決める -    if t[i] == "r": -        y[i % k].append(2) -    elif t[i] == "s": -        y[i % k].append(0) +    if i < k: +        for j in range(3): +            if (j + 1) % 3 == t[i]: +                dp[i][j] = janken[j] -        y[i % k].append(1) - - -def groupby(a): -    a2 = [[a[0], 1]] -    for i in range(1, len(a)): -        if a2[-1][0] == a[i]: -            a2[-1][1] += 1 -        else: -            a2.append([a[i], 1]) -    return a2 - - -c = 0 -for i in range(k): -    z = groupby(y[i]) -    l = len(z) -    for j in range(l): -        c += x[z[j][0]] * ((z[j][1] + 1) // 2) -print(c) +        # 更新 +        for j in range(3): +            # 遷移の元 +            for l in range(3): +                if j != l: +                    if (j + 1) % 3 == t[i]: +                        dp[i][j] = max(dp[i][j], janken[j] + dp[i - k][l]) +                    else: +                        dp[i][j] = max(dp[i][j], dp[i - k][l]) +ans = 0 +for i in range(n - k, n): +    ans += max(dp[i]) +print(ans)