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 re
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())
listT = list(T)

beforeK = T[:K]
afterK = T[K:]

ans = 0
r = re.findall('r', T)
s = re.findall('s', T)
p = re.findall('p', T)

ans = P*len(r) + R*len(s) + S*len(p)

countr = 0
counts = 0
countp = 0

for i in range(K, N-1, 1):
    if listT[i] == listT[i-K]:
        if listT[i] == 'r':
            countr += 1
        elif listT[i] == 's':
            counts += 1
        else:
            countp += 1

if countr == 1:
    ans -= P
elif countr == 0:
    ans = ans
else:
    ans -= P*((countr//2)+1)

if counts == 1:
    ans -= R
else:
    ans -= R*((counts//2)+1)

if countp == 1:
    ans -= S
else:
    ans -= S*((countp//2)+1)

print(int(ans))

def resolve():
    N, K = map(int, input().rstrip().split())
    R, S, P = map(int, input().rstrip().split())
    T = list(input().rstrip())

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

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ""
            continue
        ans += score[T[i]]

    print(s)

if __name__ == "__main__":
    resolve()


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

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

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ' '
            continue
        ans += score[T[i]]

    print(s)

if __name__ == "__main__":
    resolve()


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

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

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ' '
            continue
        ans += score[T[i]]

    print(ans)

if __name__ == "__main__":
    resolve()


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted