At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:
 - The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
 - Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
 - R points for winning with Rock;
 - S points for winning with Scissors;
 - P points for winning with Paper.
 - However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.
The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

-----Notes-----
In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.
 - If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;
 - if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;
 - if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;
 - if both players play the same hand, it is a draw.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - 1 \leq K \leq N-1
 - 1 \leq R,S,P \leq 10^4
 - N,K,R,S, and P are all integers.
 - |T| = N
 - T consists of r, p, and s.

-----Input-----
Input is given from Standard Input in the following format:
N K
R S P
T

-----Output-----
Print the maximum total score earned in the game.

-----Sample Input-----
5 2
8 7 6
rsrpr

-----Sample Output-----
27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.
We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Difficulty: MEDIUM

Solutions:
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
point = {'s': r, 'p': s, 'r': p}
x = {'s': 'r', 'p': 's', 'r': 'p'}
ans = []
P = 0
for i in t:
	if len(ans) < k or ans[-k] != x[i]:
		ans.append(x[i])
		P += point[i]
	else:
		ans.append('')
print(P)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
d = {'r': P, 's': R, 'p': S}
ans = 0
for (i, v) in enumerate(T):
	if i < K:
		ans += d[v]
	elif v != T[i - K]:
		ans += d[v[0]]
	else:
		T[i] = v + 'a'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
l = [0] * n
for i in range(n):
	if t[i] == 'r':
		l[i] = p
	elif t[i] == 's':
		l[i] = r
	else:
		l[i] = s
ans = sum(l)
for i in range(k, n):
	if t[i] == t[i - k]:
		ans -= l[i]
		t[i] = 'o'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input().rstrip())
tb = {'r': p, 's': r, 'p': s}
ans = 0
for i in range(len(t)):
	if i < k:
		ans += tb[t[i]]
	elif t[i - k] == t[i]:
		t[i] = '-'
	else:
		ans += tb[t[i]]
print(ans)


(n, k) = map(int, input().split())
(s, p, r) = map(int, input().split())
t = list(input())
ans = 0
for i in range(n):
	if t[i] == 's':
		tmp = s
	elif t[i] == 'p':
		tmp = p
	else:
		tmp = r
	if i >= k:
		if t[i] == t[i - k]:
			tmp = 0
			t[i] = None
	ans += tmp
print(ans)


