qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
    if i <= K:
        dp[i][0] = int(T[i-1]=='s') * R
        dp[i][1] = int(T[i-1]=='p') * P
        dp[i][2] = int(T[i-1]=='r') * P
    else:
        dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
        dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * P
        dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * S

ans = 0
for d in dp[-K:]:
    ans += max(d)
print(ans)

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

dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
    if i <= K:
        dp[i][0] = int(T[i-1]=='s') * R
        dp[i][1] = int(T[i-1]=='p') * S
        dp[i][2] = int(T[i-1]=='r') * P
    else:
        dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
        dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * S
        dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * P

ans = 0
for d in dp[-K:]:
    ans += max(d)
print(ans)
Buggy code:
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(map(str, input()))

res = 0

def change(hand):
    if hand == 'r':
        return 'p'

    if hand == 's':
        return 'r'

    if hand == 'p':
        return 's'

memo = []
for (i,t) in enumerate(T):
    if i > K:
        if memo[i-K] == change(t):
          memo.append(t)
          continue
 
    if t == 'r':
        res = res+P
        memo.append(change(t))

    if t == 's':
        res = res+R
        memo.append(change(t))

    if t == 'p':
        res = res+S
        memo.append(change(t))

print(res)
    



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

res = 0

def change(hand):
    if hand == 'r':
        return 'p'

    if hand == 's':
        return 'r'

    if hand == 'p':
        return 's'

memo = []
for (i,t) in enumerate(T):
    if i > K-1:
        if memo[i-K] == change(t):
          memo.append(' ')
          continue
 
    if t == 'r':
        res = res+P
        memo.append(change(t))

    if t == 's':
        res = res+R
        memo.append(change(t))

    if t == 'p':
        res = res+S
        memo.append(change(t))

print(res)
Buggy code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

r_point = t.count('s') * r
s_point = t.count('p') * s
p_point = t.count('r') * p

sum_point = r_point+s_point+p_point

for i, moji in enumerate(t):
    if i+k >= len(t):
        break
    print(t[i], t[i+k])
    if t[i] == 'r' and t[i+k] == 'r':
        sum_point -= p
        t[i+k] = 'x'
    if t[i] == 's' and t[i+k] == 's':
        sum_point -= r
        t[i+k] = 'x'
    if t[i] == 'p' and t[i+k] == 'p':
        sum_point -= s
        t[i+k] = 'x'

print(sum_point)


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

r_point = t.count('s') * r
s_point = t.count('p') * s
p_point = t.count('r') * p

sum_point = r_point+s_point+p_point

for i, moji in enumerate(t):
    if i+k >= len(t):
        break
    if t[i] == 'r' and t[i+k] == 'r':
        sum_point -= p
        t[i+k] = 'x'
    if t[i] == 's' and t[i+k] == 's':
        sum_point -= r
        t[i+k] = 'x'
    if t[i] == 'p' and t[i+k] == 'p':
        sum_point -= s
        t[i+k] = 'x'

print(sum_point)
Buggy code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
d=[]
ct=0
for i in range(k):
    for j in range(i,n-i,k):
        d.append(t[j])
    for l in range(len(d)-1):
        if d[l]==d[l+1]:
            d[l+1]='out'
    #print(d,i,n,k)
    ct+=d.count('r')*p+d.count('s')*r+d.count('p')*s
    d=[]
    #print(ct)
    #ct+=

print(ct)    
#print(t.count("r")*r+)

Fixed code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())
d=[]
ct=0
for i in range(k):
    #for m in range(k):
     #   if (n-1-m)%k==
    for j in range(i,n,k):
        d.append(t[j])
    for l in range(len(d)-1):
        if d[l]==d[l+1]:
            d[l+1]='out'
   # print(d,i,n,k)
    ct+=d.count('r')*p+d.count('s')*r+d.count('p')*s
    d=[]
    #print(ct)
    #ct+=

print(ct)    
#print(t.count("r")*r+)
Buggy code:
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
    print(*dp, sep='\n')
    r = 0
    for j1 in range(-k, 0, 1):
        r += max(dp[j1])
    print(r)

if __name__ == '__main__':
    main()


Fixed code:
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)

if __name__ == '__main__':
    main()
