qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
r, s, p = LI()
D = {'r': p, 'p': s, 's': r}
t = S()
flag = [1] * n
ans = 0
for i in range(n):
    if i <= k:
        ans += D[t[i]]
    else:
        if t[i - k] == t[i] and flag[i - k]:
            flag[i] = 0
        else:
            ans += D[t[i]]



print(ans)







Fixed code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
r, s, p = LI()
D = {'r': p, 'p': s, 's': r}
t = S()
flag = [1] * n
ans = 0
for i in range(n):
    if i <= k - 1:
        ans += D[t[i]]
    else:
        if t[i - k] == t[i] and flag[i - k]:
            flag[i] = 0
        else:
            ans += D[t[i]]



print(ans)
Buggy code:
n,k = map(int, input().split())
r,s,p = map(int, input().split())
S = input()
ans = 0
for i in range(k):
    Ssep = S[i::k] 
    flg = False
    for j in range(len(Ssep)):
        if j >= 1 and Ssep[j] == Ssep[j-1] and not flg:
            flg = True
            continue
        if Ssep[j] == "r":
            ans += p
        if Ssep[j] == "s":
            ans += r
        if Ssep[j] == "p":
            ans += s
        flg = False
    print(Ssep,ans)
print(ans)

Fixed code:
n,k = map(int, input().split())
r,s,p = map(int, input().split())
S = input()
ans = 0
for i in range(k):
    Ssep = S[i::k] 
    flg = False
    for j in range(len(Ssep)):
        if j >= 1 and Ssep[j] == Ssep[j-1] and not flg:
            flg = True
            continue
        if Ssep[j] == "r":
            ans += p
        if Ssep[j] == "s":
            ans += r
        if Ssep[j] == "p":
            ans += s
        flg = False
print(ans)
Buggy code:
#149d

def win(n):
	if n=='r':
		return p
	elif n=='s':
		return r
	else:
		return s

n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
score=0
for i in t:
	score += win(i)

#hands=list(t)

for i in range(n):
	if i+k<n:
		if t[i]==t[i+k]:
			score-=win(t[i+k])
			t[i+k]='x'
print(score)

Fixed code:

def win(n):
	if n=='r':
		return p
	elif n=='s':
		return r
	else:
		return s

n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
score=0
for i in t:
	score += win(i)

hands=list(t)

for i in range(n):
	if i+k<n:
		if hands[i]==hands[i+k]:
			score-=win(hands[i+k])
			hands[i+k]='x'
print(score)
Buggy code:
n, k = map(int, input().split(' '))
r, s, p = map(int, input().split(' '))
t = input()

dasita_te = []

score = 0

for i, c in enumerate(t):
    if c == "r":
        if (i >= k and dasita_te[i - k] != "p") or i < k:
            score += p
            dasita_te.append("p")
        else:
            dasita_te.append("-")
    elif c == "s":
        if (i >= k and dasita_te[i - k] != "r") or i < k:
            score += r
            dasita_te.append("r")
        else:
            dasita_te.append("-")
    elif c == "p":
        if (i >= k and dasita_te[i - k] != "s") or i < k:
            score += s
            dasita_te.append("s")
        else:
            dasita_te.append("-")
    print(i, score)

print(score)


Fixed code:
n, k = map(int, input().split(' '))
r, s, p = map(int, input().split(' '))
t = input()

dasita_te = []

score = 0

for i, c in enumerate(t):
    if c == "r":
        if (i >= k and dasita_te[i - k] != "p") or i < k:
            score += p
            dasita_te.append("p")
        else:
            dasita_te.append("-")
    elif c == "s":
        if (i >= k and dasita_te[i - k] != "r") or i < k:
            score += r
            dasita_te.append("r")
        else:
            dasita_te.append("-")
    elif c == "p":
        if (i >= k and dasita_te[i - k] != "s") or i < k:
            score += s
            dasita_te.append("s")
        else:
            dasita_te.append("-")

