*n,t=open(0).read().split()

n,k,r,s,p=list(map(int,n))

d={'r':p,'s':r,'p':s}

b=['']*n*2

a=0

for i,c in enumerate(t[:n]):

  if c!=b[i-k]:

    b[i]=c

    a+=d[c]

print(a)
*n,t=open(0).read().split()

n,k,r,s,p=list(map(int,n))

*t,=t

for i in range(n-k):

  if t[i+k]==t[i]:t[i+k]=5

a,b,c=list(map(t.count,'rsp'))

print((a*p+b*r+c*s))
*n, t = open(0).read().split()
n, k, r, s, p = list(map(int, n))
d = {"r": p, "s": r, "p": s}
b = [""] * n * 2
a = 0
for i, c in enumerate(t[:n]):
    if c != b[i - k]:
        b[i] = c
        a += d[c]
print(a)

*n, t = open(0).read().split()
n, k, r, s, p = list(map(int, n))
(*t,) = t
for i in range(n - k):
    if t[i + k] == t[i]:
        t[i + k] = 5
a, b, c = list(map(t.count, "rsp"))
print((a * p + b * r + c * s))

-d = {"r": p, "s": r, "p": s} -b = [""] * n * 2 -a = 0 -for i, c in enumerate(t[:n]): -    if c != b[i - k]: -        b[i] = c -        a += d[c] -print(a) +(*t,) = t +for i in range(n - k): +    if t[i + k] == t[i]: +        t[i + k] = 5 +a, b, c = list(map(t.count, "rsp")) +print((a * p + b * r + c * s))