Buggy code:
n, k = map(int, input().split())
r, ss, p = map(int, input().split())
s = input()
hands = [None]*n
wins = {'r':'p', 's':'r', 'p':'s'}
h_s = {'r':r, 's':ss, 'p':p}
ans = 0
for i, c in enumerate(s):
    if i - k >= 0:
        if wins[c] == hands[i-k]:æ
            hs = set(wins.keys())
            hs.remove(wins[c])
            if i + k < n:
                if wins[s[i+k]] in hs:
                    hs.remove(wins[s[i+k]])
            hands[i] = hs.pop()
            continue
    hand = wins[c]
    hands[i] = hand
    ans += h_s[hand]

print(ans)
        




Fixed code:
n, k = map(int, input().split())
r, ss, p = map(int, input().split())
s = input()
hands = [None]*n
wins = {'r':'p', 's':'r', 'p':'s'}
h_s = {'r':r, 's':ss, 'p':p}
ans = 0
for i, c in enumerate(s):
    if i - k >= 0:
        if wins[c] == hands[i-k]:
            hs = set(wins.keys())
            hs.remove(wins[c])
            if i + k < n:
                if wins[s[i+k]] in hs:
                    hs.remove(wins[s[i+k]])
            hands[i] = hs.pop()
            continue
    hand = wins[c]
    hands[i] = hand
    ans += h_s[hand]

print(ans)
Buggy code:
N, K = map(int, input().split(' '))
R, S, P = map(int, input().split(' '))
T = list(input())
print(T)
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)

Fixed code:
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)
Buggy code:
n, k = map(int,input().split())
r, s, p = map(int, input().split())
t = input()
scoremap = {
    "r": p,
    "p": s,
    "s": r
}
t_ls = [scoremap[i] for i in t]

def best(ls: list):
    print(ls)
    for i in range(len(ls) - 1):
        if ls[i] == ls[i + 1]:
            ls[i + 1] = 0
    print(ls)
    num=sum(ls)
    return num

total=0
for i in range(k):
    ls = t_ls[i::k]
    total+=best(ls)
print(total)

Fixed code:
n, k = map(int,input().split())
r, s, p = map(int, input().split())
t = input()
scoremap = {
    "r": p,
    "p": s,
    "s": r,
    "-": 0
}
t=[i for i in t]

def best(ls: list):
    for i in range(len(ls) - 1):
        if ls[i] == ls[i + 1]:
            ls[i + 1] = '-'
    num=sum([scoremap[i] for i in ls])
    return num

total=0
for i in range(k):
    ls = t[i::k]
    total+=best(ls)
print(total)
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