print(score)
Buggy code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=[i for i in input()]
H=[]
sum=0
if N<=K:
    for i in T:
        if i=="r":
            sum+=P
        elif i=="s":
            sum+=R
        else:
            sum+=S
else:
    for i in range(K):
        if T[i]=="r":
            H.append("p")
            sum+=P
        elif T[i]=="s":
            H.append("r")
            sum+=R
        else:
            H.append("s")
            sum+=S
    for i in range(K,N):
        if T[i]=="r" and H[i-K]=="p":
            if (i+K)<N and T[i+K]=="p":
                H.append("s")
            else:
                H.append("r")
            
        elif T[i]=="r":
            H.append("p")
            sum+=P
        elif T[i]=="s" and H[i-K]=="r":
            if (i+K)<N and T[i+K]=="r":
                H.append("p")
            else:    
                H.append("s")
        elif T[i]=="s":
            H.append("r")
            sum+=R
        elif T[i]=="p" and H[i-K]=="s":
            if (i+K)<N and T[i+K]=="s":
                H.append("r")
            else:    
                H.append("p")
        elif T[i]=="p":
            H.append("s")
            sum+=S
print(sum)            

Fixed code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=[i for i in input()]
H=[]
sum=0
if N<=K:
    for i in T:
        if i=="r":
            sum+=P
        elif i=="s":
            sum+=R
        else:
            sum+=S
else:
    for i in range(K):
        if T[i]=="r":
            H.append("p")
            sum+=P
        elif T[i]=="s":
            H.append("r")
            sum+=R
        else:
            H.append("s")
            sum+=S
    for i in range(K,N):
        if T[i]=="r" and H[i-K]=="p":
            if (i+K)<N and T[i+K]=="p":
                H.append("r")
            else:
                H.append("s")
            
        elif T[i]=="r":
            H.append("p")
            sum+=P
        elif T[i]=="s" and H[i-K]=="r":
            if (i+K)<N and T[i+K]=="r":
                H.append("s")
            else:    
                H.append("p")
        elif T[i]=="s":
            H.append("r")
            sum+=R
        elif T[i]=="p" and H[i-K]=="s":
            if (i+K)<N and T[i+K]=="s":
                H.append("p")
            else:    
                H.append("r")
        elif T[i]=="p":
            H.append("s")
            sum+=S
print(sum)
Buggy code:
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 code:
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 code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
kr = 1
ks= 1
kp = 1
Is = 0
Ir=0
Ip=0
A =[]

for i in range(n):
  if i-k < 0:
      A.append(1)
      if t[i] == "r":
        kr = 1
        ans += p
      elif t[i] == "s":
        ks=1
        ans += r
      else:
        kp=1
        ans += s
  else:
    if t[i] != t[i-k]:
      if t[i] == "r":
        kr=1
        ans += p
        Ir = i
        A[i%k]=1
      elif t[i] == "s":
        ans += r
        ks=1
        Is = i
        A[i%k]=1
      else:
        kp=1
        ans += s
        A[i%k]=1
    else:
      if t[i] == "r":
        if A[i%k] == 0:
          ans+=p
          A[i%k] = 1
        else:
            A[i%k]  = 0
      elif t[i] == "s":
        if A[i%k] ==0:
          ans += r
          A[i%k] = 1
        else:
            A[i%k] = 0
      else:
        if A[i%k]==0:
          ans+=s
          kp=1
          Ip = i
          A[i%k] = 1
        else: 
            A[i%k] = 0
  print(ans,t[i],A,i+1)
      
print(ans)

Fixed code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
kr = 1
ks= 1
kp = 1
Is = 0
Ir=0
Ip=0
A =[]

