Problem:


Score : 400 points

Problem Statement

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?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996



Sample input:
5 2
8 7 6
rsrpr


Sample output:
27

Submission status: Wrong Answer

Solution code:
n, k = [int(x) for x in input().split(" ")]
s, p, r = [int(x) for x in input().split(" ")]
texts = list(input())

def can_key(i, key):
    print(i - k, key)
    if i - k >= 0:
        if last_h[i - k] != key:
            return True
        return False
    return True

score = 0
last_h = []
for i, text in enumerate(texts):
    if text == "r":
        if can_key(i, r):
            score += r
            last_h.append(r)
        else:
            # score += s
            last_h.append(s)

    elif text == "s":
        if can_key(i, s):
            score += s
            last_h.append(s)
        else:
            # score += p
            last_h.append(p)

    elif text == "p":
        if can_key(i, p):
            score += p
            last_h.append(p)
        else:
            # score += r
            last_h.append(r)
print(last_h)
print(score)

Submission status: Wrong Answer

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

def score(T):
    sa = 0
    x = 0
    for i in range(len(T)):
        if x == 1 and T[i] == T[i-1] :
            if T[i] == "r":
                sa += P
                x = 0
            elif T[i] == "s":
                sa += R
                x = 0
            elif T[i] == "p":
                sa += S
                x = 0
            
        elif i > 1 and T[i] == T[i-1] :
            x = 1
        elif T[i] == "r":
            sa += P
            x = 0
        elif T[i] == "s":
            sa += R
            x = 0
        elif T[i] == "p":
            sa += S
            x = 0
    return sa
ans = 0
for k in range(K):
    ans += score(T[k::K])

print(ans)

Submission status: Wrong Answer

Solution code:

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

count = 0
point = 0
listt = []

t = list(t)
#print(t[-6]) #
while count < n:
    #print("-----------",count+1, ":",t[count])
    #print(listt, len(listt))
    if len(listt) <= k:
        if t[count] == 'r': #相手がグーだからパーで勝つ
            point += p
            listt.append('p')
            #print("パー    +",p)
        elif t[count] == 's':#相手がチョキだからグーで勝つ
            point += r
            listt.append('r')
            #print("グー    +",r)
        elif t[count] == 'p':#相手がパーだからチョキで勝つ
            point += s
            listt.append('s')
            #print("チョキ    +",s)
    elif len(listt) > k:
        if t[count] == 'r': #相手がグーだからパーで勝つ
            if listt[-k] == 'p':
                listt.append(t[count])
            else:
                point += p
                listt.append('p')
                #print("ぱー    +",p)
        elif t[count] == 's':#相手がチョキだからグーで勝つ
            if listt[-k] == 'r':
                listt.append(t[count])
            else:
                point += r
                listt.append('r')
                #print("ぐー    +",r)
        elif t[count] == 'p':#相手がパーだからチョキで勝つ
            if listt[-k] == 's':
                listt.append(t[count])
            else:
                point += s
                listt.append('s')
                #print("ちょき    +",s)
    count += 1
    
print(point)

Submission status: Wrong Answer

Solution code:

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

count = 0
point = 0
listt = []
t = list(t)

while count < n:
    #print("-----------",count+1, ":",t[count])
    #print(listt, len(listt))
    if len(listt) < k:
        if t[count] == 'r': #相手がグーだからパーで勝つ
            point += p
            listt.append('p')
            #print("パー    +",p)
        elif t[count] == 's':#相手がチョキだからグーで勝つ
            point += r
            listt.append('r')
            #print("グー    +",r)
        elif t[count] == 'p':#相手がパーだからチョキで勝つ
            point += s
            listt.append('s')
            #print("チョキ    +",s)
    elif len(listt) >= k:
        if t[count] == 'r': #相手がグーだからパーで勝つ
            if listt[-k] == 'p':
                listt.append(t[count])
            else:
                point += p
                listt.append('p')
                #print("ぱー    +",p)
        elif t[count] == 's':#相手がチョキだからグーで勝つ
            if listt[-k] == 'r':
                listt.append(t[count])
            else:
                point += r
                listt.append('r')
                #print("ぐー    +",r)
        elif t[count] == 'p':#相手がパーだからチョキで勝つ
            if listt[-k] == 's':
                listt.append(t[count])
            else:
                point += s
                listt.append('s')
                #print("ちょき    +",s)
    count += 1
    
print(point)

Submission status: Wrong Answer

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

count = 0
point = 0
listt = []
t = list(t)


