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

nk = list(input().split(" "))
n = int(nk[0])
k = int(nk[1])
rsp = list(input().split(" "))
r = int(rsp[0])
s = int(rsp[1])
p = int(rsp[2])
T = str(input())

my_choice = [""] * n
ans = 0

for i in range(0,k):
    if T[i] == "r":
        my_choice[i] = "p"
        ans += p
    elif T[i] == "s":
        my_choice[i] = "r"
        ans += r
    else:
        my_choice[i] = "s"
        ans += s

if k == n:
    print(ans)
    sys.exit()

for i in range(k,n):
    if T[i] == "r" and my_choice[i - k] != "p":
        my_choice[i] = "p"
        ans += p
    elif T[i] == "s" and my_choice[i - k] != "r":
        my_choice[i] = "r"
        ans += r
    elif T[i] == "p" and my_choice[i - k] != "s":
        my_choice[i] = "s"
        ans += s

print(my_choice)
print(ans)


import sys

nm = list(input().split(" "))
N = int(nm[0])
M = int(nm[1])
A = list(input().split(" "))
A.sort()
A.reverse()

ans = 0

start ,counter  = 0 , 0
flag1 = 0
flag2 = 0 # repete
flag3 = 0 # next step
for i in range(0,M):
    if flag1 == 0:
        ans += int(A[start]) + int(A[counter])
        counter += 1
        flag1 = 1
    elif flag2 == 0:
        ans += int(A[start]) + int(A[counter])
        flag2 = 1
    else:
        ans += int(A[start]) + int(A[counter])
        flag2 = 0
        if flag3 == 0:
            counter += 1
            if counter == N-1:
                flag3 = 1
        else:
            flag1 = 0
            flag3 = 0
            start += 1
            counter = start

print(ans)

    
    
    


import sys

nk = list(input().split(" "))
n = int(nk[0])
k = int(nk[1])
rsp = list(input().split(" "))
r = int(rsp[0])
s = int(rsp[1])
p = int(rsp[2])
T = str(input())

my_choice = [""] * n
ans = 0

for i in range(0,k):
    if T[i] == "r":
        my_choice[i] = "p"
        ans += p
    elif T[i] == "s":
        my_choice[i] = "r"
        ans += r
    else:
        my_choice[i] = "s"
        ans += s

if k == n:
    print(ans)
    sys.exit()

for i in range(k,n):
    if T[i] == "r" and my_choice[i - k] != "p":
        my_choice[i] = "p"
        ans += p
    elif T[i] == "s" and my_choice[i - k] != "r":
        my_choice[i] = "r"
        ans += r
    elif T[i] == "p" and my_choice[i - k] != "s":
        my_choice[i] = "s"
        ans += s


print(ans)


Verdicts: Wrong Answer

Runtime Error

Accepted