for i in range(n):
  if i-k < 0:
      A.append(1)
      if t[i] == "r":
        kr = 1
        ans += p
      elif t[i] == "s":
        ks=1
        ans += r
      else:
        kp=1
        ans += s
  else:
    if t[i] != t[i-k]:
      if t[i] == "r":
        kr=1
        ans += p
        Ir = i
        A[i%k]=1
      elif t[i] == "s":
        ans += r
        ks=1
        Is = i
        A[i%k]=1
      else:
        kp=1
        ans += s
        A[i%k]=1
    else:
      if t[i] == "r":
        if A[i%k] == 0:
          ans+=p
          A[i%k] = 1
        else:
            A[i%k]  = 0
      elif t[i] == "s":
        if A[i%k] ==0:
          ans += r
          A[i%k] = 1
        else:
            A[i%k] = 0
      else:
        if A[i%k]==0:
          ans+=s
          kp=1
          Ip = i
          A[i%k] = 1
        else: 
            A[i%k] = 0
      
print(ans)
Buggy code:
from collections import defaultdict as DD
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

D = DD(int)
D["s"] = R
D["p"] = S
D["r"] = P

ans = 0
C = DD(int)
for i in range(N):
  C["s"] = C["s"]-1
  C["p"] = C["p"]-1
  C["r"] = C["r"]-1
  if C[T[i]] != 0:
    ans +=  D[T[i]]
    if C[T[i]] < 0 : C[T[i]] = K
print (ans)

Fixed code:
from collections import defaultdict as DD
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

D = DD(int)
D["s"] = R
D["p"] = S
D["r"] = P

ans = 0
C = [0 for i in range(N)]
for i in range(N):
  if i < K:
    ans +=  D[T[i]]
    C[i] = 1    
  elif T[i-K] == T[i]:
    if C[i-K] != 1:
      ans +=  D[T[i]]
      C[i] = 1
  else:
      ans +=  D[T[i]]
      C[i] = 1    
print (ans)
Buggy code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T= input()
def score(x):
  if x == 'r':
    return P
  elif x == 's':
    return R
  elif x == 'p':
    return S
  else:
    return 0
s = 0
for t in range(len(T)-1):
  if T[t] == T[t+1]:
    T[t+1] = 'z'
  s += score(T[t])
print(s)  

Fixed code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T= input()
def score(x):
  if x == 'r':
    return P
  elif x == 's':
    return R
  elif x == 'p':
    return S
  else:
    return 0
s = 0
List = [x for x in T]
for t in range(len(T)-K):
  if List[t] == List[t+K]:
    List[t+K] = 'z' 
for y in List:  
  s += score(y)
print(s)
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

mp_score = {"r": P, "s": R, "p": S}

lines = [""] * K
for ix in range(K):
    for t in range(len(T)):
        if t%K == ix:
            lines[ix] += T[t]

print(lines)
ans = 0
for l in lines:
    before = ""
    for c in l:
        if before == c:
            before = ""

        else:
            ans += mp_score[c]
            before = c

print(ans)
        

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

mp_score = {"r": P, "s": R, "p": S}

lines = [""] * K
for ix in range(len(T)):
    lines[ix%K] += T[ix]

ans = 0
for l in lines:
    before = ""
    for c in l:
        if before == c:
            before = ""

        else:
            ans += mp_score[c]
            before = c

print(ans)
Buggy code:
n, k = (int(x) for x in input().split())
r, s, p = (int(x) for x in input().split())
t_ch = input()
t=[]
for i in range(n):
    t.append(t_ch[i])


for i in range(k-1, n):
    if t[i] == t[i-k]:
        t[i]=0
print(t)
for i in range(0,n):
    if t[i]=="r":
        t[i]=p
    elif t[i]=="p":
        t[i]=s
    elif t[i]=="s":
        t[i]=r
print(sum(t))    


Fixed code:
n, k = (int(x) for x in input().split())
r, s, p = (int(x) for x in input().split())
t_ch = input()
t=[]
for i in range(n):
    t.append(t_ch[i])

for i in range(k, n):
    if t[i] == t[i-k]:
        t[i]=0
for i in range(0,n):
    if t[i]=="r":
        t[i]=p
    elif t[i]=="p":
        t[i]=s
    elif t[i]=="s":
        t[i]=r