while count < n:
    #print("-----------",count+1, ":",t[count])
    #print(listt, len(listt))
    if len(listt) < k:
        if t[count] == 'r': #つ
            point += p
            listt.append('p')
            
        elif t[count] == 's':#
            point += r
            listt.append('r')
            
        elif t[count] == 'p':#
            point += s
            listt.append('s')
            
    elif len(listt) >= k:
        if t[count] == 'r': #
            if listt[-k] == 'p':
                listt.append(t[count])
            else:
                point += p
                listt.append('p')
                
        elif t[count] == 's':
            if listt[-k] == 'r':
                listt.append(t[count])
            else:
                point += r
                listt.append('r')
                
        elif t[count] == 'p':
            if listt[-k] == 's':
                listt.append(t[count])
            else:
                point += s
                listt.append('s')
                
    count += 1
    
print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
"""
N K
R S P
T
"""

ln1 = input().split()
ln2 = input().split()
ln3 = input().split()

N, K = int(ln1[0]), int(ln1[1])
R, S, P = int(ln2[0]), int(ln2[1]), int(ln2[2])
T = ln3

point = 0
result = []

def janken_result(te):
    if te == "r":
        return P
    elif te == "s":
        return R
    elif te == "p":
        return S
    else:
        exit(0)

for i in range(N):
    if i < K:
        point += janken_result(T[i])
        result.append(1)
    elif T[i] != T[i-K]:
        point += janken_result(T[i])
        result.append(1)
    else:
        if result[i-K] == 0:
            point += janken_result(T[i])
            result.append(1)
        else:
            result.append(0)
        
print(point)

Submission status: Wrong Answer

Solution code:
"""
N K
R S P
T
"""

ln1 = input().split()
ln2 = input().split()
ln3 = input().split()

N, K = int(ln1[0]), int(ln1[1])
R, S, P = int(ln2[0]), int(ln2[1]), int(ln2[2])
T = ln3

point = 0

def janken_result(te):
    if te == "r":
        return P
    elif te == "s":
        return R
    elif te == "p":
        return S
    else:
        exit(0)

for i in range(N):
    if i < K:
        point += janken_result(T[i])
    elif T[i] != T[i-K]:
        point += janken_result(T[i])
    else:
        pass

print(point)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dict = {"r":p, "s":r, "p":s}
val = 0
mae = ""

for i in range(len(t)):
  if i <= k or t[i-k] != t[i]:
    val += dict[t[i]]

print(val)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R,S,P = map(int,input().split()) #point
T = input() #r or s or p

point = 0
janken = []
for text in range(len(T)):
    if T[text] == "r":
        if text > K-1 and janken[text-K] == "p":
            janken.append("r")
            point = point
        else:
            janken.append("p")
            point = point + P

    elif T[text] == "s":
        if text > K-1 and janken[text-K] == "r":
            point = point             
            janken.append("s")

        else:
            point = point + R
            janken.append("r")


    elif T[text] == "p":
        if text > K-1 and janken[text-K] == "s":
            point = point
            janken.append("p")

        else:    
            point = point + S
            janken.append("s")


print(point)

Submission status: Wrong Answer

Solution code:
#r=gu,s=tyoki,p=pa-
N,K = map(int,raw_input().split())
R,S,P = map(int,raw_input().split())
T = raw_input()
ans = 0
win = []
for i in range(len(T)):
  if T[i] == "r":
    win.append("p")
  elif T[i] == "s":
    win.append("r")
  elif T[i] == "p":
    win.append("s")
    
for i in range(K,len(win)):
  if win[i] == win[i-K]:
    if win[i] == "r":
      win[i] = "s"
    elif win[i] == "s":
      win[i] = "p"
    elif win[i] == "p":
      win[i] = "r"
  else:
    if win[i] == "r":
      ans = ans + R
    elif win[i] == "s":
      ans = ans + S
    else:
      ans = ans + P
  #print ans

for i in range(0,K):
  if win[i] == "r":
    ans = ans + R
  elif win[i] == "s":
    ans = ans + S
  else:
    ans = ans + P
  #print ans
#print win
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
me=[]
point=0
for i in range(N):
  if T[i]=="r":
    me.append("p")
  elif T[i]=="s":
    me.append("r")
  elif T[i]=="p":
    me.append("s")
for m in range(N):
  if me[m]==me[m-K]:
    me[m]=T[m]
    
for j in range(N):
  if me[j]==T[j]:
    point +=0
  else:
    if me[j]=="s":
      point +=S
    elif me[j]=="p":
      point +=P
    elif me[j]=="r":
      point +=R
print(me)

Submission status: Wrong Answer

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

r1 = []
for j in range(N):
	if T[j] == 'r':
		r1.append(P)
	elif T[j] == 's':
		r1.append(R)
	else:
		r1.append(S)
