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

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)

Verdicts: Wrong Answer

Accepted