print(sum(t))
Buggy code:
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()
ans=0
for i in range(k):
  u=s[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)

Fixed code:
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)
Buggy code:
from collections import deque

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

best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''

while t:
    cpu = t.popleft()
    
    if len(ban) < 2:
        add_hand = best_hand[cpu]
    else:
        ban_hand = ban.pop(0)
        if best_hand[cpu] == ban_hand:
            add_hand = 'e'
        else:
            add_hand = best_hand[cpu]
    ban.append(add_hand)
    cand += add_hand
    
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))

Fixed code:
from collections import deque

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

best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''

while t:
    cpu = t.popleft()
    
    if len(ban) < k:
        add_hand = best_hand[cpu]
    else:
        ban_hand = ban.pop(0)
        if best_hand[cpu] == ban_hand:
            add_hand = 'e'
        else:
            add_hand = best_hand[cpu]
    ban.append(add_hand)
    cand += add_hand
    
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))
Buggy code:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()

ans=[0]*N
i=0
while i<N:
    if i<K:
        if T[i]=='r':
            ans[i]=P
        elif T[i]=='s':
            ans[i]=R
        else:
            ans[i]=S
    else:
        if T[i]=='r':
            if T[i-K]=='r':
                ans[i]=0
            else:
                ans[i]=P
        elif T[i]=='s':
            if T[i-K]=='s':
                ans[i]=0
            else:
                ans[i]=R
        else:
            if T[i-K]=='p':
                ans[i]=0
            else:
                ans[i]=S
    i+=1

print(sum(ans))

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

ans=[0]*N
i=0
while i<N:
    if i<K:
        if T[i]=='r':
            ans[i]=P
        elif T[i]=='s':
            ans[i]=R
        else:
            ans[i]=S
    else:
        if T[i]=='r':
            if T[i-K]=='r'and ans[i-K]==P:
                ans[i]=0
            else:
                ans[i]=P
        elif T[i]=='s':
            if T[i-K]=='s'and ans[i-K]==R:
                ans[i]=0
            else:
                ans[i]=R
        else:
            if T[i-K]=='p'and ans[i-K]==S:
                ans[i]=0
            else:
                ans[i]=S
    i+=1

print(sum(ans))
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

hands = ['r', 's', 'p']
for i,t in enumerate(T):
    if t == 'r':
        T[i] = 'p'
    elif t == 's':
        T[i] = 'r'
    else:
        T[i] = 's'
point = 0
for i,t in enumerate(T):
    if i+1 <= K:
        if t == 'r':
            point += R
        elif t == 's':
            point += S
        else:
            point += P
        continue
    print(i)
    if t == T[i-K]:
        # print(i)
        a = 0
        if len(T)-1 < i+K:
            next_hand = T[i]
        else:
            next_hand = T[i+K]
        while T[i] == T[i-K] or T[i] == next_hand:
            T[i] = hands[a]
            a += 1
    else:
        if t == 'r':
            point += R
        elif t == 's':
            point += S
        else:
            point += P
print(point)

Fixed code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

hands = ['r', 's', 'p']
for i,t in enumerate(T):
    if t == 'r':
        T[i] = 'p'
    elif t == 's':
        T[i] = 'r'
    else:
        T[i] = 's'
point = 0
for i,t in enumerate(T):
    if i+1 <= K:
        if t == 'r':
            point += R
        elif t == 's':
            point += S
        else:
            point += P
        continue
    if t == T[i-K]:
        a = 0
        if len(T)-1 < i+K:
            next_hand = T[i]
        else:
            next_hand = T[i+K]
        while T[i] == T[i-K] or T[i] == next_hand:
            T[i] = hands[a]
            a += 1
    else:
        if t == 'r':
            point += R
        elif t == 's':
            point += S
        else:
            point += P
print(point)
Buggy code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
cnt = 0
flag = True
def jannkenn(string):
    if string ==  'r':
        return p
    elif string == 'p':
        return s
    elif string == 's':
        return r