r2 = []
for i1 in range(K):
  r2.append(r1[i1])
  
for i in range(K,N):
	if r1[i] == r1[i - K]:
		if r2[i-K] == 0:
			r2.append(r1[i])
		else:
			r2.append(0)
	else:
		r2.append(r1[i])

print(sum(r2))

Submission status: Wrong Answer

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

r1 = []
for j in range(N):
	if T[j] == 'r':
		r1.append(P)
	elif T[j] == 's':
		r1.append(R)
	else:
		r1.append(S)

for i in range(K,N):
	if r1[i] == r1[i - K]:
		if r1[i] != r1[i - K * 2] and (i - K * 2) > -1:
			r1[i] = 0
print(sum(r1))

Submission status: Wrong Answer

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

def point(str):
    if str=="r":
        return P,"p"
    elif str=="s":
        return R,"r"
    elif str=="p":
        return S,"s"

DP=[[] for i in range(N)]

ans=0
for i in range(N):
    if i<K:
        temp,DP[i]=point(T[i])
        ans+=temp
    else:
        temp,temD=point(T[i])
        if not temD==DP[i-K]:
            DP[i]=temD
            ans+=temp
        else:
            DP[i]=T[i]
print(ans)

Submission status: Wrong Answer

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

r1 = []
for j in range(N):
	if T[j] == 'r':
		r1.append(P)
	elif T[j] == 's':
		r1.append(R)
	else:
		r1.append(S)

for i in range(K,N):
	if r1[i] == r1[i - K]:
		r1[i] = 0
print(sum(r1))

Submission status: Wrong Answer

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

r1 = []
for j in T:
	if j == 'r':
		r1.append(P)
	elif j == 's':
		r1.append(R)
	else:
		r1.append(S)

for i in range(K, len(r1)):
	if r1[i] == r1[i - K]:
		r1[i] = 0
print(sum(r1))

Submission status: Wrong Answer

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


def win(h):
    if h == 'r':
        return P
    elif h == 's':
        return R
    else:
        return S


score = []
for i in range(N):
    if i < K:
        score.append(win(T[i]))
    else:
        s = win(T[i])
        if s != score[i - K]:
            score.append(s)
        else:
            score.append(0)


print(sum(score))

Submission status: Wrong Answer

Solution code:
import math


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



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


# Lets wrirte a  Greedy SOlution

def determine_R_P_S(val):
    if val == "r":
        return "p"
    elif val == "p":
        return "s"
    else:
        return "r"
    
def add_profit(machine_val, you_played, succeed, R, P, S):
    if machine_val == "r":
        if succeed == 1:
            return P
        else:
            return 0

    if machine_val == "p":
        if succeed == 1:
            return S
        else:
            return 0

    if machine_val == "s":
        if succeed == 1:
            return R
        else:
            return 0
    


def total_profit(T, R, P, S, K):
    profit = 0
    for i in range(0, K+1):
        I_played = determine_R_P_S(T[i])
        profit += add_profit(T[i], I_played, 1, R, P, S)

    for i in range(K+1, N):
        I_played = determine_R_P_S(T[i])
        I_played_previous = determine_R_P_S(T[i - K])
        if I_played != I_played_previous:
            profit += add_profit(T[i], I_played, 1, R,  P, S)
        else:
            profit += add_profit(T[i], I_played, 0, R,  P, S)
    
    return profit



print(total_profit(T, R, P, S, K))

Submission status: Wrong Answer

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

def score(c):
	if c=="r":
		return p
	elif c=="s":
		return r
	else:
		return s

ans = 0
for i in range(n):
	if i < k:
		ans+=score(t[i])
	else:
		if t[i] == t[i-k]:
			if i >= 2*k and t[i]==t[i-2*k]:
				ans+=score(t[i])
		else:
			ans+=score(t[i])
print(ans)

Submission status: Wrong Answer

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

#output
from collections import Counter

x = T.count("r")
y = T.count("s")
z = T.count("p")

for i in range(K):
    Q = T[i::K]
    M = len(Q)
    x_temp = 0
    y_temp = 0
    z_temp = 0
    for i in range(M-1):
        if Q[i] == Q[i+1] == "r":
            x_temp += 1
            x_temp %= 2
            x -= x_temp
            y_temp = 0
            z_temp = 0
        if Q[i] == Q[i+1] == "s":
            y_temp += 1
            y_temp %= 2
            y -= y_temp
            z_temp = 0
            x_temp = 0
        if Q[i] == Q[i+1] == "p":
            z_temp += 1
            z_temp %= 2
            z -= z_temp 
            x_temp = 0
            y_temp = 0

