Problem: 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?

Submission attempts (in order):
def main():
  N,K = input().split()
  N = int(N)
  K = int(K)
  R,S,P = input().split()
  R = int(R)
  S = int(S)
  P = int(P)
  T = input()
  #r -> a -> p 
  #s -> b -> r
  #p -> c -> s
  T = T.replace("r","a")
  T = T.replace("s","b")
  T = T.replace("p","c")
  T = T.replace("a","p")
  T = T.replace("b","r")
  T = T.replace("c","s")
  print(T)
  r_count = T.count("r")
  s_count = T.count("s")
  p_count = T.count("p")
  print(r_count, s_count, p_count)
  
  T = list(T)
  
  for i in range(K,N-K,1):
    if(T[i]==T[i-K]):
      if(T[i]=="r"):
        r_count=r_count-1
        if(T[i+K]=="p"):
          T[i]="s"
        else:
          T[i]="p"
      elif(T[i]=="s"):
        s_count=s_count-1
        if(T[i+K]=="r"):
          T[i]="p"
        else:
          T[i]="r"
      else:
        p_count=p_count-1
        if(T[i+K]=="s"):
          T[i]="r"
        else:
          T[i]="s"
          
  for i in range(N-K,N,1):
    if(T[i]==T[i-K]):
      if(T[i]=="r"):
        r_count=r_count-1
        T[i]="p"
      elif(T[i]=="s"):
        s_count=s_count-1
        T[i]="r"
      else:
        p_count=p_count-1
        T[i]="s"


  print(r_count, s_count, p_count)
  Score = R*r_count + S*s_count + P*p_count
  print(Score)
  

if __name__=="__main__":
  main()

def main():
  N,K = input().split()
  N = int(N)
  K = int(K)
  R,S,P = input().split()
  R = int(R)
  S = int(S)
  P = int(P)
  T = input()
  #r -> a -> p 
  #s -> b -> r
  #p -> c -> s
  T = T.replace("r","a")
  T = T.replace("s","b")
  T = T.replace("p","c")
  T = T.replace("a","p")
  T = T.replace("b","r")
  T = T.replace("c","s")
  #print(T)
  #r_count = T.count("r")
  #s_count = T.count("s")
  #p_count = T.count("p")
  #print(r_count, s_count, p_count)
  
  T = list(T)
  score=0
  
  for i in range(N-K):
    if(T[i]=="r"):
      score = score+R
    elif(T[i]=="s"):
      score = score+S
    elif(T[i]=="p"):
      score = score+P
    if(T[i]==T[i+K]):
      T[i+K]="n"
          
  for i in range(N-K,N,1):
    if(T[i]=="r"):
      score = score+R
    elif(T[i]=="s"):
      score = score+S
    elif(T[i]=="p"):
      score = score+P

  print(score)
  

if __name__=="__main__":
  main()

Verdicts: Internal error

Accepted