Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
R, S, P = (int(i) for i in input().split())
T = input()
hands = []
a = ['r', 's', 'p']

def add(s):
    if s == 'r': return P
    if s == 's': return R
    else: return S
   
def win(s):
    if s == 'r': return 'p'
    if s == 's': return 'r'
    else: return 's'
         
point = 0
for i in range(N):
    if i < K: 
        hands.append(win(T[i]))
        point += add(T[i])
    else:
        if win(T[i]) != hands[i-K]:
            hands.append(win(T[i]))
            point += add(T[i])
        else:
            if i+K < N:
                a.remove(win(T[i+K]))
                a.remove(win(T[i]))
                hands.append(a[0])
                a = ['r', 's', 'p']
            else:
                hands.append(T[i])

print(point)

Fixed submission:
N, K = (int(i) for i in input().split())
R, S, P = (int(i) for i in input().split())
T = input()
hands = []
a = ['r', 's', 'p']

def add(s):
    if s == 'r': return P
    if s == 's': return R
    else: return S
   
def win(s):
    if s == 'r': return 'p'
    if s == 's': return 'r'
    else: return 's'
         
point = 0
for i in range(N):
    if i < K: 
        hands.append(win(T[i]))
        point += add(T[i])
    else:
        if win(T[i]) != hands[i-K]:
            hands.append(win(T[i]))
            point += add(T[i])
        else:
            if i+K < N:
                a.remove(win(T[i]))
                if win(T[i+K]) != win(T[i]):
                    a.remove(win(T[i+K]))
                
                hands.append(a[0])
                a = ['r', 's', 'p']
            else:
                hands.append(T[i])

print(point)

Buggy python submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
R, S, P = (int(i) for i in input().split())
T = input()
hands = []

def add(s):
    if s == 'r': return P
    if s == 's': return R
    else: return S
   
def win(s):
    if s == 'r': return 'p'
    if s == 's': return 'r'
    else: return 's'
         
point = 0
for i in range(N):
    if i < K: 
        hands.append(win(T[i]))
        point += add(T[i])
    else:
        if win(T[i]) != hands[i-K]:
            hands.append(win(T[i]))
            point += add(T[i])
        else:
            if i+K < N:
                a = int('r')+int('s')+int('p')
                a -= int(win(T[i])+int(win(T[i+K])))
                hands.append(str(a))
            else:
                hands.append(T[i])

print(point)

Fixed submission:
N, K = (int(i) for i in input().split())
R, S, P = (int(i) for i in input().split())
T = input()
hands = []
a = ['r', 's', 'p']

def add(s):
    if s == 'r': return P
    if s == 's': return R
    else: return S
   
def win(s):
    if s == 'r': return 'p'
    if s == 's': return 'r'
    else: return 's'
         
point = 0
for i in range(N):
    if i < K: 
        hands.append(win(T[i]))
        point += add(T[i])
    else:
        if win(T[i]) != hands[i-K]:
            hands.append(win(T[i]))
            point += add(T[i])
        else:
            if i+K < N:
                a.remove(win(T[i]))
                if win(T[i+K]) != win(T[i]):
                    a.remove(win(T[i+K]))
                
                hands.append(a[0])
                a = ['r', 's', 'p']
            else:
                hands.append(T[i])

print(point)