answer = x*P + y*R + z*S 
print(answer)

Submission status: Wrong Answer

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

#output
from collections import Counter
answer = 0

x = T.count("r")
y = T.count("s")
z = T.count("p")

for i in range(K):
    Q = T[i::K]
    M = len(Q)
    x_temp = 0
    y_temp = 0
    z_temp = 0
    for i in range(M-1):
        if Q[i] == Q[i+1] == "r":
            x_temp += 1
            x_temp %= 2
            x -= x_temp
        if Q[i] == Q[i+1] == "s":
            y_temp += 1
            y_temp %= 2
            y -= y_temp
        if Q[i] == Q[i+1] == "p":
            z_temp += 1
            z_temp %= 2
            z -= z_temp 

answer = x*P + y*R + z*S 
print(answer)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
point=0
l=[]
point_list=[r,s,p]
kind=['r','s','p','r']
for i in range(n):
  for j in range(len(kind)-1):
    if t[i]==kind[j]:
      if i-k>=0 and t[i]==kind[l[i-k]+1]:
        if i+k<n and t[i+k]==kind[j+1]:
          if j==2:j=-1
          l.append(j+1)
        else:
          l.append(j)
      else:
        point+=point_list[j-1]
        if j==0:j=3
        l.append(j-1)
      break
print(l)
print(point)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

num = []
for i in range(len(t)):
    char = t[i]
    if char == "r":
        point = p
    elif char =="s":
        point = r
    else:
        point = s
    
    if i > (k-1):
        if point == num[i -k]:
            point = 0
    num.append(point)
    
print(sum(num))

Submission status: Wrong Answer

Solution code:
#149_d:greedy
n,k = [int(i) for i in input().split()]
r,s,p =[int(i) for i in input().split()]
t = input()

dic = dict()
dic["r"]=p
dic["s"]=r
dic["p"]=s

ans = []
for i in range(k):
    ans.append(dic[t[i]])
    
for i in range(n-k):
    char = t[k+i]
    ans.append(dic[char])
    if ans[-1]==ans[-1-k]:
        ans[-1]=0

print(sum(ans))

Submission status: Wrong Answer

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


def subtotal(sub_T):
    #dp[hand, sub_total_point]
    dp = [['non', 0]]
    sub_total_point = 0

    for i in range(0,len(sub_T)):
        hand = sub_T[i]
        print(str(i)+ ':' + sub_T[i])
        if hand != dp[i][0]:
            if hand == 'r':
                sub_total_point += P
            elif hand == 's':
                sub_total_point += R
            elif hand == 'p':
                sub_total_point += S
            else:
                pass

        else:
            hand = 'n'

        dp.append([hand,sub_total_point])

    return sub_total_point

def main():
    total_point = 0

    if K==1:
        total_point += subtotal(T)

    else:
        for m in range(0, K):
            sub_T = []
            for n in range(0, int(N/K)+1):
                if n*K+m < N:
                    sub_T.append(T[n*K+m])
                else:
                    pass

            total_point += subtotal(sub_T)

    print(total_point)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
r, s, p = LI()
D = {'r': p, 'p': s, 's': r}
t = S()
flag = [1] * n
ans = 0
for i in range(n):
    if i <= k:
        ans += D[t[i]]
    else:
        if t[i - k] == t[i] and flag[i - k]:
            flag[i] = 0
        else:
            ans += D[t[i]]



print(ans)

Submission status: Wrong Answer

Solution code:
def cal(x, R, S, P):
  if x == 'r':
    return P
  elif x == 's':
    return R
  else:
    return S

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
point = 0
j0 = T[0]
flg = 0
for l in range(K):
  for i, j in zip(range(N), T):
    if i % K == l:
      if j != j0 or flg == 0:
        point += cal(j, R, S, P)
        print(i, j, point)
        if j == j0:
          flg = 1
        else:
          flg = 0
    j0 = j
print(point)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
r, s, p = map(int,input().split())
l = list(input())
ans = 0

def jan(a):
  if a == "r":
    return p
  elif a == "s":
    return r
  return s

