Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
 
def MaxScore(rsp, s):
    Score = 0
    t = list(s)
    t = t + ['t']
    for i in range(len(t)-1):
        if t[i] == t[i+1]:
            t[i+1] = 'x' + t[i+1]
    for i in range(len(t)):
        if t[i] == 'r':
            Score = Score + rsp[2]
        elif t[i] == 's':
            Score = Score + rsp[0]
        elif t[i] == 'p':
            Score = Score + rsp[1]
    return Score
 
def strsplit(n, t, k):
    tList = [""] * k
    for i in range(n):
        tList[i % k] = tList[i % k] + t[i]
    return tList
 
RSP = [R, S, P]
Answer = 0
for i in range(K):
    Answer = MaxScore(RSP, strsplit(N, T, K)[i]) + Answer
 
print(Answer)

Fixed submission:
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
 
def EarnScore(rsp, t):
    if t == 'r':
        return rsp[2]
    elif t == 's':
        return rsp[0]
    elif t == 'p':
        return rsp[1]
    else:
        return 0
 
RSP = [R, S, P]
Answer = 0
ListT = list(T)
for i in range(N):
    Answer = EarnScore(RSP, ListT[i]) + Answer
    if i + K < N:
        if ListT[i] == ListT[i+K]:
            ListT[i+K] = 'x'
 
print(Answer)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
 
def MaxScore(rsp, s):
    Score = 0
    t = list(s)
    t = t + ['t']
    for i in range(len(t)-1):
        if t[i] == t[i+1]:
            t[i+1] = 'x' + t[i+1]
    for i in range(len(t)):
        if t[i] == 'r':
            Score = Score + rsp[2]
        elif t[i] == 's':
            Score = Score + rsp[0]
        elif t[i] == 'p':
            Score = Score + rsp[1]
    return Score
 
def strsplit(n, t, k):
    tList = [""] * k
    for i in range(n):
        tList[i % k] = tList[i % k] + t[i]
    return tList
 
RSP = [R, S, P]
Answer = 0
for i in range(K):
    Answer = MaxScore(RSP, strsplit(N, T, K)[i]) + Answer
 
print(Answer)

Fixed submission:
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
 
def EarnScore(rsp, t):
    if t == 'r':
        return rsp[2]
    elif t == 's':
        return rsp[0]
    elif t == 'p':
        return rsp[1]
    else:
        return 0
 
RSP = [R, S, P]
Answer = 0
ListT = list(T)
for i in range(N):
    Answer = EarnScore(RSP, ListT[i]) + Answer
    if i + K < N:
        if ListT[i] == ListT[i+K]:
            ListT[i+K] = 'x'
 
print(Answer)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()

def MaxScore(rsp, t):
    Score = 0
    t = t + 't'
    for i in range(len(t)):
        if t[i] == t[i+1]:
            pass
        else:
            if t[i] == 'r':
                Score = Score + rsp[2]
            elif t[i] == 's':
                Score = Score + rsp[0]
            else:
                Score = Score + rsp[1]
    return Score

def strsplit(n, t, k):
    tList = [""] * k
    for i in range(n):
        tList[i % k] = tList[i % k] + t[i]
    return tList

RSP = [R, S, P]
Answer = 0
for i in range(K):
    Answer = MaxScore(RSP, strsplit(N, T, K)[i]) + Answer

print(Answer)

Fixed submission:
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
 
def EarnScore(rsp, t):
    if t == 'r':
        return rsp[2]
    elif t == 's':
        return rsp[0]
    elif t == 'p':
        return rsp[1]
    else:
        return 0
 
RSP = [R, S, P]
Answer = 0
ListT = list(T)
for i in range(N):
    Answer = EarnScore(RSP, ListT[i]) + Answer
    if i + K < N:
        if ListT[i] == ListT[i+K]:
            ListT[i+K] = 'x'
 
print(Answer)