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 = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

point = 0

for i in range(n):
    if t[i]=="r":point+=p
    if t[i]=="s":point+=r
    if t[i]=="p":point+=s

for i in range(k+2):
    t+="a"

if k>=n/2:
    count = 0
    for i in range(n-k):
        if t[i]==t[k+i]:
            if t[i]=="r":count+=r
            if t[i]=="s":count+=s
            if t[i]=="p":count+=p
    print(point-count)
else:
    count = 0
    for i in range(k): #for each streams
        dub = 0
        num = 0
        num = n//k+1 if i+1<=n%k else n//k
        for j in range(num):
            if t[i+j*k]==t[i+(j+1)*k]:
                dub+=1
            else:
                if t[i+(j-1)*k]=="r" and dub!=0:
                    count += p*(dub//2)
                if t[i+(j-1)*k]=="s" and dub!=0:
                    count += r*(dub//2)
                if t[i+(j-1)*k]=="p" and dub!=0:
                    count += s*(dub//2)
                dub = 0


    print(int(point-count))

Submission status: Wrong Answer

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

def score(s):
  if s == 'r':
    output = P
  elif s == 's':
    output = R
  else:
    output = S
  return output

k_list = [0]*K 
answer = 0
for i in range(K):
  s = T[i]
  ind = i%K
  k_list[ind] = s
  answer += score(s)
  print(answer, k_list)
for j in range(K,N):
  s = T[j]
  ind = j%K
  if s == T[j-K] and k_list[ind] == s:
    k_list[ind] = 0
  elif s == T[j-K] and k_list[ind] != s:
    k_list[ind] = s
    answer += score(s)
  else:
    k_list[ind] = s
    answer += score(s)
  print(answer, k_list)

Submission status: Wrong Answer

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

################ DANGER ################
test = ""
#test = \
"""
5 2
8 7 6
rsrpr
ans 27
"""

"""
7 1
100 10 1
ssssppr
ans 211
"""

"""
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
ans 4996
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
        
n, k = map(int, input2().split())
r, s, p = map(int, input2().split())
t = list(input2())

rsp = {"r", "s", "p"}

for i in range(k, n-1):
    if t[i] == t[i-k]:
        t[i] = rsp - {t[i], t[i+1]}

ans = (t.count("r") * p +
       t.count("s") * r +
       t.count("p") * s)

print(ans)

Submission status: Wrong Answer

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

max_score = 0

score_by_hand = {"r": P, "s": R, "p": S}
result = 0
for k in range(K):
    column = T[k::K]
    max_score = score_by_hand[column[0]]
    conflicts = {hand: 1 for hand in ("r", "s", "p")}
    for i, hand in enumerate(column[1:]):
        if hand == column[i]:
            conflicts[hand] += 1
        max_score += score_by_hand[hand]
    for hand in ("r", "s", "p"):
        max_score = max_score - score_by_hand[hand] * (conflicts[hand] // 2)
    result += max_score

print(result)

Submission status: Wrong Answer

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

# N,K=7 ,1
# R,S,P=100 ,10, 1
# T="ssssppr"

# N,K=5, 2
# R,S,P=8, 7, 6
# T="rsrpr"

N,K=30, 5
R,S,P=325, 234, 123
T="rspsspspsrpspsppprpsprpssprpsr"


max_ans=T.count("s")*R+T.count("p")*S+T.count("r")*P
for i in range(K):
    tmp_ans=T[i::K]
    for i in range(len((tmp_ans))-1):
        if tmp_ans[i]==tmp_ans[i+1]:
            if tmp_ans[i]=="s":
                max_ans-=R
            if tmp_ans[i]=="p":
                max_ans-=S
            if tmp_ans[i]=="r":
                max_ans-=P
            tmp_ans = tmp_ans[:i+1] + 'X' +tmp_ans[i+2:]

print(max_ans)

Submission status: Wrong Answer

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

for i in range(n):
    if t[i] == "r":
        point.append(p)
    elif t[i] == "s":
        point.append(r)
    else:
        point.append(s)

for i in range(2, n):
    if point[i-2] == point[i]:
        point[i] = 0

print(sum(point))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N, K  = map(int, input().split())
R, S, P  = map(int, input().split())
T = list(input())
Group = [[0]*0 for h in range(K)]
Ans = 0

for i in range(len(T)):
    L = i % K
    Group[L].append(T[i])

for i in range(K):
    A = Group[i][0]
    Bit = 0
    for j in range(len(Group[i])):
        if Group[i][j] == A and Bit == 0:
            Bit = 1
            A = Group[i][j]
            if Group[i][j] == "r":
                Ans += P
            elif Group[i][j] == "s":
                Ans += R
            else:
                Ans += S
        elif Group[i][j] == A and Bit == 1:
            Bit = 0
            A = Group[i][j]
        else :
            Bit = 1
            A = Group[i][j]
            if Group[i][j] == "r":
                Ans += P
            elif Group[i][j] == "s":
                Ans += R
            else:
                Ans += S
print(Ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
t = input()
w= t.upper()
T = list(t)
WW = ''.join(w)
WW = WW.replace("R","p")
WW = WW.replace("S","r")
WW = WW.replace("P","s")
WW =WW.lower()
W = list(WW)

ans = 0


for i in range(len(W)):
    if W[i] == "r":
        ans += R
    elif W[i] == "s":
        ans += S
    else:
        ans += P



for i in range(n-k):
    if W[i] == W[i+k]:
        W[i+k] = T[i+k]
        if W[i+k] == "r":
            ans -= P
        elif W[i+k] == "s":
            ans -= R
        elif W[i+k] == "p":
            ans -= S
        

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(K):
    dp = [[0] * 3 for _ in range(N)]
    if T[i] == 'r':
        dp[i][2] = P
    if T[i] == 's':
        dp[i][0] = R
    if T[i] == 'p':
        dp[i][1] = S
    for j in range(i+K, N, K):
        if T[j] == 'r':
            dp[j][0] = max(dp[j-K][1], dp[j-K][2])
            dp[j][1] = max(dp[j-K][0], dp[j-K][2])
            dp[j][2] = max(dp[j-K][0], dp[j-K][1]) + P
        if T[j] == 's':
            dp[j][0] = max(dp[j-K][1], dp[j-K][2]) + R
            dp[j][1] = max(dp[j-K][0], dp[j-K][2])
            dp[j][2] = max(dp[j-K][0], dp[j-K][1])
        if T[j] == 'p':
            dp[j][0] = max(dp[j-K][1], dp[j-K][2])
            dp[j][1] = max(dp[j-K][0], dp[j-K][2]) + S
            dp[j][2] = max(dp[j-K][0], dp[j-K][1])
        if j + K >= N:
            ans += max(dp[j])
print(ans)

Submission status: Wrong Answer

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

ans = 0
count = 0
tt = ''
tmp = ''
for i in range(n):  
  if t[i] == 'r':
    if tmp == 'p' and i >= k:
      tt = 'r'
    else:
      tt = 'p'
      ans+=p
  elif t[i] == 's':
    if tmp == 'r' and i >= k:
      tt = 's'
    else:
      tt = 'r'
      ans+=r
  elif t[i] == 'p':
    if tmp == 's' and i >= k:
      tt = 'p'
    else:
      tt = 's'
      ans+=s
  if i % 2 == 0:
    tmp = tt
print(ans)

Submission status: Wrong Answer

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

dp = [[0, 0, 0] for _ in range(n)]
best_play = [0 for i in range(n)]

for play in range(n):
    c_play = t[play] 

    # print(f'play: {play} and c_play: {c_play}')

    # rock
    if c_play == 's':
        dp[play][0] = r
    # paper
    elif c_play == 'r':
        dp[play][1] = p

    # scissor
    elif c_play == 'p':
        dp[play][2] = s

    best_play[play] = max(dp[play])
    
    if play != 0:
        best_play[play] += best_play[play-1]

    # if passed first k plays
    if play - k >= 0:
        cry = dp[play-k]

        dp[play][0] += max(cry[1], cry[2])
        dp[play][1] += max(cry[0], cry[2])
        dp[play][2] += max(cry[1], cry[0])
        
        # cumulative sum of best after play - kth game till current
        # print(f'at: {play} and k: {k} and range sum args: {play-1} and {play-k}')
        range_ = best_play[play - 1] - best_play[play - k]
        # print(range_)
        dp[play] = list(map(lambda x: x + range_, dp[play]))
    else: # simple dp for first k plays
        if play == 0:
            continue

        prev = max(dp[play-1])
        dp[play] = list(map(lambda x: x + prev, dp[play]))

print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
def get_reward(x, r, s, p):
    if x == "r":
        return p
    if x == "s":
        return r
    if x == "p":
        return s


def rotate(x):
    if x == "r":
        return "s"
    if x == "s":
        return "p"
    if x == "p":
        return "r"


N, K = [int(i) for i in input().split(" ")]
R, S, P = [int(i) for i in input().split(" ")]
T = list(input())

total = 0

for i, x in enumerate(T):
    if i <= K-1:
        total += get_reward(x, R, S, P)
        continue
    if T[i-K] != x:
        total += get_reward(x, R, S, P)
        continue
    T[i] = rotate(x)


print(total)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
score_map = {
    "r": p,
    "p": s,
    "s": r,
}
score = [0] * n
for i, c in enumerate(t):
    score[i] = score_map[c]
for i, c in enumerate(score[k:]):
    if score[i] == c:
        score[i+k] = 0
print(sum(score))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
points=0
hands=[]
for i in range(n):
	if t[i]=='r':
		hands.append(p)
		points+=p
	if t[i]=='s':
		hands.append(r)
		points+=r
	if t[i]=='p':
		hands.append(s)
		points+=s
		
for i in range(k):
	j=i
	renzoku=1
	while j+k<n:
		if hands[j]==hands[j+k]:
			renzoku+=1
		else:
			points-=hands[j]*(renzoku//2)
			renzoku=1
		j+=k
	points-=hands[j]*(renzoku//2)
print(points)

Submission status: Wrong Answer

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

d = {"s":r, "p":s, "r":p}
score = 0
for idx in range(k):
    List = []
    for i in range(n):
        if idx+i*k > n-1:
            break
        else:
           List.append(t[idx+i*k])
    print(List)
    not_liset = True
    tmp = List[0]
    score += d[tmp]
    for i in range(1, len(List)):
        if tmp == List[i] and not_liset:
            not_liset = False
        else:
            score += d[List[i]]
            not_liset = True
        tmp = List[i]
print(score)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
score_map = {
    "r": p,
    "p": s,
    "s": r,
}
score = [0] * n
for i, c in enumerate(t):
    score[i] = score_map[c]
print(score)
for i, c in enumerate(score[k:]):
    print(c, score[i])
    if score[i] == c:
        score[i+k] = 0
print(score, sum(score))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

def win(m):
    if m == 0:
        return 2
    if m == 1:
        return  0
    if m == 2:
        return 1


N, K = MI()
RSP = LI()
T = input()

M = []
for t in T:
    if t == 'r':
        M.append(0)
    if t == 's':
        M.append(1)
    if t == 'p':
        M.append(2)

P = [win(m) for m in M]
PP = [RSP[p] for p in P]

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

print(sum(PP))

Submission status: Wrong Answer

Solution code:
def win_hand(h,r,s,p):
	if h=='r':
		return p
	elif h=='s':
		return r
	else:
		return s		
		
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
score=0
dp=[0]*(n+5)
dp[0]=win_hand(t[0],r,s,p)
for i in range(1,n):
	if i>k:
		if t[i]!=t[i-k]:
			dp[i]=max(dp[i-1],dp[i-1]+win_hand(t[i],r,s,p))
		else:
			dp[i]=dp[i-1]
	else:
		dp[i]=max(dp[i-1]+win_hand(t[i],r,s,p),dp[i-1])
print(dp[n-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
optimal = {'r':'p', 's':'r', 'p':'s'}
point = {'r':R, 's':S, 'p':P}
ans = 0

A = []

for i in range(0, N):
    if i <= K-1:
        A.append(optimal[T[i]])
        ans = ans + point[A[i]]
    elif A[i-K] != optimal[T[i]]:
        A.append(optimal[T[i]])
        ans = ans + point[A[i]]
    elif i + K <= N-1:
        if optimal[T[i]] != 'r' and optimal[T[i+K]] != 'r':
            A.append('s')
        elif optimal[T[i]] != 's' and optimal[T[i+K]] != 's':
            A.append('p')
        else:
            A.append('r')
    else:
        if optimal[T[i]] != 'r':
            A.append('s')
        elif optimal[T[i]] != 's':
            A.append('p')
        else:
            A.append('r')

print(ans)

Submission status: Wrong Answer

Solution code:
#############################
#
# じゃんけん説明
# r: グー
# s: チョキ
# p: パー
#
#############################
#
# 入力r -> 勝利時の グー の点数
# 入力s -> 勝利時の チョキ の点数
# 入力p -> 勝利時の パー の点数
#
#############################

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

MY_HAND = []
ANS = 0

for battle_time in range(n):
  if battle_time < k:
    if t[battle_time] == "r":
      MY_HAND.append("p")
      ANS += p
    
    if t[battle_time] == "s":
      MY_HAND.append("r")
      ANS += r
    
    if t[battle_time] == "p":
      MY_HAND.append("s")
      ANS += s
  else:
    if t[battle_time] == "r":
      if MY_HAND[battle_time-k] == "p":
        # TODO: 必要に応じて負けを選択しないといけない
        MY_HAND.append("r")
        ANS += 0
      else:
        MY_HAND.append("p")
        ANS += p

    if t[battle_time] == "s":
      if MY_HAND[battle_time-k] == "r":
        # TODO: 必要に応じて負けを選択しないといけない
        MY_HAND.append("s")
        ANS += 0
      else:
        MY_HAND.append("r")
        ANS += r
    
    if t[battle_time] == "p":
      if MY_HAND[battle_time-k] == "s":
        # TODO: 必要に応じて負けを選択しないといけない
        MY_HAND.append("p")
        ANS += 0
      else:
        MY_HAND.append("s")
        ANS += s

print(ANS)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()

dp = [0] * n
dic = {"r": P, "s": R, "p": S}

# print(dp, dic)

for i in range(n):
    if i >= k and dp[i - k] == dic[t[i]]:
        continue
    dp[i] = dic[t[i]]

print(sum(dp))

Submission status: Wrong Answer

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

te = {"r":p, "s":r, "p":s}
kioku = []
cnt = 0
for i, teki in enumerate(t):
    if len(kioku)<k:
        cnt += te[teki]
        kioku.append([te[teki],False])
    else:
        if kioku[i-k][0] == te[teki] and kioku[i-k][1] == False:
            kioku.append([te[teki],True])
        else:
            cnt += te[teki]
            kioku.append([te[teki],False])
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()] # グー：r チョキ：s パー：p
t = list(input())

addscoremap = {'r': p, 's': r, 'p': s}

score = 0

for i in range(n):
  if (0 < i-k) and (t[i] == t[i-k]):
    t[i] = 'x'
    continue
  score += addscoremap[t[i]]

print(score)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
d = {'r': 'p', 's': 'r', 'p': 's'}
a = {'r' : R, 's' : S, 'p' : P}
l = [d[s] for s in T]
cnt = 0
for i, s in enumerate(T):
    if i < K:
        cnt += a[l[i]]
        continue
    if s == 'r' and l[i-K] != 'p':
        cnt += P
    elif s == 'r' and l[i-K] == 'p':
        #cnt += R
        l[i] = 'r'

    if s == 's' and l[i-K] != 'r':
        cnt += R
    elif s == 's' and l[i-K] == 'r':
        #cnt += S
        l[i] = 's'

    if s == 'p' and l[i-K] != 's':
        cnt += S
    elif s == 'p' and l[i-K] == 's':
        #cnt += P
        l[i] = 'p'
print(cnt)

Submission status: Wrong Answer

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

for i in range(K):
    if T[i] == "r":
        ans[i] = P
    elif T[i] == "s":
        ans[i] = R
    else:
        ans[i] = S

for i in range(K, N):
    if T[i] == "r" and ans[i-K] != P:
        ans[i] = P
    elif T[i] == "s" and ans[i-K] != R:
        ans[i] = R
    elif T[i] == "p" and ans[i-K] != S:
        ans[i] = S
    else:
        ans[i] = 0
print(sum(ans))

Submission status: Wrong Answer

Solution code:
def get_reward(x, r, s, p):
    if x == "r":
        return p
    if x == "s":
        return r
    if x == "p":
        return s


def rotate(x):
    if x == "r":
        return "s"
    if x == "s":
        return "p"
    if x == "p":
        return "r"


N, K = [int(i) for i in input().split(" ")]
R, S, P = [int(i) for i in input().split(" ")]
T = list(input())

total = 0

for i, x in enumerate(T):
    if i <= K-1 or T[i-K] != x:
        total += get_reward(x, R, S, P)
        continue
    if i >= K:
        T[i] = rotate(x)


print(total)

Submission status: Wrong Answer

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

score = 0
for k in range(K):
    if T[k]=='r':
        score += P
    elif T[k]=='s':
        score += R
    else:
        score += S
    odd = False
    for n in range(K+k, N, K):
        print(n)
        if T[n-K] == T[n] and not odd:
            odd = True
        else:
            if T[n]=='r':
                score += P
            elif T[n]=='s':
                score += R
            else:
                score += S
            odd = False

print(score)

Submission status: Wrong Answer

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

count = 0
result = []

command = ["r", "s", "p"]

def next(x):
  if x == "r":
    return "p"
  elif x == "s":
    return "r"
  elif x == "p":
    return "s"

def get_point(x):
  if x == "r":
    return R
  elif x == "s":
    return S
  elif x == "p":
    return P

count = 0

def solve(index):
  global count
  n = next(T[index])
  could_not_win = len(result) >= K and result[-K] == n
  if not could_not_win:
    count += get_point(n)
    return n
  else:
    if N - 1 >= index + 2:
      m = next(T[index+2])
      return list(filter(lambda x: x != n and x != m, command))[0]
    else:
      # できるだけ得点が高いものを返したい
      highest = -1
      cs = list(filter(lambda x: x != n, command))
      x, y = get_point(cs[0]),  get_point(cs[1])
      if x > y:
        return cs[0]
      else:
        return cs[1]

for i in range(N):
  x = T[i]
  result.append(solve(i))

print(count)

Submission status: Wrong Answer

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

def janken(r, s, p, hand, khand):
    if hand == "r" and khand != "r":
        return(p)
    elif hand == "s" and khand != "s":
        return(r)
    elif hand == "p" and khand != "p":
        return(s)
    else:
        return(0)

score = 0
for i in range(n):
    if k >= i:
        khand = "no"
    else:
        khand = t[i - k]
    score += janken(r, s, p, t[i], khand)

print(score)

Submission status: Wrong Answer

Solution code:
N,K=[int(x) for x in input().split()]
R,S,P=[int(x) for x in input().split()]
T=input()
sum=0
hands=''
for i in range(K):

    if T[i] == 'r':
        sum+=P
        hands+='p'
    elif T[i] == 's':
        sum+=R
        hands+='r'
    elif T[i] == 'p':
        sum+=S
        hands+='s'

for i in range(K,N):

    if T[i] == 'r':
        if hands[i-K] != 'p':
            sum+=P
            hands+='p'
        else:
            hands+='r'

    elif T[i] == 's':
        if hands[i-K] != 'r':
            sum+=R
            hands+='r'
        else:
            hands+='s'

    elif T[i] == 'p':
        if hands[i-K] != 's':
            sum+=S
            hands+='s'
        else:
            hands+='p'
print(sum)

Submission status: Wrong Answer

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

#r - P
#s - R
#p - S

ans = [0] *len(T)
for i,x in enumerate(T):
  if x == 'r':
    ans[i] = P
  elif x == 's':
    ans[i] = R
  elif x == 'p':
    ans[i] = S
  
  if i >= K:
    if ans[i-K] == ans[i]:
      ans[i] = 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())
d=[]
ct=0
for i in range(k):
    for j in range(i,n-i,k):
        d.append(t[j])
    for l in range(len(d)-1):
        if d[l]==d[l+1]:
            d[l+1]='out'
    #print(d,i,n,k)
    ct+=d.count('r')*p+d.count('s')*r+d.count('p')*s
    d=[]
    #print(ct)
    #ct+=

print(ct)    
#print(t.count("r")*r+)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
R,S,P=map(int,input().split())
l=list(input())
play=[]

def point(hand):
    if hand=="r":
        return ["p",P]
    elif hand=="s":
        return ["r",R]
    else:
        return ["s",S]

ans=0
for i in range(N)[::-1]:
    if len(play)>=K:
        if point(l[i])[0]==play[-K]:
            if i-K>=0:
                temp=point(l[i-K])[0]
                for item in ["r","s","p"]:
                    if item!=play[-K] and item!=temp:
                        play.append(item)
                        break
            else:
                pass
        else:
            play.append(point(l[i])[0])
            ans+=point(l[i])[1]
            
    else:
        play.append(point(l[i])[0])
        ans+=point(l[i])[1]

#print(play)
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  if t[i] == "r":
    if i-k<0 or m[i-k]!="p":
      m.append("p")
      ans+=p
    elif i+k<n and t[i+k] != "r":
      m.append("r")
    else:
      m.append("s")
  elif t[i] == "s":
    if i-k<0 or m[i-k]!="r":
      m.append("r")
      ans+=r
    elif i+k<n and t[i+k] != "s":
      m.append("s")
    else:
      m.append("p")
  elif t[i]== "p":
    if i-k<0 or m[i-k]!="s":
      m.append("s")
      ans+=s
    elif i+k<n and t[i+k] != "r":
      m.append("r")
    else:
      m.append("p")
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N,K = map(int,input().split())

R,S,P = map(int,input().split())

T = input()
H = ''
score = 0

def janken(hands):
    if hands == 'r':
        my_hand = 'p'
    
    elif hands == 's':
        my_hand = 'r'
    
    else:
        my_hand = 's'

    return(my_hand)

def my_score(hands):
    if hands == 'r':
        my_score = R
    
    elif hands == 's':
        my_score = S
    
    else:
        my_score = P

    return(my_score)


for i in range(K):
    x = janken(T[i])
    H += x
    score += my_score(x)


for j in range(K,N):
    x = janken(T[j])
    if x == H[j-K]:
        H += T[j]
        #score += my_score(T[j])
    else:
        H += x
        score += my_score(x)
    


#print(H)
print(score)

Submission status: Wrong Answer

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

hands = ''
for i in range(n):
    if t[i] == 'r':
        hands += 'p'
    elif t[i] == 'p':
        hands += 's'
    else:
        hands += 'r'

cnt = 0
flg = True
for i in range(k,n):
    if hands[i] == hands[i-k]:
        hands = hands[:i] + t[i] + hands[i+1:]

for i in range(n):
    if (hands[i]=='r')&(t[i]=='s'):
        cnt += r
    elif (hands[i]=='s')&(t[i]=='p'):
        cnt += s
    elif (hands[i]=='p')&(t[i]=='r'):
        cnt += p
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy

# N回じゃんけん
# K回前の手は出せない
N, K = map(int, input().split())

# 得点
# グーで勝つ：R
# チョキで勝つ：S
# パーで勝つ: P
R,S,P = map(int, input().split())

# 筐体が出す手
# r=グー, s=チョキ, p=パー
T = input()
#print(T)
# 置換する

ans = copy.copy(T)
ans = ans.replace("r","P").replace("s", "R").replace("p", 'S')
#print(ans)

result = 0
for i in range(0, K):
    if ans[i] == "P":
        result += P
        #print("+", P)
    elif ans[i] == "R":
        result += R
        #print("+", R)
    elif ans[i] == "S":
        result +=S
        #print("+", S)
    #print(ans[i],result)
    
for i in range(K, len(ans)):
    # 2個前の手と同じだったら、0点にする
    if ans[i] == ans[i-K]:
        result +=0
        ans_list = list(ans)
        ans_list[i] = T[i].upper()
        ans = "".join(ans_list)
        #print("draw", ans)
    else:
        if ans[i] == "P":
            result += P
            #print("+", P)
        elif ans[i] == "R":
            result += R
            #print("+", R)
        elif ans[i] == "S":
            result +=S
            #print("+", S)
    #print(ans[i],result)

print(result)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
List = [[] for k in range(K)]
for n in range(N):
    List[n % K].append(T[n])

point = {'r': P, 's': R, 'p': S}
print(List)
score = 0
for k in range(K):
    L = List[k]
    count = 1
    length = len(L)
    for i in range(length):
        try:
            if L[i] == L[i+1]:
                count += 1
            else:
                score += point[L[i]]*((count+1)//2)
                count = 1
        except:
            score += point[L[i]]*((count+1)//2)
print(score)

Submission status: Wrong Answer

Solution code:
N, K = (int(i) for i in input().split())
R, S, P = (int(i) for i in input().split())
T = input()
hands = []

def add(s):
    if s == 'r': return P
    if s == 's': return R
    else: return S
   
def hand(s):
    if s == 'r': return 'p'
    if s == 's': return 'r'
    else: return 's'
         
point = 0
for i in range(N):
    if i < K: 
        hands.append(hand(T[i]))
        point += add(T[i])
    else:
        if hand(T[i]) != hands[i-K]:
            hands.append(hand(T[i]))
            point += add(T[i])
        else:
            hands.append(T[i])

print(point)

Submission status: Wrong Answer

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

score = {
  'r': r,
  's': s,
  'p': p
}

win_map = {
  'r': 'p',
  's': 'r',
  'p': 's'
}

result = [''] * n
result_num = 0
for j in range(n):
  if j >= k and result[j - k] == win_map[t[j]]:
    result[j] = t[j]
  else:
    result[j] = win_map[t[j]]
    result_num += score[win_map[t[j]]]


print(result_num)

Submission status: Wrong Answer

Solution code:
# K回前と現在の問いが同じだったら0点

str1 = input().split(" ")
str2 = input().split(" ")
t = input()

n = int(str1[0])
k = int(str1[1])

r = int(str2[0])
s = int(str2[1])
p = int(str2[2])

result = 0
douchilist = []
for i in range(0,n):
    if i >= k:
        print(t[i])
        print(t[i-k])
        if t[i] == t[i-k] and i-k not in douchilist:
            result += 0
            douchilist.append(i)
            continue

    
    if t[i] == "r":
        result += p
        continue

    if t[i] == "s":
        result += r
        continue

    if t[i] == "p":
        result += s
        continue


print(result)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c,d,e=map(int,input().split())
g=input()
l = a-b
for i in range(l):
   if g[i-1] == g[i-1+b]:
      g = g[:i-1+b] + 'a' + g[i+b:]
      
else:
  R = g.count('r')
  S = g.count('s')
  P = g.count('p')
  answer = c*S+d*P+e*R
  print(answer)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T=list(input())
kachi = {'r':'p', 's':'r', 'p':'s'}
aico = {'r':'r', 's':'s', 'p':'p'}
point = {'r':R, 's':S, 'p':P}
count = 0
me=['' for j in range(N)]

for i in range(N):
    if i<K:
        count = count + point[kachi[T[i]]]
        me[i] = kachi[T[i]]
    else:
        if me[i-K] == kachi[T[i]]:
            me[i] = aico[T[i]]
        else:
            count = count + point[kachi[T[i]]]
            me[i] = kachi[T[i]]
print(count)