for i in range(len(l)):
  if i<k:
    ans += jan(l[i]) 
  elif l[i] != l[i-k]:
    ans += jan(l[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
U = []
ans = 0

for t in T:
    if t == 'r':
        U.append(P)
    elif t == 's':
        U.append(R)
    else:
        U.append(S)

for i in range(K):
    check = U[i]
    ans += check
    while True:
        i += K
        if i >= N:
            break
        if check == U[i]:
            check = -1
        else:
            ans += U[i]
            check = U[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
U = []
ans = 0

for t in T:
    if t == 'r':
        U.append(P)
    elif t == 's':
        U.append(R)
    else:
        U.append(S)

for i in range(K):
    check = U[i]
    ans += check
    while True:
        print(ans)
        i += K
        if i >= N:
            break
        if check == U[i]:
            check = '-1'
        else:
            ans += U[i]
            check = U[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())
score = 0
prev = "a"
for i in range(0,K):
    for j in range(i,N,K):
        if prev != T[j:j+1]:
            if T[j:j+1] == "r":
                score += P
            elif T[j:j+1] == "s":
                score += R
            else:
                score += S
            prev = T[j:j+1]
        else:
            prev = ""
print(score)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
U = []
ans = 0

for t in T:
    if t == 'r':
        U.append(P)
    elif t == 's':
        U.append(R)
    else:
        U.append(S)

for i in range(K):
    check = U[i]
    ans += int(check)
    while True:
        i += K
        if i >= N:
            break
        if check == U[i]:
            if check == 'r' and U[i+K] == 'r':
                ans += max(R,S)
            elif check == 'r' and U[i+K] == 's':
                ans += S
            elif check == 'r' and U[i+K] == 'p':
                ans += R
            elif check == 's' and U[i+K] == 's':
                ans += max(P,S)
            elif check == 's' and U[i+K] == 'r':
                ans += S
            elif check == 's' and U[i+K] == 'p':
                ans += P
            elif check == 'p' and U[i+K] == 'p':
                ans += max(P,R)
            elif check == 'p' and U[i+K] == 's':
                ans += P
            else:
                ans += R
            check = '-1'
        else:
            ans += int(U[i])
            check = U[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
R,S,P = input().split()
T = input()
U = []
ans = 0

for t in T:
    if t == 'r':
        U.append(P)
    elif t == 's':
        U.append(R)
    else:
        U.append(S)

for i in range(K):
    check = U[i]
    ans += int(check)
    while True:
        i += K
        if i >= N:
            break
        if check == U[i]:
            check = '-1'
        else:
            ans += int(U[i])
            check = U[i]
print(ans)

Submission status: Wrong Answer

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

dasita_te = []

score = 0

for i, c in enumerate(t):
    if c == "r":
        if (i >= k and dasita_te[i - k] != "p") or i < k:
            score += p
            dasita_te.append("p")
        else:
            dasita_te.append("-")
    elif c == "s":
        if (i >= k and dasita_te[i - k] != "r") or i < k:
            score += r
            dasita_te.append("r")
        else:
            dasita_te.append("-")
    elif c == "p":
        if (i >= k and dasita_te[i - k] != "s") or i < k:
            score += s
            dasita_te.append("s")
        else:
            dasita_te.append("-")
    print(i, score)

print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
rsp = list(map(int, input().split()))
t = input()
ans = 0
d = {'r': 2, 's':0, 'p': 1}
for c in t:
  ans += rsp[d[c]]
for i in range(k):
  prev = t[i]
  seq = 1
  for j in range(i+k, n, k):
    if t[j] == prev:
      seq += 1
    else:
      ans -= rsp[d[prev]] * (seq // 2)
      prev = t[j]
      seq = 1
    ans -= rsp[d[prev]] * (seq // 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
p,r,s=map(int,input().split())
mc=input()
ans=0
for i in range(len(mc)):
  if i>=k and mc[i-k]!=mc[i]:
    if mc[i]=='r':
      ans+=r
    elif mc[i]=='p':
      ans+=p
    else:
      ans+=s

Submission status: Wrong Answer

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

hands = ['r', 's', 'p']
for i,t in enumerate(T):
    if t == 'r':
        T[i] = 'p'
    elif t == 's':
        T[i] = 'r'
    else:
        T[i] = 's'
point = 0
for i,t in enumerate(T):
    if i+1 <= K:
        if t == 'r':
            point += R
        elif t == 's':
            point += S
        else:
            point += P
        continue
    print(i)
    if t == T[i-K]:
        # print(i)
        a = 0
        if len(T)-1 < i+K:
            next_hand = T[i]
        else:
            next_hand = T[i+K]
        while T[i] == T[i-K] or T[i] == next_hand:
            T[i] = hands[a]
            a += 1
    else:
        if t == 'r':
            point += R
        elif t == 's':
            point += S
        else:
            point += P
print(point)

Submission status: Wrong Answer

Solution code:
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"
      elif(T[i]=="p"):
        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"
      elif(T[i]=="p"):
        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()

Submission status: Wrong Answer

Solution code:
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()