human
I found an interesting problem on https://atcoder.jp/contests/abc149/tasks/abc149_d:
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...

I tried it in Python, but could not do it. Can you solve it?

Give me a Python program to print the maximum total score earned in the game?
assistant
#Here is Python program to print the maximum total score earned in the game.

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

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)