score = np.array([0, R, S, P], dtype=int)
M = (1 + (N-1)//K)
addi = M * K - N
t = np.array([{'n':0, 's':1, 'p':2, 'r':3}[i] for i in T+'n'*addi], dtype=int)

t = t.reshape(M,K).T

for i in range(K):
    for j in range(M):
        if j!=0 and t[i,j] == t[i,j-1]:
            t[i,j] = 0

print(score[t].sum())

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

import numpy as np

score = np.array([0, R, S, P], dtype=int)
M = (1 + (N-1)//K)
addi = M * K - N
t = np.array([{'n':0, 's':1, 'p':2, 'r':3}[i] for i in T+'n'*addi], dtype=int)

t = t.reshape(M,K).T

for i in range(K):
    for j in range(M):
        if j!=0 and t[i,j] == t[i,j-1]:
            t[i,j] = 0

print(score[t].sum())
Buggy code:
def main():
  [n, k] = [int(i) for i in input().split()]
  [r, s, p] = [int(i) for i in input().split()]
  T =  input()
  
  my = T.replace("r", "hoge").replace("s", "r").replace("p", "s").replace("hoge", "p") 
  for i in range(k, n):
    if my[i] == my[i-k]:
      my = my[:i] + "l" + my[i+1:]  
  print(my)
  print(my.count("r")* r + my.count("s")*s + my.count("p")* p)
  
if __name__ == "__main__":
  main()

Fixed code:
def main():
  [n, k] = [int(i) for i in input().split()]
  [r, s, p] = [int(i) for i in input().split()]
  T =  input()
  
  my = T.replace("r", "hoge").replace("s", "r").replace("p", "s").replace("hoge", "p") 
  for i in range(k, n):
    if my[i] == my[i-k]:
      my = my[:i] + "l" + my[i+1:]  

  print(my.count("r")* r + my.count("s")*s + my.count("p")* p)
  
if __name__ == "__main__":
  main()
Buggy code:
n,k=[int(i) for i in input().split()]
r,s,p=[int(i) for i in input().split()]
hand=input()
ans=0
for i in range(k):
  free=True
  j=i
  while j<n:
    if free=True or hand[j-k]!=hand[j]:
      if hand[j]='r':
        ans+=p
      elif hand[j]='s':
        ans+=r
      else:
        ans+=s
      free=False
    else:
      free=True
    j+=k
print(ans)

Fixed code:
n,k=[int(i) for i in input().split()]
r,s,p=[int(i) for i in input().split()]
hand=input()
ans=0
for i in range(k):
  free=True
  j=i
  while j<n:
    if free==True or hand[j-k]!=hand[j]:
      if hand[j]=='r':
        ans+=p
      elif hand[j]=='s':
        ans+=r
      else:
        ans+=s
      free=False
    else:
      free=True
    j+=k
print(ans)
Buggy code:
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 i in range(n-k):
  temp= i-k
  if temp >=0 and t[i]==t[temp]:
    t[i]=""
  else:
    ans+=hand[t[i]]
print(ans)

Fixed code:
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 i in range(n):
  temp= i-k
  if temp >=0 and t[i]==t[temp]:
    t[i]=" "
  else:
    ans+=hand[t[i]]
print(ans)
Buggy code:
import math

if __name__=="__main__":
    M=0
    n,k=input().split()
    r,s,p=input().split()
    t=input()
    t=list(t)
    n,k,r,s,p=int(n),int(k),int(r),int(s),int(p)
    for i in range(0,n):
       if t[i]=='r':
           t[i]='p'
           M+=p
       elif t[i]=='s':
           t[i]='r'
           M+=r
       else:
           t[i]='s'
           M+=s
    for i in range(k,n):
        if t[i]==t[i-k]:
            if t[i]=='r':
                M-=r
            elif t[i]=='s':
                M-=s
            else:
                M-=p
        t[i]='u'
    print(M)


Fixed code:
import math

if __name__=="__main__":
    M=0
    n,k=input().split()
    r,s,p=input().split()
    t=input()
    t=list(t)
    n,k,r,s,p=int(n),int(k),int(r),int(s),int(p)
    for i in range(0,n):
       if t[i]=='r':
           t[i]='p'
           M+=p
       elif t[i]=='s':
           t[i]='r'
           M+=r
       else:
           t[i]='s'
           M+=s
    for i in range(k,n):
        if t[i]==t[i-k]:
            if t[i]=='r':
                M-=r
            elif t[i]=='s':
                M-=s
            else:
                M-=p
            t[i]='u'
    print(M)
Buggy code:
*t,s=open(0).read().split()
n,k,r,s,p=map(int,t)
d={'r':p,'s':r,'p':s}
b=['']*n*2
a=0
for i,c in enumerate(s[:n]):
  if c!=b[i-k]:
    b[i]=c
    a+=d[c]
print(a)

Fixed code:
*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)
Buggy code:
N, K = map(int, input().split(" "))
R, S, P = map(int, input().split(" "))
T = input()

score_by_hand = {"r": P, "s": R, "p": S}
result = 0
score = 0
for k in range(K):
    column = T[k::K]
    print(column)
    before = None
    for hand in column:
        if hand == before:
            before = None
        else:
            score += score_by_hand[hand]
            before = hand

print(score)

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

score_by_hand = {"r": P, "s": R, "p": S}
result = 0
score = 0
for k in range(K):
    column = T[k::K]
    before = None
    for hand in column:
        if hand == before:
            before = None
        else:
            score += score_by_hand[hand]
            before = hand

print(score)
Buggy code:
from collections import deque
N,K = (int(x) for x in input().split())
R,S,P = (int(x) for x in input().split())
T = input()
count = 0
prog = 0
checker = ""
l = list(T)
d = deque(l)
for hand in l:
    if prog >= K:
        if hand == "r" and hand != checker:
            count += P
            checker = d.popleft()
        elif hand == "s" and hand != checker:
            count += R
            checker = d.popleft()
        elif hand == "p" and hand != checker:
            count += S
            checker = d.popleft()
        else:
            checker = d.popleft() + " "
    else:
        prog += 1
        if hand == "r":
            count += P
        elif hand == "s":
            count += R
        else:
            count += S
        if prog >= K:
            checker = d.popleft()
print(count)

Fixed code:
from collections import deque
N,K = (int(x) for x in input().split())
R,S,P = (int(x) for x in input().split())
T = input()
count = 0
prog = 0
checker = ""
l = list(T)
d = deque(l[0:K])
for hand in l:
    if prog >= K:
        if hand == "r" and hand != checker:
            count += P
            d.append(hand)
            checker = d.popleft()
        elif hand == "s" and hand != checker:
            count += R
            d.append(hand)
            checker = d.popleft()
        elif hand == "p" and hand != checker:
            count += S
            d.append(hand)
            checker = d.popleft()
        else:
            d.append(hand+" ")
            checker = d.popleft()
    else:
        prog += 1
        if hand == "r":
            count += P
        elif hand == "s":
            count += R
        else:
            count += S
        if prog >= K:
            checker = d.popleft()
print(count)
Buggy code:
n,k=list(map(int,input().split()))
r,p,s=list(map(int,input().split()))
t=input()
vic=""
ans=0
for i in t:
    if i=="r":
        vic+="p"
    if i=="p":
        vic+="s"
    if i=="s":
        vic+="r"
#print(vic[:k])
for i in vic[:k]:
    if i=="r":
        ans+=r
    elif i=="p":
        ans+=p
    elif i=="s":
        ans+=s
#print(vic)
#print(ans)
for i in range(k,n):
    #print(i,":",vic[i])
    if vic[i]==vic[i-k]:
        #print("lose")
        if not i==n-1:
            vic=vic[:i]+'n'+vic[i+1:]
    else:
        #print("win")
        if vic[i]=="r":
            ans+=r
        elif vic[i]=="p":
            ans+=p
        elif vic[i]=="s":
            ans+=s
        else:
            pass
            #print("wrong input")

    #print()

print(ans)

Fixed code:
n,k=list(map(int,input().split()))
r,s,p=list(map(int,input().split()))
t=input()
vic=""
ans=0
for i in t:
    if i=="r":
        vic+="p"
    if i=="p":
        vic+="s"
    if i=="s":
        vic+="r"
#print(vic[:k])
for i in vic[:k]:
    if i=="r":
        ans+=r
    elif i=="p":
        ans+=p
    elif i=="s":
        ans+=s
#print(vic)
#print(ans)
for i in range(k,n):
    #print(i,":",vic[i])
    if vic[i]==vic[i-k]:
        #print("lose")
        if not i==n-1:
            vic=vic[:i]+'n'+vic[i+1:]
    else:
        #print("win")
        if vic[i]=="r":
            ans+=r
        elif vic[i]=="p":
            ans+=p
        elif vic[i]=="s":
            ans+=s
        else:
            pass
            #print("wrong input")

    #print()

print(ans)
Buggy code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = 0
print(sum(t.count("r")*r + t.count("s")*s + t.count("p")*p))

Fixed code:
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

print(sum([t.count("r")*p, t.count("s")*r, t.count("p")*s]))
Buggy code:
import math
import sys

INF = 10**10
(N, K) = list(map(int,input().split()))
(R, S, P) = list(map(int,input().split()))
T = input()

#print(N,K)
#print(R,S,P)
#print(T)

def maxp(s):
    vr = 0
    vs = 0
    vp = 0
    for i in range(0,len(s)):
        if s[i] == 'r':
            nvr = 0 + max(vs,vp)
            nvs = 0 + max(vp,vr)
            nvp = P + max(vr,vs)
        elif s[i] == 's':
            nvr = R + max(vs,vp)
            nvs = 0 + max(vp,vr)
            nvp = 0 + max(vr,vs)
        else:
            nvr = 0 + max(vs,vp)
            nvs = S + max(vp,vr)
            nvp = 0 + max(vr,vs)
        vr = nvr
        vs = nvs
        vp = nvp
        #print(s[i],vr,vs,vp)
    return(max(vr,vs,vp))
ans=0
for i in range(0,K):
    p = ""
    for k in range(i,len(T),K):
        p = p + T[k]
    #print(p)
    ans  = ans + maxp(p)

Fixed code:
import math
import sys

INF = 10**10
(N, K) = list(map(int,input().split()))
(R, S, P) = list(map(int,input().split()))
T = input()

#print(N,K)
#print(R,S,P)
#print(T)

def maxp(s):
    vr = 0
    vs = 0
    vp = 0
    for i in range(0,len(s)):
        if s[i] == 'r':
            nvr = 0 + max(vs,vp)
            nvs = 0 + max(vp,vr)
            nvp = P + max(vr,vs)
        elif s[i] == 's':
            nvr = R + max(vs,vp)
            nvs = 0 + max(vp,vr)
            nvp = 0 + max(vr,vs)
        else:
            nvr = 0 + max(vs,vp)
            nvs = S + max(vp,vr)
            nvp = 0 + max(vr,vs)
        vr = nvr
        vs = nvs
        vp = nvp
        #print(s[i],vr,vs,vp)
    return(max(vr,vs,vp))
ans=0
for i in range(0,K):
    p = ""
    for k in range(i,len(T),K):
        p = p + T[k]
    #print(p)
    ans  = ans + maxp(p)
print(ans)
Buggy code:
N, K = (int(x) for x in input().split())
R, S, P = (int(x) for x in input().split())
T = input()

def getScore(t):
    if t == "r":
        print("P", end="")
        return P
    elif t == "s":
        print("R", end="")
        return R
    elif t == "p":
        print("S", end="")
        return S
    else:
        print(" ", end="")

score=0
mycard = []
for i in range(N):
    if i < K:
        score += getScore(T[i])
        mycard.append(1)
    else:
        if mycard[i-K] == 0:
            score += getScore(T[i])
            mycard.append(1)
        else:
            if T[i] != T[i-K]:
                score += getScore(T[i])
                mycard.append(1)
            else:
                mycard.append(0)
print("")
print(score)

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

def getScore(t):
    if t == "r":
        return P
    elif t == "s":
        return R
    elif t == "p":
        return S

score=0
mycard = []
for i in range(N):
    if i < K:
        score += getScore(T[i])
        mycard.append(1)
    else:
        if mycard[i-K] == 0:
            score += getScore(T[i])
            mycard.append(1)
        else:
            if T[i] != T[i-K]:
                score += getScore(T[i])
                mycard.append(1)
            else:
                mycard.append(0)
print(score)
Buggy code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = str(input())
score = 0
lose = 0
def janken(hand):
    if hand == 'r':
        return(p)
    if hand == 's':
        return(r)
    if hand == 'p':
        return(s)

for i in range(n):
    if i <= k - 1:
        score += janken(T[i])
    else:
        if T[i] == T[i - k]:
            if i - k != lose:
                lose = i
            else:
                score += janken(T[i])
        else:
            score += janken(T[i])
print(score)

Fixed code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = str(input())
score = 0
lose = []
def janken(hand):
    if hand == 'r':
        return(p)
    if hand == 's':
        return(r)
    if hand == 'p':
        return(s)

for i in range(n):
    if i <= k - 1:
        score += janken(T[i])
    else:
        if T[i] == T[i - k]:
            if i - k not in lose:
                lose.append(i)
            else:
                score += janken(T[i])
        else:
            score += janken(T[i])
print(score)
Buggy code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

hands = [None] * N
d1 = {'r': 'p', 's': 'r', 'p': 's'}
d2 = {'r': P, 's': R, 'p': S}
result = 0
for i in range(len(T)):
    if i >= K and d1[T[i]] == hands[i - K]:
        if i + K < N:
            hands[i] = list(set('rps') - set(T[i + K]) - set(T[i]))[0]
        else:
            hands[i] = T[i]
    else:
        hands[i] = d1[T[i]]
        result += d2[T[i]]
print(result)


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

hands = [None] * N
d1 = {'r': 'p', 's': 'r', 'p': 's'}
d2 = {'r': P, 's': R, 'p': S}
result = 0
for i in range(len(T)):
    if i >= K and d1[T[i]] == hands[i - K]:
        if i + K < N:
            hands[i] = set('rps') - set(T[i + K]) - set(T[i])
        else:
            hands[i] = T[i]
    else:
        hands[i] = d1[T[i]]
        result += d2[T[i]]
print(result)