for i in range(k):
    last = i
    for j in range(n):
        if i+k*j < n:
            if  last == i:
                cnt += jannkenn(t[i+k*j])
            elif t[last] != t[i+k*j]:
                cnt += jannkenn(t[i+k*j])
                
        else:
            break
        last = i+k*j
print(cnt)

Fixed code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
cnt = 0
flag = True
flag_win = 0
def jannkenn(string):
    if string ==  'r':
        return p
    elif string == 'p':
        return s
    elif string == 's':
        return r
for i in range(k):
    last = i
    for j in range(n):
        if i+k*j < n:
            if  j == 0:
                cnt += jannkenn(t[i+k*j])
                #print(i,j)
                flag_win = 1
            elif t[last] != t[i+k*j]:
        #        print(i,j)
                cnt += jannkenn(t[i+k*j])
                flag_win = 1
                
            elif t[last] == t[i+k*j]:
                if flag_win == 0:
                    cnt += jannkenn(t[i+k*j])
                    flag_win = 1
                    
                else:
                    flag_win = 0
                
        else:
            break
        last = i+k*j
print(cnt)
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
List = [[] for k in range(K)]
for n in range(N):
    List[n % K].append(T[n])

point = {'r': P, 's': R, 'p': S}
print(List)
score = 0
for k in range(K):
    L = List[k]
    count = 1
    length = len(L)
    for i in range(length):
        try:
            if L[i] == L[i+1]:
                count += 1
            else:
                score += point[L[i]]*((count+1)//2)
                count = 1
        except:
            score += point[L[i]]*((count+1)//2)
print(score)


Fixed code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
List = [[] for k in range(K)]
for n in range(N):
    List[n % K].append(T[n])

point = {'r': P, 's': R, 'p': S}

score = 0
for k in range(K):
    L = List[k]
    count = 1
    length = len(L)
    for i in range(length):
        try:
            if L[i] == L[i+1]:
                count += 1
            else:
                score += point[L[i]]*((count+1)//2)
                count = 1
        except:
            score += point[L[i]]*((count+1)//2)
print(score)
Buggy code:
line1 = input().split(' ')
line2 = input().split(' ')
N = int(line1[0])
K = int(line1[1])
R = int(line2[0])
S = int(line2[1])
P = int(line2[2])
T = input()
score = 0
mem = list(range(K))

for i in range(N):
  index = i % K

  if (mem[index] != T[i:i+1]):
    if (T[i:i+1] == 'r'):
      score = score + R
    elif (T[i:i+1] == 's'):
      score = score + S
    elif (T[i:i+1] == 'p'):
      score = score + P
    mem[index] = T[i:i+1]
  else:
    mem[index] = 0

print(score)

Fixed code:
line1 = input().split(' ')
line2 = input().split(' ')
N = int(line1[0])
K = int(line1[1])
R = int(line2[0])
S = int(line2[1])
P = int(line2[2])
T = input()
score = 0
mem = list(range(K))

for i in range(N):
  index = i % K

  if (mem[index] != T[i:i+1]):
    if (T[i:i+1] == 'r'):
      score = score + P
    elif (T[i:i+1] == 's'):
      score = score + R
    elif (T[i:i+1] == 'p'):
      score = score + S
    mem[index] = T[i:i+1]
  else:
    mem[index] = 0

print(score)
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

res = [0]*N
hands = ["r", "s", "p"]

for i in range(N):
    res[i] = hands[hands.index(T[i])-1]

for i in range(N):
    if i >= K and res[i-K] == res[i]:
        res[i] = 0

score = R*res.count("r") + S*res.count("s") + P*res.count("p")
print(res)
print(R*res.count("r"), S*res.count("s"), P*res.count("p"))
print(score)


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

res = [0]*N
hands = ["r", "s", "p"]

for i in range(N):
    res[i] = hands[hands.index(T[i])-1]

for i in range(N):
    if i >= K and res[i-K] == res[i]:
        res[i] = 0

score = R*res.count("r") + S*res.count("s") + P*res.count("p")
print(score)