from itertools import groupby
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
point = {'s': r, 'p': s, 'r': p}
t = input()
ans = 0
for i in range(k):
	t_ = t[i::k]
	cnt = groupby(list(t_))
	for (te, c) in cnt:
		ans += point[te] * -(-len(list(c)) // 2)
print(ans)


def inp(r, s, p, jan):
	if jan == 's':
		return r
	elif jan == 'p':
		return s
	else:
		return p
(n, k) = map(int, input().split(' '))
(r, s, p) = map(int, input().split(' '))
t = list(input())
total = 0
for i in range(n):
	if i < k:
		total += inp(r, s, p, t[i])
	elif t[i] != t[i - k]:
		total += inp(r, s, p, t[i])
	else:
		t[i] = 'x'
print(total)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
L = input()
T = []
for i in range(N):
	T.append(L[i])
for i in range(K, N):
	if T[i] == T[i - K]:
		T[i] = '0'
p = 0
for i in T:
	if i == 'r':
		p += P
	elif i == 's':
		p += R
	elif i == 'p':
		p += S
print(p)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
p = {'r': P, 's': R, 'p': S}
T = [s for s in input()]
ans = 0
for i in range(N):
	if i >= K and T[i] == T[i - K]:
		T[i] = '.'
		continue
	ans += p[T[i]]
print(ans)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
T_split = [[] for i in range(K)]
for i in range(N):
	T_split[i % K].append(T[i])
ans = 0
flag = 0
for i in range(len(T_split)):
	for j in range(len(T_split[i])):
		if flag == 1:
			flag = 0
			continue
		if T_split[i][j] == 'r':
			point = P
		elif T_split[i][j] == 's':
			point = R
		elif T_split[i][j] == 'p':
			point = S
		ans += point
		if j != len(T_split[i]) - 1:
			if T_split[i][j] == T_split[i][j + 1]:
				flag = 1
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
d = []
for i in range(N):
	if T[i] == 'r':
		if i < K or d[i - K] != 'p':
			d.append('p')
		else:
			d.append('a')
	elif T[i] == 's':
		if i < K or d[i - K] != 'r':
			d.append('r')
		else:
			d.append('a')
	elif i < K or d[i - K] != 's':
		d.append('s')
	else:
		d.append('a')
ans = d.count('r') * R + d.count('s') * S + d.count('p') * P
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
tt = list(t)
d = {'r': p, 's': r, 'p': s}
dp = [d[t[i]] for i in range(n)]
for i in range(n - k):
	if tt[i] == tt[i + k]:
		dp[i + k] = 0
		tt[i + k] = 'x'
print(sum(dp))


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
rsp = {'r': p, 's': r, 'p': s}
ans = 0
for i in range(n):
	if i < k:
		ans += rsp[t[i]]
	elif t[i] != t[i - k]:
		ans += rsp[t[i]]
	else:
		t[i] = 'a'
print(ans)


from itertools import groupby
(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
d = {'r': P, 's': R, 'p': S}
print(sum((sum(map(lambda p: d[p[0]] * ((len(list(p[1])) + 1) // 2), groupby(T[k::K]))) for k in range(K))))


(N, K) = map(int, input().split())
score = list(map(int, input().split()))
T = input()
dp = [[0] * 3 for _ in range(N + 1)]

def judge(a, b):
	if a == 'r' and b == 2:
		return score[2]
	elif a == 's' and b == 0:
		return score[0]
	elif a == 'p' and b == 1:
		return score[1]
	return 0
for i in range(1, N + 1):
	for j in range(3):
		for k in range(3):
			if i > K:
				if j == k:
					continue
			else:
				dp[i][j] = judge(T[i - 1], j)
				continue
			dp[i][j] = max(dp[i][j], dp[i - K][k] + judge(T[i - 1], j))
ans = 0
for a in dp[-K:]:
	ans += max(a)
print(ans)


(N, K) = map(int, input().split())
dic = {}
(dic['s'], dic['p'], dic['r']) = map(int, input().split())
T = input()
score = [0] * N
for i in range(N):
	if i >= K and T[i] == T[i - K] and (score[i - K] > 0):
		continue
	score[i] = dic[T[i]]
print(sum(score))


(n, k) = map(int, input().split())
(s, p, r) = map(int, input().split())
dic = {'p': p, 'r': r, 's': s}
t = input()
ans = 0
for i in range(k):
	bef = 'a'
	for j in range(i, n, k):
		if bef == t[j]:
			bef = 'a'
		else:
			ans += dic[t[j]]
			bef = t[j]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
point = 0
for i in range(k):
	part = t[i::k]
	R = part.count('r') - part.count('rr')
	S = part.count('s') - part.count('ss')
	P = part.count('p') - part.count('pp')
	point += R * p + S * r + P * s
print(point)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T1 = input()
T2 = T1.replace('r', str(P) + ' ').replace('s', str(R) + ' ').replace('p', str(S) + ' ')[:-1]
T2 = list(map(int, T2.split()))
for i in range(N):
	if i >= K and T1[i] == T1[i - K] and (T2[i - K] != 0):
		T2[i] = 0
print(sum(T2))


(N, K) = map(int, input().split())
p = [int(x) for x in input().split()]
T = [-1] * K + [0 if x == 'r' else 1 if x == 's' else 2 for x in input()]
s = 0
for i in range(K, N + K):
	if T[i] == T[i - K]:
		T[i] = -1
	else:
		s += p[(T[i] + 2) % 3]
print(s)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = [ti for ti in input()]
score = {'z': 0, 'r': p, 's': r, 'p': s}
for i in range(k, n):
	if t[i] == t[i - k]:
		t[i] = 'z'
print(sum([score[ti] for ti in t]))


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
L = [0] * N
dic = dict()
dic['r'] = P
dic['s'] = R
dic['p'] = S
dic['0'] = 0
res = 0
for i in range(N):
	if i < N - K and T[i] == T[i + K] and (L[i] == 0):
		L[i + K] = 1
	if L[i] == 0:
		res += dic[T[i]]
print(res)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for j in range(N - K):
	if T[K + j] == T[j]:
		T[K + j] = 0
print(sum([T.count('r') * P, T.count('s') * R, T.count('p') * S]))


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
t = list(input())
q = ['q'] * K
t = t + q
s = 0
for i in range(K, N + K):
	if t[-i - 1] == t[-i - 1 + K]:
		t[-i - 1] = 'q'
		continue
	elif t[-i - 1] == 'r':
		s += P
	elif t[-i - 1] == 's':
		s += R
	elif t[-i - 1] == 'p':
		s += S
print(s)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
pt = [0 for i in range(n)]
for i in range(n):
	if t[i] == 'r':
		pt[i] = p
	elif t[i] == 's':
		pt[i] = r
	else:
		pt[i] = s
	if i >= k and t[i] == t[i - k] and (pt[i - k] > 0):
		pt[i] = 0
print(sum(pt))


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
d = {'r': p, 's': r, 'p': s}
s = input()
memo = s[:k]
ans = 0
for (i, j) in enumerate(s):
	if i < k:
		ans += d[j]
	elif memo[0] != j:
		ans += d[j]
		memo = memo[1:] + j
	else:
		memo = memo[1:] + '#'
print(ans)


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
t = input()
s = 'rsp'
dp = [[-10 ** 10] * (n + k) for _ in range(3)]
for i in range(k):
	for j in range(3):
		dp[j][i] = 0
for i in range(n):
	for j in range(3):
		for l in range(3):
			if j == l:
				continue
			res = ((s.index(t[i]) - l + 3) % 3 == 1) * p[l]
			if dp[l][i + k] < dp[j][i] + res:
				dp[l][i + k] = dp[j][i] + res
ans = 0
for i in range(n, n + k):
	ans += max(dp[0][i], dp[1][i], dp[2][i])
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list('x' * K + input())
win = {'r': P, 's': R, 'p': S, 'x': 0}
ans = 0
for i in range(len(T)):
	if T[i] == T[i - K]:
		T[i] = 'x'
	else:
		ans += win[T[i]]
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
d = {'r': P, 's': R, 'p': S}
ans = 0
for (i, c) in enumerate(T):
	if i < K or c != T[i - K]:
		ans += d[c]
		continue
	else:
		T[i] = '_'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
for i in range(k, n):
	if t[i] == t[i - k]:
		t[i] = ''
ans = t.count('r') * p + t.count('s') * r + t.count('p') * s
print(ans)


import math

def main():
	(N, K) = [int(n) for n in input().split(' ')]
	(R, S, P) = [int(p) for p in input().split(' ')]
	T = list(input())
	T.reverse()
	cnt = 0
	for i in range(K):
		tmp = []
		for j in range(math.ceil((N - i) / K)):
			if len(tmp) == 0 or T[i + j * K] != tmp[-1][0]:
				if T[i + j * K] == 'r':
					tmp.append(['r', P, 1])
				elif T[i + j * K] == 's':
					tmp.append(['s', R, 1])
				elif T[i + j * K] == 'p':
					tmp.append(['p', S, 1])
			else:
				tmp[-1][2] += 1
		for l in range(len(tmp)):
			cnt += tmp[l][1] * math.ceil(tmp[l][2] / 2)
	print(cnt)
main()


import collections
(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = list(input())
for i in range(N):
	if i + K < N and T[i] == T[i + K]:
		T[i + K] = 'x'
C = collections.Counter(T)
ans = 0
ans += C['r'] * P
ans += C['s'] * R
ans += C['p'] * S
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
l = []
for i in range(n):
	if t[i] == 'r':
		l.append(p)
	elif t[i] == 's':
		l.append(r)
	else:
		l.append(s)
score = sum(l)
for j in range(k, n):
	if t[j] == t[j - k]:
		t[j] = '-'
		score -= l[j]
print(score)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
ok = [True] * N
d = {'r': P, 's': R, 'p': S}
ans = 0
for i in range(N):
	if i >= K and T[i - K] == T[i] and ok[i - K]:
		ok[i] = False
	if ok[i]:
		ans += d[T[i]]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
ans = 0
lst = [False] * n
for i in range(n):
	if i < k or t[i] != t[i - k] or (not lst[i - k]):
		ans += p if t[i] == 'r' else r if t[i] == 's' else s
		lst[i] = True
print(ans)


(n, k) = [int(x) for x in input().split()]
(r, s, p) = [int(x) for x in input().split()]
t = list(input())
addscoremap = {'r': p, 's': r, 'p': s}
score = 0
for i in range(n):
	if 0 <= i - k and t[i] == t[i - k]:
		t[i] = 'x'
		continue
	score += addscoremap[t[i]]
print(score)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
ans = 0
check = [0] * N
for i in range(N):
	j = T[i]
	if i >= K:
		if j == check[i - K]:
			continue
	if j == 'r':
		ans += P
	elif j == 's':
		ans += R
	else:
		ans += S
	check[i] = j
print(ans)


(N, K) = [int(x) for x in input().split()]
(R, S, P) = [int(x) for x in input().split()]
T = input()
point = {'r': P, 's': R, 'p': S}
win = [False] * N
total = 0
for i in range(N):
	if i < K or T[i] != T[i - K] or win[i - K] == False:
		total += point[T[i]]
		win[i] = True
print(total)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
d = {'r': p, 's': r, 'p': s}
t = input()
ans = 0
prev = ['#' for _ in range(k)]
for (i, move) in enumerate(t):
	if prev[i % k] != move:
		ans += d[move]
		prev[i % k] = move
	else:
		prev[i % k] = '#'
print(ans)


(N, K) = map(int, input().split())
RSP = list(map(int, input().split()))
T = list(input())
rsp = ['r', 's', 'p']
for i in range(N - K):
	if T[i] == T[i + K]:
		T[i + K] = 0
print(sum((RSP[i] * T.count(rsp[(i + 1) % 3]) for i in range(3))))


(N, K) = list(map(int, input().split()))
pt = list(map(int, input().split()))
T = input()
pc_hand = [0] * N
my_hand = [0] * N
for i in range(N):
	if T[i] == 'r':
		pc_hand[i] = 0
	elif T[i] == 's':
		pc_hand[i] = 1
	else:
		pc_hand[i] = 2
point = 0
for i in range(N):
	if i >= K and T[i] == T[i - K] and ((my_hand[i - K] + 1) % 3 == pc_hand[i - K]):
		my_hand[i] = pc_hand[i]
	else:
		my_hand[i] = (pc_hand[i] - 1) % 3
		point += pt[my_hand[i]]
print(point)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
li = list(t[:k])
cnt = 0
for (itr, val) in enumerate(t):
	if itr >= k and val == li[itr % k]:
		li[itr % k] = 'x'
	else:
		if val == 'r':
			cnt += p
		elif val == 's':
			cnt += r
		else:
			cnt += s
		li[itr % k] = val
print(cnt)


(n, k) = (int(x) for x in input().split())
(r, s, p) = (int(x) for x in input().split())
t = input()
a = []
ans = 0
for i in range(0, n):
	a.append(t[i])
for j in range(0, n):
	if j - k >= 0 and a[j - k] == a[j]:
		a[j] = 'o'
	p
	if a[j] == 'r':
		ans = ans + p
	if a[j] == 's':
		ans = ans + r
	if a[j] == 'p':
		ans = ans + s
print(ans)


(n, k) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for i in range(n - k):
	if T[i] == T[i + k]:
		T[i + k] = ''
ans = 0
for i in range(n):
	if T[i] == 'r':
		ans += P
	if T[i] == 's':
		ans += R
	if T[i] == 'p':
		ans += S
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
a = {'r': p, 's': r, 'p': s}
b = [1] * n
score = 0
for i in range(n):
	if i > k - 1 and t[i] == t[i - k]:
		b[i] = 1 - b[i - k]
	score += a[t[i]] if b[i] == 1 else 0
print(score)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
me = ''
ans = 0
for i in range(n):
	if t[i] == 'r':
		if i < k:
			me += 'p'
			ans += p
		elif me[i - k] != 'p':
			me += 'p'
			ans += p
		elif t[i - k] == 'p':
			me += 'p'
			ans += p
		else:
			me += 'r'
	elif t[i] == 's':
		if i < k:
			me += 'r'
			ans += r
		elif me[i - k] != 'r':
			me += 'r'
			ans += r
		elif t[i - k] == 'r':
			me += 'r'
			ans += r
		else:
			me += 's'
	elif i < k:
		me += 's'
		ans += s
	elif me[i - k] != 's':
		me += 's'
		ans += s
	elif t[i - k] == 's':
		me += 's'
		ans += s
	else:
		me += 'p'
print(ans)


(N, K) = [int(i) for i in input().split()]
(R, S, P) = [int(i) for i in input().split()]
T = list(input())
score = [[0, 0, 0] * K]
for i in range(N - K):
	if T[i] == T[i + K]:
		T[i + K] = '.'
print(T.count('p') * S + T.count('s') * R + T.count('r') * P)


f = lambda : map(int, input().split())
(N, K) = f()
(r, s, p) = f()
T = list(input())
F = [0] * N
res = 0
for i in range(N):
	if F[i] == 1:
		continue
	if i + K < N:
		if T[i] == T[i + K]:
			F[i + K] = 1
	if T[i] == 's':
		res += r
	elif T[i] == 'p':
		res += s
	else:
		res += p
print(res)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
ret = 0
for i in range(k):
	last = 'x'
	for c in t[i::k]:
		if last != c:
			ret += p if c == 'r' else r if c == 's' else s
			last = c
		else:
			last = 'x'
print(ret)


(n, k) = map(int, input().split())
s = dict(zip('spr', map(int, input().split())))
t = list(input())
r = sum((s[h] for h in t[0:k]))
for i in range(k, n):
	if t[i - k] != t[i]:
		r += s[t[i]]
	else:
		t[i] = None
print(r)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
a = [0] * N
score = {'r': P, 's': R, 'p': S}
ans = 0
for i in range(N):
	if i + K <= N - 1:
		if a[i] == 0 and T[i] == T[i + K]:
			a[i + K] = 1
	if a[i] == 0:
		ans += score[T[i]]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
dp = [0] * (len(t) + 1)
dp[0] = 0

def pon(d):
	if d == 'r':
		return p
	elif d == 's':
		return r
	else:
		return s
m = []
for (i, j) in enumerate(t):
	m.append(j)
	if i >= k:
		if m[i - k] == j:
			dp[i + 1] = dp[i]
			m[i] = 'skip'
		else:
			dp[i + 1] = dp[i] + pon(j)
	else:
		dp[i + 1] = dp[i] + pon(j)
print(dp[-1])


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
pattern = {'r': P, 's': R, 'p': S}
ret = 0
for i in range(N):
	tmp = i - K
	if tmp >= 0 and T[tmp] == T[i]:
		T[i] = ''
		continue
	ret += pattern[T[i]]
print(ret)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
s = {'r': P, 's': R, 'p': S}
res = 0
for i in range(N):
	if i >= K:
		if T[i] == T[i - K]:
			T[i] = 0
			continue
	res += s[T[i]]
print(res)


(*n, t) = open(0).read().split()
(n, k, r, s, p) = 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, k) = map(int, input().split())
(R, S, P) = map(int, input().split())
points = {'r': P, 's': R, 'p': S}
l = list(input())
com = [''] * n
ans = 0
for (i, j) in enumerate(l):
	p = points[j]
	com[i] = j
	if i - k >= 0 and com[i] == com[i - k]:
		com[i] = ''
		p = 0
	ans += p
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
pat = {'r': p, 'p': s, 's': r, '': 0}
hands = [''] * n
ans = 0
for i in range(n):
	if i < k or hands[i - k] != t[i]:
		hands[i] = t[i]
		ans += pat[t[i]]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
T = [i for i in t]
win = ''
for i in range(len(T) - k):
	if T[i] == T[i + k]:
		T[i + k] = '#'
ans = 0
for i in T:
	if i == 'r':
		ans += p
	elif i == 's':
		ans += r
	elif i == 'p':
		ans += s
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
T = input()
cnt = 0
N = [0] * n
for i in range(n):
	if N[i] == 1:
		continue
	if i + k <= n - 1:
		if T[i] == T[i + k]:
			N[i + k] = 1
	if T[i] == 'r':
		cnt += p
	elif T[i] == 's':
		cnt += r
	else:
		cnt += s
print(cnt)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
t_list = list(t)
for i in range(n - k):
	if t_list[i] == t_list[i + k]:
		t_list[i + k] = '_'
result = t_list.count('r') * p + t_list.count('p') * s + t_list.count('s') * r
print(result)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
S = list(input())
ans = 0
rsp = [''] * n
for (i, op) in enumerate(S):
	if op == 'r':
		(me, pt) = ('p', p)
	elif op == 's':
		(me, pt) = ('r', r)
	else:
		(me, pt) = ('s', s)
	if i - k >= 0 and rsp[i - k] == me:
		(me, pt) = ('', 0)
	ans += pt
	rsp[i] = me
print(ans)


from collections import deque

def calc(t, r, s, p):
	if t == 'r':
		return p
	elif t == 's':
		return r
	else:
		return s
(n, k) = list(map(int, input().split()))
(r, s, p) = list(map(int, input().split()))
T = input()
d = deque()
ans = 0
for (i, t) in enumerate(T):
	if i < k:
		ans += calc(t, r, s, p)
		d.append(t)
	else:
		x = d.popleft()
		if x == t:
			d.append(0)
		else:
			ans += calc(t, r, s, p)
			d.append(t)
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
ans = [0] * n
for (i, c) in enumerate(t):
	if i >= k and c == t[i - k] and (ans[i - k] > 0):
		continue
	if c == 'r':
		ans[i] = p
	elif c == 's':
		ans[i] = r
	else:
		ans[i] = s
print(sum(ans))


import math
import bisect
(N, K) = list(map(int, input().split(' ')))
(r, s, p) = list(map(int, input().split(' ')))
di = {}
di['r'] = p
di['s'] = r
di['p'] = s
di['@'] = 0
T = input()
T = list(T)
for i in range(K, N):
	if T[i - K] == T[i]:
		T[i] = '@'
ans = 0
for temp in T:
	ans += di[temp]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
cnt = {'r': 0, 's': 0, 'p': 0}
for i in range(n):
	if i <= k - 1:
		cnt[t[i]] += 1
	elif t[i] == t[i - k]:
		t[i] = 'o'
		continue
	else:
		cnt[t[i]] += 1
ans = p * cnt['r'] + r * cnt['s'] + s * cnt['p']
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
for a in range(n - k):
	if t[k + a] == t[a]:
		t[k + a] = 0
x = t.count('r') * p + t.count('s') * r + t.count('p') * s
print(x)


import collections
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
for j in range(k, len(t)):
	if t[j] == t[j - k]:
		t[j] = ''
ts = collections.Counter(t)
print(ts['p'] * s + ts['s'] * r + ts['r'] * p)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
sco = {'r': P, 's': R, 'p': S}
T = input()
B = [-1] * N
ans = 0
for i in range(N):
	if i < K:
		ans += sco[T[i]]
	elif T[i] != T[i - K]:
		ans += sco[T[i]]
	elif B[i - K] == -1:
		B[i] = 0
	else:
		ans += sco[T[i]]
print(ans)


def main():
	(n, k) = list(map(int, input().split()))
	(r, s, p) = list(map(int, input().split()))
	t = input()
	c = ''
	ans = 0
	for i in range(n):
		if t[i] == 'r':
			if i >= k and c[i - k] == 'p':
				c += 'x'
			else:
				c += 'p'
				ans += p
		elif t[i] == 's':
			if i >= k and c[i - k] == 'r':
				c += 'x'
			else:
				c += 'r'
				ans += r
		elif i >= k and c[i - k] == 's':
			c += 'x'
		else:
			c += 's'
			ans += s
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
for i in range(K, N):
	if T[i] == T[i - K] and T[i - K] != 'x':
		T = T[:i] + 'x' + T[i + 1:]
	else:
		continue
R_win = T.count('s')
S_win = T.count('p')
P_win = T.count('r')
point = R_win * R + S_win * S + P_win * P
print(point)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
d = {'r': P, 's': R, 'p': S}
T = input()
ans = 0
for i in range(min(N, K)):
	flag = 0
	tmp = T[i::K]
	for j in range(len(tmp) - 1):
		if tmp[j] != tmp[j + 1] or flag:
			ans += d[tmp[j]]
			flag = 0
		else:
			flag = 1
	ans += d[tmp[-1]]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
res = 0
for i in range(n):
	if i > k - 1 and t[i - k] == t[i]:
		t[i] = 'n'
	if t[i] == 'r':
		res += p
	elif t[i] == 's':
		res += r
	elif t[i] == 'p':
		res += s
print(res)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = str(input())
dic = {'r': p, 's': r, 'p': s}
b = [1] * n
ans = 0
for i in range(n):
	if i > k - 1 and t[i] == t[i - k]:
		b[i] -= b[i - k]
	ans += dic[t[i]] if b[i] == 1 else 0
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
d = {'r': P, 's': R, 'p': S}
ans = 0
for i in range(N):
	if i < K:
		ans += d[T[i]]
	elif T[i] != T[i - K]:
		ans += d[T[i]]
	else:
		T[i] = 'z'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = str(input())
t_list = [c for c in t]
for i in range(k, n):
	if t_list[i] == t_list[i - k]:
		t_list[i] = 'x'
score = 0
for hand in t_list:
	if hand == 'r':
		score += p
	elif hand == 's':
		score += r
	elif hand == 'p':
		score += s
print(score)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
score_list = []
ans = 0
for i in range(K):
	pre_word = 'dummy'
	for j in range(i, N, K):
		if T[j] != pre_word:
			if T[j] == 'r':
				ans += P
				pre_word = 'r'
			elif T[j] == 's':
				ans += R
				pre_word = 's'
			else:
				ans += S
				pre_word = 'p'
		else:
			pre_word = 'dummy'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
T = input()
rsp = {'r': p, 'p': s, 's': r}
ans = [-1] * n
for i in range(n):
	if ans[i] == -1:
		p = rsp[T[i]]
		ans[i] = p
		if i + k < n:
			if T[i] == T[i + k]:
				ans[i + k] = 0
print(sum(ans))


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
read_data = input()
res = 0
log = []
for i in range(len(read_data)):
	if len(log) < k:
		if read_data[i] == 'r':
			res += p
		if read_data[i] == 's':
			res += r
		if read_data[i] == 'p':
			res += s
		log.append(read_data[i])
	else:
		tmp = log.pop(0)
		if tmp != read_data[i]:
			if read_data[i] == 'r':
				res += p
			if read_data[i] == 's':
				res += r
			if read_data[i] == 'p':
				res += s
			log.append(read_data[i])
		else:
			log.append('-')
print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20

def I():
	return int(input())

def F():
	return float(input())

def S():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LS():
	return input().split()

def resolve():
	(N, K) = LI()
	RSP_score = LI()
	rsp_num = {'r': 0, 's': 1, 'p': 2}
	T = [rsp_num[i] for i in S()]
	dp = [[0] * 3 for _ in range(N)]
	for i in range(N):
		for j in range(3):
			if i - K >= 0:
				dp[i][j] += max([dp[i - K][k] for k in range(3) if k != j])
			if (j + 1) % 3 == T[i]:
				dp[i][j] += RSP_score[j]
	ans = sum([max(i) for i in dp[N - K:]])
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(n, k) = list(map(int, input().split()))
(r, s, p) = list(map(int, input().split()))
t = list(input())
win = {'r': p, 's': r, 'p': s}
res = 0
for i in range(n - k):
	if t[i + k] == t[i]:
		t[i + k] = 0
for i in range(n):
	if t[i] != 0:
		res += win[t[i]]
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = input()
before = ['a'] * k
dic = {'r': a[2], 's': a[0], 'p': a[1]}
ans = 0
for (i, s) in enumerate(l):
	i = i % k
	if before[i] != s:
		ans += dic[s]
		before[i] = s
	else:
		before[i] = 'a'
print(ans)


(n, k) = map(int, input().split())
d = dict()
(d['s'], d['p'], d['r']) = map(int, input().split())
T = list(input())
ans = 0
for i in range(len(T)):
	if i - k >= 0 and T[i - k] == T[i]:
		T[i] = '*'
	else:
		ans += d[T[i]]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
point = {'r': p, 's': r, 'p': s}
log = ['' for _ in range(k)]
ans = 0
for (i, play) in enumerate(t):
	if play == log[i % k]:
		log[i % k] = ''
		continue
	log[i % k] = play
	ans += point[play]
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
D = {'r': P, 's': R, 'p': S}
result = ['none'] * N
ans = 0
for i in range(N):
	if i < K:
		ans += D[T[i]]
		result[i] = T[i]
	elif T[i] != result[i - K]:
		ans += D[T[i]]
		result[i] = T[i]
print(ans)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, K) = list(map(int, readline().split()))
	point = list(map(int, readline().split()))
	T = readline().strip()
	T = list(map(int, T.translate(str.maketrans('rsp', '012'))))
	hand = [0] * N
	ans = 0
	for (i, h) in enumerate(T):
		win = (h - 1) % 3
		if i >= K and win == hand[i - K]:
			hand[i] = -1
		else:
			hand[i] = win
			ans += point[win]
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
d = {'r': p, 's': r, 'p': s}
ans = 0
for i in range(k):
	pa = ''
	while i < n:
		if t[i] == pa:
			pa = ''
		else:
			ans += d[t[i]]
			pa = t[i]
		i += k
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for i in range(N - K):
	if T[i] == T[i + K]:
		T[i + K] = '@'
dic1 = {'r': P, 's': R, 'p': S, '@': 0}
points = 0
for i in range(N):
	points += dic1[T[i]]
print(points)


from collections import deque
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
point = {}
point['r'] = r
point['s'] = s
point['p'] = p
t = input()

def janken(opp, rireki, point, k):
	if opp == 'r':
		rireki.append('p')
		return point['p']
	elif opp == 's':
		rireki.append('r')
		return point['r']
	elif opp == 'p':
		rireki.append('s')
		return point['s']
ans = 0
rireki = deque()
for i in range(n):
	hand = t[i]
	ans += janken(hand, rireki, point, k)
for i in range(k, n):
	if rireki[i] == rireki[i - k]:
		ans -= point[rireki[i]]
		rireki[i] = 'else'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
dict = {'r': p, 's': r, 'p': s}
val = 0
for i in range(n):
	if i < k:
		val += dict[t[i]]
	elif t[i - k] != t[i]:
		val += dict[t[i]]
	else:
		t[i] = ' '
print(val)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
hand = {'r': p, 's': r, 'p': s}
ans = 0
for n_ in range(n):
	temp = n_ - k
	if temp >= 0 and t[n_] == t[temp]:
		t[n_] = ''
	else:
		ans += hand[t[n_]]
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
trans = {'r': 'p', 's': 'r', 'p': 's'}
score = {'r': R, 's': S, 'p': P, 't': 0}
a = [trans[t] for t in T]
for i in range(K, N):
	if a[i] == a[i - K]:
		a[i] = 't'
print(sum([score[s] for s in a]))


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
d = {'r': p, 's': r, 'p': s}
t = input()
ans = 0
for i in range(k):
	bef = None
	for c in t[i::k]:
		if c == bef:
			bef = None
			pass
		else:
			ans += d[c]
			bef = c
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()

def janken(n):
	if n == 'r':
		return P
	elif n == 's':
		return R
	else:
		return S
ans = 0
for i in range(K):
	h = T[i::K]
	l = len(h)
	f = 1
	a = ''
	for j in range(l):
		if a != h[j]:
			a = h[j]
			f = 0
			ans += janken(h[j])
		else:
			ans += f * janken(h[j])
			f = -(f - 1)
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
(r, s, p) = (0, 0, 0)
for i in range(N):
	if i - K >= 0 and T[i - K] == T[i]:
		T[i] = None
	elif T[i] == 'r':
		p += 1
	elif T[i] == 's':
		r += 1
	elif T[i] == 'p':
		s += 1
print(r * R + s * S + p * P)


(n, k) = list(map(int, input().split()))
(r, s, p) = list(map(int, input().split()))
t = input()
ans = 0
for i in range(k):
	(R, S, P) = (0, 0, 0)
	for hand in t[i::k]:
		if hand == 'r':
			(R, S, P) = (max(S, P), max(R, P), max(R, S) + p)
		elif hand == 's':
			(R, S, P) = (max(S, P) + r, max(R, P), max(R, S))
		elif hand == 'p':
			(R, S, P) = (max(S, P), max(R, P) + s, max(R, S))
	ans += max(R, S, P)
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(str(input()))
for i in range(N - K):
	if T[K + i] == T[i]:
		T[K + i] = 'x'
Rc = T.count('r')
Sc = T.count('s')
Pc = T.count('p')
count = P * Rc + S * Pc + R * Sc
print(count)


(N, K) = map(int, input().split())
points = list(map(int, input().split()))
hand = {'r': 0, 's': 1, 'p': 2}
T = [hand[t] for t in input()]
win = [False] * N
ans = 0
for i in range(N):
	if i < K or T[i] != T[i - K] or (not win[i - K]):
		win[i] = True
		ans += points[(T[i] + 2) % 3]
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input() + '*' * K
h = [''] * N
(f, n) = ('', '')
ans = 0
for i in range(N):
	if K <= i:
		f = h[i - K]
	n = T[i + K]
	if T[i] == 'r':
		if f == 'p':
			h[i] = n
		else:
			ans += P
			h[i] = 'p'
	if T[i] == 'p':
		if f == 's':
			h[i] = n
		else:
			ans += S
			h[i] = 's'
	if T[i] == 's':
		if f == 'r':
			h[i] = n
		else:
			ans += R
			h[i] = 'r'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
ans = 0
D = {'r': p, 's': r, 'p': s}
for i in range(n):
	if i - k < 0 or t[i] != t[i - k]:
		ans += D[t[i]]
	else:
		t[i] = 'n'
print(ans)


def jan(x, a, b, c):
	if x == 's':
		return a
	elif x == 'r':
		return c
	else:
		return b
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
r = int(r)
s = int(s)
p = int(p)
t = list(input())
m = [0] * n
ans = 0
for i in range(n):
	if i >= k:
		if t[i] == t[i - k]:
			if m[i - k] == 1:
				ans += jan(t[i], r, s, p)
			else:
				m[i] = 1
		else:
			ans += jan(t[i], r, s, p)
	else:
		ans += jan(t[i], r, s, p)
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
dic = {}
dic['r'] = p
dic['s'] = r
dic['p'] = s
ans = sum([dic[s] for s in t])
for i in range(k, len(t)):
	if t[i - k] == t[i]:
		ans -= dic[t[i]]
		t = t[:i] + 'a' + t[i + 1:]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
T = list(input())
for i in range(k, n):
	if T[i] == T[i - k]:
		T[i] = 'x'
answer = 0
for t in T:
	if t == 'r':
		answer += p
	elif t == 's':
		answer += r
	elif t == 'p':
		answer += s
print(answer)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
pattern = {'r': p, 's': r, 'p': s, '': 0}
ans = 0
for i in range(n):
	tmp = i - k
	if tmp >= 0 and t[tmp] == t[i]:
		t[i] = ''
	ans += pattern[t[i]]
print(ans)


from array import array
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = array('u', list(input()))
for i in range(k, n):
	if t[i] == t[i - k]:
		t[i] = '*'
ans = t.count('r') * p + t.count('s') * r + t.count('p') * s
print(ans)


from collections import deque
(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
Tlist = input()
Answer = 0

def po(x):
	if x == 's':
		return R
	elif x == 'r':
		return P
	else:
		return S
for i in range(K):
	TK = list(Tlist[i::K]).copy()
	TK.append('')
	T2 = TK[0]
	sig = 2
	for i in range(1, len(TK)):
		T1 = T2
		T2 = TK[i]
		if T1 == T2 and i != len(TK) - 1:
			sig += 1
		else:
			Answer += po(T1) * (sig // 2)
			sig = 2
print(Answer)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, K) = list(map(int, readline().split()))
	point = list(map(int, readline().split()))
	T = readline().strip()
	T = T.translate(str.maketrans('rsp', '012'))
	T = list(map(int, T))
	ans = 0
	for i in range(K):
		vec = T[i::K]
		M = len(vec)
		dp = [[0] * 3 for _ in range(M + 1)]
		for j in range(M):
			for k in range(3):
				dp[j + 1][k] = max(dp[j][(k + 1) % 3], dp[j][(k + 2) % 3])
				if (k + 1) % 3 == vec[j]:
					dp[j + 1][k] += point[k]
		ans += max(dp[M])
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
get_score = list(map(int, input().split()))
t = list(input())
dic = {'r': 0, 's': 1, 'p': 2}
ans = 0
for i in range(n):
	if t[i] == 'D':
		continue
	if i + k < n and t[i] == t[i + k]:
		t[i + k] = 'D'
	ans += get_score[(dic[t[i]] + 2) % 3]
print(ans)


def main():
	(N, K) = list(map(int, input().split()))
	(R, S, P) = list(map(int, input().split()))
	T = input()
	dict = {'r': P, 's': R, 'p': S}
	check = []
	ans = 0
	for i in range(N):
		if i - K < 0:
			ans += dict[T[i]]
			check.append(1)
		elif T[i - K] != T[i]:
			ans += dict[T[i]]
			check.append(1)
		elif T[i - K] == T[i]:
			if i - 2 * K < 0:
				ans += 0
				check.append(0)
			elif T[i - 2 * K] == T[i]:
				if check[i - K] == 1:
					ans += 0
					check.append(0)
				else:
					ans += dict[T[i]]
					check.append(1)
			else:
				ans += 0
				check.append(0)
	return ans
print(main())


(n, k) = map(int, input().split())
(gu, choki, pa) = map(int, input().split())
t = list(input())
total = 0
for (i, v) in enumerate(t):
	if i >= k and v == t[i - k]:
		t[i] = 'd'
	elif v == 'r':
		total += pa
	elif v == 's':
		total += gu
	else:
		total += choki
print(total)


from itertools import groupby
(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
D = {'r': P, 's': R, 'p': S}
T = list(input())
c = 0
for i in range(K):
	gr = groupby(T[i::K])
	for (key, group) in gr:
		l = len(list(group))
		d = D[key]
		c += d * ((l + 1) // 2)
print(c)


(n, k) = map(int, input().split())
p = [int(i) for i in input().split()]
t = list(input())
a = 0
for i in range(n):
	if i < k or t[i] != t[i - k]:
		a += p['spr'.index(t[i])]
	else:
		t[i] = 'q'
print(a)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for n in range(N - K):
	if T[n + K] == T[n]:
		T[n + K] = ''
print(P * T.count('r') + R * T.count('s') + S * T.count('p'))


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
dic = {'r': p, 's': r, 'p': s}
score = 0
for i in range(n):
	if t[i] == 0:
		continue
	score += dic[t[i]]
	if i + k < n and t[i + k] == t[i]:
		t[i + k] = 0
print(score)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
point = {'r': p, 's': r, 'p': s}
ans = 0
for start in range(k):
	prev = 'nil'
	for e in t[start::k]:
		if e != prev:
			ans += point[e]
			prev = e
		else:
			prev = 'nil'
print(ans)


(a, b, t) = open(0)
(n, k) = map(int, a.split())
(r, s, p) = map(int, b.split())
d = {'r': ('p', p), 's': ('r', r), 'p': ('s', s)}
command = [0] * n
point = 0
for (i, s) in enumerate(list(t.strip())):
	(c, q) = d[s]
	if i - k >= 0 and command[i - k] == c:
		continue
	command[i] = c
	point += q
print(point)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
x = 0
for i in range(len(t)):
	if i >= k and t[i] == t[i - k]:
		t[i] = ' '
	if t[i] == 'r':
		x += p
	elif t[i] == 's':
		x += r
	elif t[i] == 'p':
		x += s
print(x)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for i in range(K, N, 1):
	if T[i] == T[i - K]:
		T[i] = 'NG'
R2 = T.count('r')
S2 = T.count('s')
P2 = T.count('p')
print(P * R2 + R * S2 + S * P2)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
X = {'r': P, 's': R, 'p': S}
win = [False] * K
ans = 0
for i in range(N):
	if i < K or T[i] != T[i - K] or (not win[i % K]):
		ans += X[T[i]]
		win[i % K] = True
	else:
		win[i % K] = False
print(ans)


import sys
(n, k) = map(int, sys.stdin.readline().split())
(r, s, p) = map(int, sys.stdin.readline().split())
t = sys.stdin.readline()
ans = 0
for i in range(k, n):
	if t[i] == t[i - k]:
		t = t[:i] + 'a' + t[i + 1:]
ans = t.count('r') * p + t.count('s') * r + t.count('p') * s
print(ans)


(n, k) = map(int, input().split())
scores = list(map(int, input().split()))
t = [0 if i == 'r' else 1 if i == 's' else 2 for i in input()]
score = 0
no = [-1 for i in t]
for (i, x) in enumerate(t):
	if no[i] != x:
		score += scores[x - 1]
		try:
			no[i + k] = x
		except:
			pass
print(score)


from itertools import groupby as gb
(n, k, g, t, p, s) = map(lambda v: v if v[0] in 'rsp' else int(v), open(0).read().split())
(r, ss, pa) = (0, 0, 0)
l = [''] * k
for (x, i) in enumerate(list(s)):
	if l[x % k] == i:
		l[x % k] = ''
		continue
	if i == 'r':
		pa += 1
	elif i == 's':
		r += 1
	else:
		ss += 1
	l[x % k] = i
print(r * g + ss * t + pa * p)


import math
(n, k) = map(int, input().split(' '))
(r, s, p) = map(int, input().split(' '))
t = input()
w = {'r': p, 's': r, 'p': s}
li = [0 for _ in range(n)]
for i in range(len(t)):
	wp = w[t[i]]
	if not (i - k >= 0 and li[i - k] == wp and (t[i] == t[i - k])):
		li[i] = wp
print(sum(li))


(N, K) = [int(_) for _ in input().split()]
(R, S, P) = [int(_) for _ in input().split()]
T = input()
s = {'r': P, 's': R, 'p': S}
score = []
for i in range(N):
	if i < K:
		score.append(s[T[i]])
		continue
	if T[i] == T[i - K] and score[i - K] != 0:
		score.append(0)
	else:
		score.append(s[T[i]])
print(sum(score))


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
array = [''] * k
for i in range(n):
	array[i % k] += t[i]
a = 0
for l in array:
	l = l.replace('rr', 'r0').replace('ss', 's0').replace('pp', 'p0')
	a += p * l.count('r') + r * l.count('s') + s * l.count('p')
print(a)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
win = {'r': ['p', P], 's': ['r', R], 'p': ['s', S]}
hands = []
tot = 0
for (i, c) in enumerate(T):
	if i >= K and win[c][0] == hands[i - K]:
		hands.append('anything')
		continue
	hands.append(win[c][0])
	tot += win[c][1]
print(tot)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = [i for i in input()]
ans = 0
for i in range(n):
	if i >= k and t[i] == t[i - k]:
		t[i] = 'o'
		continue
	if t[i] == 'r':
		ans += p
	elif t[i] == 's':
		ans += r
	else:
		ans += s
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
P = {'r': P, 's': R, 'p': S}
score = [-1 for _ in range(N)]
for (i, t) in enumerate(T):
	if i < K:
		score[i] = P[t]
	elif t == T[i - K] and score[i - K] != 0:
		score[i] = 0
	else:
		score[i] = P[t]
print(sum(score))


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


(n, k) = (int(w) for w in input().split()[:2])
(r, s, p) = (int(w) for w in input().split()[:3])
t = input()
h = {'r': 'p', 's': 'r', 'p': 's'}
score = {'r': r, 's': s, 'p': p, 'e': 0}
z = [h[c] for c in t]
for i in range(k, n):
	if z[i] == z[i - k]:
		z[i] = 'e'
x = sum((score[v] for v in z))
print(x)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
arr = [0] * N
d = {'r': P, 's': R, 'p': S}
for (i, t) in enumerate(T):
	if i - K >= 0:
		if T[i - K] != t:
			arr[i] = d[t]
		elif arr[i - K] == 0:
			arr[i] = d[t]
	else:
		arr[i] = d[t]
print(sum(arr))


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
ans = 0
for i in range(0, K):
	rsp_K = T[i::K]
	rsp_before = ''
	for rsp in rsp_K:
		if rsp == 'r':
			if rsp_before != 'r':
				ans += P
				rsp_before = 'r'
			else:
				rsp_before = ''
		elif rsp == 's':
			if rsp_before != 's':
				ans += R
				rsp_before = 's'
			else:
				rsp_before = ''
		elif rsp == 'p':
			if rsp_before != 'p':
				ans += S
				rsp_before = 'p'
			else:
				rsp_before = ''
print(ans)


(n, k) = (int(_) for _ in input().split())
(R, S, P) = (int(_) for _ in input().split())
t = list(input())
a = {'r': P, 's': R, 'p': S, 'f': 0}
Q = n // k
q = n % k
ans = 0
for i in range(n):
	ans += a[t[i]]
for i in range(k, n):
	if t[i] == t[i - k]:
		ans -= a[t[i - k]]
		if t[i - k] is not 'f':
			t[i] = 'f'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
for i in range(n - k):
	if t[i] == t[i + k]:
		t[i + k] = '0'
rr = t.count('s')
ss = t.count('p')
pp = t.count('r')
print(rr * r + ss * s + pp * p)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
hand = {'r': P, 's': R, 'p': S}
ans = 0
for i in range(K):
	s = str()
	tmp = i
	while tmp < N:
		s += T[tmp]
		tmp += K
	count = 1
	prev = str()
	for j in range(len(s)):
		if s[j] == prev:
			count += 1
		else:
			count = 1
		if count % 2 == 0:
			continue
		prev = s[j]
		ans += hand[s[j]]
print(ans)


import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
P = {'s': R, 'p': S, 'r': P, 'N': 0}
score = 0
for i in range(N):
	if i + K < N:
		if T[i] == T[i + K]:
			T[i + K] = 'N'
	score += P[T[i]]
print(score)


(n, k) = map(int, input().split())
score_dict = dict(zip('spr', map(int, input().split())))
t = list(input())
score = sum([score_dict[h] for h in t[:k]])
for i in range(k, n):
	if t[i] != t[i - k]:
		score += score_dict[t[i]]
	else:
		t[i] = None
print(score)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	(n, k) = map(int, input().split())
	(r, s, p) = map(int, input().split())
	t = input()
	dp = [[0] * 3 for _ in range(n + k)]
	for i1 in range(k):
		i2 = i1 + k
		while i2 - k < n:
			dp[i2][0] = max(dp[i2 - k][1], dp[i2 - k][2])
			dp[i2][0] += r if t[i2 - k] == 's' else 0
			dp[i2][1] = max(dp[i2 - k][0], dp[i2 - k][2])
			dp[i2][1] += s if t[i2 - k] == 'p' else 0
			dp[i2][2] = max(dp[i2 - k][0], dp[i2 - k][1])
			dp[i2][2] += p if t[i2 - k] == 'r' else 0
			i2 += k
	r = 0
	for j1 in range(-k, 0, 1):
		r += max(dp[j1])
	print(r)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
(s, p, r) = map(int, input().split())
t = input()
u = [0] * k
tt = [[p, r, s][(x == 'r') + 2 * (x == 's')] for x in t]
ans = 0
for i in range(n):
	if u[i % k] == 0:
		ans += tt[i]
		u[i % k] = 1
	elif not t[i] == t[i - k]:
		ans += tt[i]
	else:
		u[i % k] = 0
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
s = input()
d = {'r': P, 's': R, 'p': S}
dd = set()
r = 0
for i in range(N):
	r += d[s[i]]
	if i >= K:
		if i - K not in dd:
			if s[i - K] == s[i]:
				dd.add(i)
				r -= d[s[i]]
print(r)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
ans = 0
for i in range(k):
	u = t[i::k]
	u = u.replace('rr', 'rx')
	u = u.replace('pp', 'px')
	u = u.replace('ss', 'sx')
	ans += u.count('s') * r
	ans += u.count('p') * s
	ans += u.count('r') * p
print(ans)


import copy
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
T = list(input())
for i in range(n - k):
	if T[i] == T[i + k]:
		T[i + k] = 'x'
cr = T.count('r')
cp = T.count('p')
cs = T.count('s')
print(cp * s + cr * p + cs * r)


import sys
input = sys.stdin.readline

def main():
	(N, K) = map(int, input().split())
	(R, S, P) = map(int, input().split())
	T = list(input().rstrip())
	D = [[] for _ in range(K)]
	for (i, t) in enumerate(T):
		D[i % K].append(t)
	ans = 0
	for List in D:
		pre = -1
		for (i, p) in enumerate(List):
			if p == 'r':
				s = P
			elif p == 's':
				s = R
			else:
				s = S
			if pre != p:
				ans += s
				pre = p
			else:
				pre = -1
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
(a, b, c) = map(int, input().split())
t = input()
d = {'r': c, 's': a, 'p': b}
ans = 0
for i in range(n):
	if i < k:
		ans += d[t[i]]
	elif t[i] != t[i - k]:
		ans += d[t[i]]
	else:
		t = t[:i] + 'z' + t[i + 1:]
print(ans)


from itertools import groupby
(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
C = {'s': R, 'r': P, 'p': S}
ans = 0
for i in range(K):
	A = T[i::K]
	ans += sum(((len(tuple(v)) + 1) // 2 * C[k] for (k, v) in groupby(A)))
print(ans)


import os
import sys
from collections import Counter

def main():
	(N, K) = list(map(int, input().split()))
	(R, S, P) = list(map(int, input().split()))
	T = input()
	takahashi = ''
	for t in T:
		if t == 's':
			takahashi += 'r'
		elif t == 'p':
			takahashi += 's'
		else:
			takahashi += 'p'
	for i in range(K, N):
		if takahashi[i - K] == takahashi[i]:
			takahashi = takahashi[:i] + '_' + takahashi[i + 1:]
	ans = takahashi.count('r') * R + takahashi.count('s') * S + takahashi.count('p') * P
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
win = {'r': P, 's': R, 'p': S}
tmp = [1] * N
ans = 0
for i in range(N):
	if i < K:
		ans += win[T[i]]
		tmp[i] = 0
	elif T[i] != T[i - K] or tmp[i - K]:
		ans += win[T[i]]
		tmp[i] = 0
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
sc = 0
for i in range(n):
	if i + k < n and t[i] == t[i + k]:
		t[i + k] = 'x'
print(t.count('r') * p + t.count('p') * s + t.count('s') * r)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
Pred = []
dp = []
for i in range(K, N):
	if T[i] == T[i - K]:
		T[i] = 'x'
	else:
		continue
x = T.count('r')
y = T.count('s')
z = T.count('p')
print(P * x + R * y + S * z)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
q = str(input())
mukou = [0] * n
ans = 0
for i in range(n):
	if i >= k:
		if q[i] == q[i - k] and mukou[i - k] == 0:
			mukou[i] = 1
for i in range(n):
	if mukou[i] == 0:
		if q[i] == 'r':
			ans += p
		elif q[i] == 's':
			ans += r
		else:
			ans += s
print(ans)


(N, K) = map(int, input().split())
(S, P, R) = map(int, input().split())
point = {'s': S, 'p': P, 'r': R}
T = str(input())
max_point = 0
for i in range(K):
	while i < N:
		if i + K < N and T[i] == T[i + K]:
			max_point += point[T[i]]
			i = i + 2 * K
		else:
			max_point += point[T[i]]
			i = i + K
print(max_point)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
a = 0
for i in range(k):
	l = 'z'
	m = 0
	for c in t[i::k]:
		if c == l:
			m += 1
		else:
			if l == 'r':
				a += p * (m // 2)
			elif l == 's':
				a += r * (m // 2)
			elif l == 'p':
				a += s * (m // 2)
			l = c
			m = 2
	else:
		if l == 'r':
			a += p * (m // 2)
		elif l == 's':
			a += r * (m // 2)
		elif l == 'p':
			a += s * (m // 2)
print(a)


import copy
(N, K) = list(map(int, input().split()))
(my_R, my_S, my_P) = list(map(int, input().split()))
hand_score = {'r': my_P, 's': my_R, 'p': my_S}
T = input()
ans = 0
for i in range(K):
	cnt = (N - i - 1) // K + 1
	dp = {'R': 0, 'S': 0, 'P': 0}
	new_dp = {'R': 0, 'S': 0, 'P': 0}
	for j in range(cnt):
		check = {'r': 0, 's': 0, 'p': 0}
		check[T[j * K + i]] = hand_score[T[j * K + i]]
		new_dp['R'] = max(dp['S'] + check['s'], dp['P'] + check['p'])
		new_dp['S'] = max(dp['P'] + check['p'], dp['R'] + check['r'])
		new_dp['P'] = max(dp['R'] + check['r'], dp['S'] + check['s'])
		dp = copy.copy(new_dp)
	ans += max(dp.values())
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
taka = ''
ans = 0
for i in range(N):
	if i >= K:
		if T[i] == taka[i - K]:
			taka += 'n'
			continue
	if T[i] == 'r':
		ans += P
		taka += 'r'
	elif T[i] == 's':
		ans += R
		taka += 's'
	else:
		ans += S
		taka += 'p'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
res_list = {'r': 'p', 's': 'r', 'p': 's'}
t = input()
res = [0] * n
ans = 0
for (i, rsp) in enumerate(t):
	res_rsp = res_list[rsp]
	if i < k or res[i - k] != res_rsp:
		ans += eval(res_rsp)
		res[i] = res_rsp
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for i in range(N - K):
	if T[K + i] == T[i]:
		T[K + i] = 'x'
ans = T.count('r') * P + T.count('s') * R + T.count('p') * S
print(ans)


(n, k) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
dict = {'r': 'p', 's': 'r', 'p': 's'}
hand = []
for t in T:
	hand.append(dict[t])
for i in range(n - k):
	if hand[i] == hand[i + k]:
		hand[i + k] = 'x'
ans = 0
for t in hand:
	if t == 'r':
		ans += R
	elif t == 's':
		ans += S
	elif t == 'p':
		ans += P
print(ans)


def decide_hand2(T, hand, i, K, N):
	if T[i] == 'r':
		if i <= K - 1:
			hand[i] = 'p'
		elif hand[i - K] == 'p':
			hand[i] = '-'
		else:
			hand[i] = 'p'
	elif T[i] == 'p':
		if i <= K - 1:
			hand[i] = 's'
		elif hand[i - K] == 's':
			hand[i] = '-'
		else:
			hand[i] = 's'
	elif T[i] == 's':
		if i <= K - 1:
			hand[i] = 'r'
		elif hand[i - K] == 'r':
			hand[i] = '-'
		else:
			hand[i] = 'r'

def main():
	(N, K) = map(int, input().split())
	(R, S, P) = map(int, input().split())
	T = input()
	hand = ['' for _ in range(N)]
	for i in range(N):
		decide_hand2(T, hand, i, K, N)
	ans = 0
	for i in range(N):
		if hand[i] == 'r':
			ans += R
		elif hand[i] == 's':
			ans += S
		elif hand[i] == 'p':
			ans += P
	print(ans)

def __starting_point():
	main()
__starting_point()


import collections
(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
for i in range(N - K):
	if T[i] == T[i + K]:
		T[i + K] = 'a'
c = collections.Counter(T)
print(c['r'] * P + c['s'] * R + c['p'] * S)


(n, k) = [int(i) for i in input().split(' ')]
(r, s, p) = [int(i) for i in input().split(' ')]
t = list(input())
score = {'r': p, 's': r, 'p': s, 'l': 0}
ans = 0
for i in range(n):
	ans += score[t[i]]
	if i + k < n and t[i] == t[i + k]:
		t[i + k] = 'l'
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
st = input()
for i in range(len(st) - 1):
	if i + k > len(st) - 1:
		break
	elif st[i] == st[i + k]:
		st = st[:i + k] + 'n' + st[i + k + 1:]
win = r * st.count('s') + s * st.count('p') + p * st.count('r')
print(win)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
ans = [''] * N
point = 0
for (i, t) in enumerate(T):
	if t == 'r':
		ans_tmp = 'p'
		point_tmp = P
	elif t == 's':
		ans_tmp = 'r'
		point_tmp = R
	elif t == 'p':
		ans_tmp = 's'
		point_tmp = S
	if i - K >= 0:
		if ans[i - K] == ans_tmp:
			ans_tmp = ''
			point_tmp = 0
	ans[i] = ans_tmp
	point += point_tmp
print(point)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
point = {'r': P, 's': R, 'p': S}
T = input()
res = [0 for _ in range(N)]
for (i, t) in enumerate(T):
	if i - K < 0 or (i - K >= 0 and (res[i - K] == 0 or T[i - K] != T[i])):
		res[i] = point[t]
print(sum(res))


(N, K) = map(int, input().split(' '))
(R, S, P) = map(int, input().split(' '))
T = list(input())
score = 0
A = T
for i in range(N - K):
	if T[i] == T[i + K]:
		A[i + K] = 'a'
for i in range(N):
	if A[i] == 'r':
		score += P
	elif A[i] == 's':
		score += R
	elif A[i] == 'p':
		score += S
print(score)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
check = [0] * N
ans = 0
for i in range(N):
	if i < K or T[i] != T[i - K] or (not check[i - K]):
		ans += P if T[i] == 'r' else R if T[i] == 's' else S
		check[i] = 1
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
dp = [0] * n
a = {'r': p, 's': r, 'p': s}
for i in range(n):
	if i >= k and t[i] == t[i - k]:
		dp[i] = 0
		t[i] = 'x'
	else:
		dp[i] = a[t[i]]
print(sum(dp))


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
points = 0
for i in range(K, N):
	if T[i] == T[i - K]:
		T = T[:i] + '#' + T[i + 1:]
for i in range(N):
	if T[i] == 'r':
		points += P
	elif T[i] == 's':
		points += R
	elif T[i] == 'p':
		points += S
print(points)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
score = {'s': R, 'p': S, 'r': P}
ans = 0
for o in range(K):
	pre = 'X'
	for i in range(o, N, K):
		h = T[i]
		if h != pre:
			ans += score[h]
			pre = h
		else:
			pre = 'X'
print(ans)


(N, K) = (int(i) for i in input().split())
(R, S, P) = (int(i) for i in input().split())
T = input()
ans = 0
d = {}
d['r'] = P
d['s'] = R
d['p'] = S
rens = [0] * N
for i in range(N):
	if i >= K and T[i - K] == T[i]:
		rens[i] = rens[i - K] + 1
	if rens[i] % 2 == 0:
		ans += d[T[i]]
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = 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
		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 = input()
win = [False] * n

def janken(char):
	if char == 'r':
		return p
	elif char == 's':
		return r
	else:
		return s
cnt = 0
for i in range(n):
	if i - k < 0:
		point = janken(t[i])
		cnt += point
		win[i] = True
	elif t[i] != t[i - k]:
		point = janken(t[i])
		cnt += point
		win[i] = True
	elif not win[i - k]:
		point = janken(t[i])
		cnt += point
		win[i] = True
print(cnt)


(N, K) = list(map(int, input().split()))
(R, S, P) = list(map(int, input().split()))
T = input()
cnt = [0 for _ in range(N)]
score = {'r': P, 's': R, 'p': S}
for i in range(N):
	if i < K:
		cnt[i] = score[T[i]]
	elif T[i - K] != T[i]:
		cnt[i] = score[T[i]]
	elif cnt[i - K] == 0:
		cnt[i] = score[T[i]]
print(sum(cnt))


(n, k) = map(int, input().split())
B = list(map(int, input().split()))
S = list(input())
A = [[] for i in range(k)]
for i in range(n):
	if S[i] == 's':
		A[i % k].append(0)
	elif S[i] == 'p':
		A[i % k].append(1)
	else:
		A[i % k].append(2)
ans = 0
for i in range(k):
	f = 0
	for j in range(len(A[i])):
		if f == 0:
			ans = ans + B[A[i][j]]
			if j != len(A[i]) - 1:
				if A[i][j] == A[i][j + 1]:
					f = 1
		else:
			f = 0
print(ans)


(n, k) = list(map(int, input().split()))
(r, s, p) = list(map(int, input().split()))
T = input()
record = [False for _ in range(n)]
ans = 0

def win(t):
	if t == 'r':
		return p
	elif t == 's':
		return r
	else:
		return s
for (i, t) in enumerate(T):
	if i < k:
		ans += win(t)
		record[i] = t
	else:
		f = record[i - k]
		if f:
			if f == t:
				continue
			else:
				ans += win(t)
				record[i] = t
		else:
			ans += win(t)
			record[i] = t
print(ans)


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]
import string

def main():
	(n, k) = i_map()
	(r, s, p) = i_map()
	dic = {'r': p, 's': r, 'p': s}
	t = list(s_input())
	ans = 0
	for (i, j) in enumerate(t):
		if i < k:
			ans += dic[j]
		elif j != t[i - k]:
			ans += dic[j]
		else:
			t[i] = 'z'
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = 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)


from itertools import groupby
from math import ceil
(*A, T) = open(0).read().split()
(n, k, r, s, p) = map(int, A)
T = T.strip()
d = {'r': p, 's': r, 'p': s}
X = [T[i::k] for i in range(k)]
s = 0
for x in X:
	for (key, rep) in groupby(x):
		s += d[key] * ceil(len(list(rep)) / 2)
print(s)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = list(input())
graph = {'r': P, 's': R, 'p': S, '*': 0}
for (i, t) in enumerate(T):
	if len(T) - i - K > 0:
		if t == T[i + K]:
			T[i + K] = '*'
ans = 0
for t in T:
	ans += graph[t]
print(ans)


(n, k) = map(int, input().split())
(s, p, r) = map(int, input().split())
t = input()
cnt = 0
for i in range(k):
	f = 0
	pre = ''
	for j in range(i, n, k):
		if pre != t[j] or f == 1:
			cnt += eval(t[j])
			f = 0
		else:
			f = 1
		pre = t[j]
print(cnt)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
Pt = [0, p, r, s]
Ans = [0] * k
Prev = [0] * k
for i in range(n):
	if t[i] == 'r':
		cur = 1
	elif t[i] == 's':
		cur = 2
	else:
		cur = 3
	ii = i % k
	if Prev[ii] == cur:
		Prev[ii] = 0
	else:
		Ans[ii] += Pt[cur]
		Prev[ii] = cur
print(sum(Ans))


def main():
	(N, K) = list(map(int, input().split()))
	(R, S, P) = list(map(int, input().split()))
	T = input()
	command = [''] * N
	ans = 0
	for (i, t) in enumerate(T):
		if t == 'r':
			point = P
			command_candidate = 'p'
		elif t == 's':
			point = R
			command_candidate = 'r'
		else:
			point = S
			command_candidate = 's'
		if i >= K and command[i - K] == command_candidate:
			point = 0
			command_candidate = ''
		ans += point
		command[i] = command_candidate
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
ans = 0
for i in range(k):
	R = 0
	S = 0
	P = 0
	cnt = 0
	while i + cnt * k < n:
		if i + cnt * k - k < 0:
			if t[i + cnt * k] == 'r':
				ans += p
				P = 1
			elif t[i + cnt * k] == 's':
				ans += r
				R = 1
			else:
				ans += s
				S = 1
		elif i + cnt * k - k >= 0 and t[i + cnt * k] == t[i + cnt * k - k]:
			if t[i + cnt * k] == 'r' and P == 0:
				ans += p
				P = 1
			elif t[i + cnt * k] == 'r' and P == 1:
				P = 0
			elif t[i + cnt * k] == 's' and R == 0:
				ans += r
				R = 1
			elif t[i + cnt * k] == 's' and R == 1:
				R = 0
			elif t[i + cnt * k] == 'p' and S == 0:
				ans += s
				S = 1
			elif t[i + cnt * k] == 'p' and S == 1:
				S = 0
		elif i + cnt * k - k >= 0 and t[i + cnt * k] != t[i + cnt * k - k]:
			if t[i + cnt * k] == 'r':
				ans += p
				P = 1
			elif t[i + cnt * k] == 's':
				ans += r
				R = 1
			else:
				ans += s
				S = 1
		cnt += 1
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
dic = {'r': p, 's': r, 'p': s}
t = list(input())
ans = 0
for i in range(len(t)):
	if i < k:
		ans += dic[t[i]]
	elif not t[i - k] == t[i]:
		ans += dic[t[i]]
	else:
		t[i] = 'x'
print(ans)


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

def score(hand):
	if hand == 's':
		return r
	if hand == 'p':
		return s
	if hand == 'r':
		return p
ans = 0
changed = [0] * n
for i in range(n):
	if i >= k and t[i] == t[i - k] and (changed[i - k] == 0):
		changed[i] = 1
		continue
	ans += score(t[i])
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = [_ for _ in str(input())]
ans = 0
for i in range(n):
	if i - k < 0:
		if t[i] == 'r':
			ans += p
		elif t[i] == 's':
			ans += r
		elif t[i] == 'p':
			ans += s
	elif t[i] == 'r' and t[i - k] != 'r':
		ans += p
	elif t[i] == 's' and t[i - k] != 's':
		ans += r
	elif t[i] == 'p' and t[i - k] != 'p':
		ans += s
	else:
		t[i] = 'a'
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
score_dic = {'r': R, 's': S, 'p': P}
win_dic = {'r': 'p', 's': 'r', 'p': 's'}
T = list(input())
score = 0
for i in range(0, N, 1):
	if i >= K and T[i - K] == T[i]:
		T[i] = 'm'
	else:
		score += score_dic[win_dic[T[i]]]
print(score)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
c = [''] * n
ans = 0
for i in range(n):
	if t[i] == 'r':
		rsp = 'p'
		point = p
	elif t[i] == 's':
		rsp = 'r'
		point = r
	elif t[i] == 'p':
		rsp = 's'
		point = s
	if i >= k and c[i - k] == rsp:
		rsp = ''
		point = 0
	c[i] = rsp
	ans += point
print(ans)


from collections import deque
(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
d = {'s': r, 'p': s, 'r': p}
before = deque([])
ans = 0
for i in range(n):
	if i < k:
		before.append(t[i])
		ans += d[t[i]]
	else:
		b = before.popleft()
		if t[i] != b:
			before.append(t[i])
			ans += d[t[i]]
		else:
			before.append('n')
print(ans)


(n, k) = map(int, input().split())
S = list(map(int, input().split()))
s = input()
T = [s[i::k] for i in range(k)]
a = 0
for t in T:
	b = 'x'
	for c in t:
		if c != b:
			a += S['spr'.index(c)]
			b = c
		else:
			b = 'x'
print(a)


(a, b) = map(int, input().split())
(c, d, e) = map(int, input().split())
g = input()
l = a - b
for i in range(l):
	if g[i] == g[i + b]:
		g = g[:i + b] + 'a' + g[i + 1 + b:]
else:
	R = g.count('r')
	S = g.count('s')
	P = g.count('p')
	answer = c * S + d * P + e * R
	print(answer)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
s = input()
ans = 0
for i in range(k, n):
	if s[i] == s[i - k]:
		s = s[:i] + 'z' + s[i + 1:]
for i in range(n):
	ans += a['sprz'.index(s[i])]
print(ans)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
st = list(input())
for i in range(n - k):
	if st[i] == st[i + k]:
		st[i + k] = 'no'
win = r * st.count('s') + s * st.count('p') + p * st.count('r')
print(win)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
d = {'r': p, 's': r, 'p': s}
t = input()
mode = [True] * n
score = 0
for i in range(n):
	score += d[t[i]]
	if i >= k and mode[i - k] and (t[i] == t[i - k]):
		score -= d[t[i]]
		mode[i] = False
print(score)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
hands = {'r': r, 's': s, 'p': p}
win = {'r': p, 's': r, 'p': s}
t = input()
ans = []
for i in range(n):
	c = t[i]
	if i - k >= 0 and t[i - k] == c and ans[i - k]:
		ans.append(0)
	else:
		ans.append(win[c])
print(sum(ans))


(n, k) = map(int, input().split())
scores = {k: v for (k, v) in zip('spr', map(int, input().split()))}
zero_score_index = set()
t = input()
total = sum((scores[tt] for tt in t))
for i in range(n):
	if i < k:
		continue
	if t[i] == t[i - k] and i - k not in zero_score_index:
		zero_score_index.add(i)
		total -= scores[t[i]]
print(total)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = input()
point = {'r': (p, 'p'), 's': (r, 'r'), 'p': (s, 's')}
ans = 0
hand = ''
for i in range(n):
	if i < k:
		ans += point[t[i]][0]
		hand += point[t[i]][1]
	elif t[i - k] != t[i]:
		ans += point[t[i]][0]
		hand += point[t[i]][1]
	elif hand[i - k] != point[t[i]][1]:
		ans += point[t[i]][0]
		hand += point[t[i]][1]
	elif i + k < n:
		hand += 'rsp'.replace(point[t[i + k]][1], '').replace(hand[i - k], '')[0]
	else:
		hand += 'rsp'.replace(hand[i - k], '')[0]
print(ans)


(n, k) = map(int, input().split())
(rp, sp, pp) = map(int, input().split())
p = {'r': pp, 's': rp, 'p': sp}
t = [s for s in input()]
ans = 0
for i in range(n):
	if i >= k and t[i] == t[i - k]:
		t[i] = '.'
		continue
	ans += p[t[i]]
print(ans)


(n, k) = (int(a) for a in input().split())
(r, s, p) = (int(a) for a in input().split())
T = list(input())
point = 0
for i in range(n):
	if i < k:
		pass
	elif T[i] == T[i - k]:
		T[i] = 0
a = T.count('r')
b = T.count('s')
c = T.count('p')
print(a * p + r * b + c * s)


(n, k) = map(int, input().split())
(r, s, p) = map(int, input().split())
t = list(input())
rsp = {'r': p, 's': r, 'p': s}
sumt = 0
chk = [1] * n
for i in range(len(t)):
	sumt += rsp[t[i]]
	if i >= k and t[i] == t[i - k]:
		chk[i] = chk[i - k] + 1
		chk[i - k] = 1
ans = sumt
for i in range(len(chk)):
	if chk[i] != 1:
		chg = chk[i] // 2
		ans -= rsp[t[i]] * chg
print(ans)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
dic = {'r': P, 's': R, 'p': S}
flag = [0] * N
rlt = 0
T = input()
for i in range(N):
	if i < K or T[i] != T[i - K] or flag[i - K] == 1:
		rlt += dic[T[i]]
	else:
		flag[i] = 1
print(rlt)


(N, K) = map(int, input().split())
(R, S, P) = map(int, input().split())
T = input()
moi = [['x'] for i in range(K)]
for i in range(N):
	moi[i % K].append(T[i])
for i in range(K):
	moi[i].pop(0)
moji = ''
for i in range(K):
	cnt = 0
	for j in range(len(moi[i])):
		if j == 0:
			moji += moi[i][j]
		else:
			if moi[i][j - 1] != moi[i][j]:
				moji += moi[i][j]
				cnt = 0
			if moi[i][j - 1] == moi[i][j] and cnt == 1:
				moji += moi[i][j]
				cnt = 0
			elif moi[i][j - 1] == moi[i][j] and cnt == 0:
				cnt += 1
ans = 0
for i in range(len(moji)):
	if moji[i] == 'r':
		ans += P
	elif moji[i] == 's':
		ans += R
	else:
		ans += S
print(ans)