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

point = {"r":p, "s":r, "p":s}

log = [0 for _ in range(k)] 
ans = 0

for i, play in enumerate(t):

    if point[play] == log[i % k]:
        log[i % k] = 0
        continue
    log[i % k] = point[play]
    ans += point[play]
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
count_rsp = [0,0,0]
for i in range(k):
  hand = ['N']*(n//k+1)
  if t[i] == 'r':
      hand[0] = 'p'
      count_rsp[2] += 1
  elif t[i] == 's':
      hand[0] = 'r'
      count_rsp[0] += 1
  else:
      hand[0] = 's'
      count_rsp[1] += 1
  for j in range(i+k,n,k):
    if t[j] == 'r':
      if hand[j//k-1] != 'p':
        hand[j//k] = 'p'
        count_rsp[2] += 1
      else:
        if j+k < n and t[j+k] == 'p':
          hand[j//k] = 'r'
        else:
          hand[j//k] = 's'
    elif t[j] == 's':
      if hand[j//k-1] != 'r':
        hand[j//k] = 'r'
        count_rsp[0] += 1
      else:
        if j+k < n and t[j+k] == 's':
          hand[j//k] = 'p'
        else:
          hand[j//k] = 's'
    else:
      if hand[j//k-1] != 's':
        hand[j//k] = 's'
        count_rsp[1] += 1
      else:
        if j+k < n and t[j+k] == 's':
          hand[j//k] = 'p'
        else:
          hand[j//k] = 'r'
print(count_rsp[0]*r+count_rsp[1]*s+count_rsp[2]*p)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
count_rsp = [0,0,0]
for i in range(k):
  hand = ['N']*(n//k+1)
  if t[i] == 'r':
      hand[0] = 'p'
      count_rsp[2] += 1
  elif t[i] == 's':
      hand[0] = 'r'
      count_rsp[0] += 1
  else:
      hand[0] = 's'
      count_rsp[1] += 1
  for j in range(i+k,n,k):
    if t[j] == 'r':
      if hand[j//k-1] != 'p':
        hand[j//k] = 'p'
        count_rsp[2] += 1
      else:
        if j+k < n and t[j+k] == 'p':
          hand[j//k] = 'p'
        else:
          hand[j//k] = 'r'
    elif t[j] == 's':
      if hand[j//k-1] != 'r':
        hand[j//k] = 'r'
        count_rsp[0] += 1
      else:
        if j+k < n and t[j+k] == 's':
          hand[j//k] = 's'
        else:
          hand[j//k] = 'r'
    else:
      if hand[j//k-1] != 's':
        hand[j//k] = 's'
        count_rsp[1] += 1
      else:
        if j+k < n and t[j+k] == 's':
          hand[j//k] = 'p'
        else:
          hand[j//k] = 'r'
print(count_rsp[0]*r+count_rsp[1]*s+count_rsp[2]*p)

Submission status: Wrong Answer

Solution code:
import copy

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

#rock,scissor,paper
#P   ,R      ,S
hands =  ["r","s","p"]
points = [P,R,S]

flgs = [[] for i in range(N)]
flg = [0,0,0]

total = 0

for i in range(K):
  h = hands.index(H[i])
  total += points[h]
  flg[h] += 1
  flgs[i] = copy.deepcopy(flg)

for i in range(K,N):
  h = hands.index(H[i])
  f = flgs[i - K][h]
  if f % 2 == 0:
    total += points[h]
  flg[h] += 1
  flgs[i] = copy.deepcopy(flg)
    
print(total)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
d = [[] for _ in range(K)]

for i, s in enumerate(input()):
    score = R if s=="s" else S if s=="p" else P
    d[i%K].append(score)

ans = 0
for l in d:
    prev_value = 10**5
    same_count = 0
    for i in l:
        if i!=prev_value:
            ans += i
            if same_count>0:
                ans += prev_value * (same_count//2)
            same_count = 0
        else:
            same_count += 1
        
        prev_value = i
    if same_count>0:
        ans += prev_value * (same_count//2)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
d = [[] for _ in range(K)]

for i, s in enumerate(input()):
    score = R if s=="s" else S if s=="p" else P
    d[i%K].append(score)

ans = 0
for l in d:
    prev_value = 10**5
    for i in l:
        if i!=prev_value:
            ans += i
            prev_value = i
        else:
            prev_value = 10**5

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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(N):
    if i >= K:
        if T[i] == T[i-K]:
            continue

    if T[i] == "r":
        ans += P
    elif T[i] == "s":
        ans += R
    else:
        ans += S
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().rstrip().split(' ')]
R,S,P = [int(i) for i in input().rstrip().split(' ')]
r = 0
T = input()
te = ["p","r","s"]
point = {"p":P,"r":R,"s":S}
Play = []
for i,t in enumerate(T):
    best = te[te.index(t)-1]
    if Play[i-K] != best if i >= K else True:
        Play += [best]
        r += point[best]
    else:
        Play += [t]
print(r)

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().rstrip().split(' ')]
R,S,P = [int(i) for i in input().rstrip().split(' ')]
r = 0
T = input()
Play = []
def bK(i,t):
    global Play
    if i+1 > K:
        return Play[i-K] != t
    else:
        return True

for i,t in enumerate(T):
    if t == "r":
        if bK(i,"p"):
            r += P
            Play += ["p"]
        else:
            Play += ["r"]
    elif t == "s":
        if bK(i,"r"):
            r += R
            Play += ["r"]
        else:
            Play += ["s"]
    elif t == "p":
        if bK(i,"s"):
            r += S
            Play += ["s"]
        else:
            Play += ["p"]

print(r)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
ans = 0
temp = t[:]
desirable = t[:]
for i in range(0, k):
  if t[i] == 'r':
    desirable[i] = 'p'
  elif t[i] == 's':
    desirable[i] = 'r'
  elif t[i] == 'p':
    desirable[i] = 's'
for i in range(0, k):
  if t[i] == 'r':
    temp[i] = 'p'
    ans += p
  elif t[i] == 's':
    temp[i] = 'r'
    ans += r
  elif t[i] == 'p':
    temp[i] = 's'
    ans += s
for i in range(k, n):
  if t[i] == 'r' and temp[i - k] != 'p':
    ans += p
    temp[i] = 'p'
  elif t[i] == 'r' and temp[i - k] == 'p':
    if i + k < n:
      if desirable[i + k] == 's':
        temp[i] = 'r'
      elif desirable[i + k] == 'r':
        temp[i] = 's'
      else:
        temp[i] = 's'
  if t[i] == 's' and temp[i - k] != 'r':
    ans += r
    temp[i] = 'r'
  elif t[i] == 's' and temp[i - k] == 'r':
    if i + k < n:
      if desirable[i + k] == 's':
        temp[i] = 'p'
      elif desirable[i + k] == 'p':
        temp[i] = 's'
      else:
        temp[i] = 's'
  if t[i] == 'p' and temp[i - k] != 's':
    ans += s
    temp[i] = 's'
  elif t[i] == 'p' and temp[i - k] == 's':
    if i + k < n:
      if desirable[i + k] == 'r':
        temp[i] = 'p'
      elif desirable[i + k] == 'p':
        temp[i] = 'r'
      else:
        temp[i] = 'r'
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
temp = t[:]
desirable = t[:]
for i in range(0, k):
  if t[i] == 'r':
    desirable[i] = 'p'
  elif t[i] == 's':
    desirable[i] = 'r'
  elif t[i] == 'p':
    desirable[i] = 's'
for i in range(0, k):
  if t[i] == 'r':
    temp[i] = 'p'
    ans += p
  elif t[i] == 's':
    temp[i] = 'r'
    ans += r
  elif t[i] == 'p':
    temp[i] = 's'
    ans += s
for i in range(k, n):
  if t[i] == 'r' and temp[i - k] != 'p':
    ans += p
    temp[i] = 'p'
  elif t[i] == 'r' and temp[i - k] == 'p':
    if i + k < n:
      if desirable[i + k] == 's':
        temp[i] = 'r'
      elif desirable[i + k] == 'r':
        temp[i ] = 's'
  if t[i] == 's' and temp[i - k] != 'r':
    ans += r
    temp[i] = 'r'
  elif t[i] == 's' and temp[i - k] == 'r':
    if i + k < n:
      if desirable[i + k] == 's':
        temp[i] = 'p'
      elif desirable[i + k] == 'p':
        temp[i ] = 's'
  if t[i] == 'p' and temp[i - k] != 's':
    ans += s
    temp[i] = 's'
  elif t[i] == 'p' and temp[i - k] == 's':
    if i + k < n:
      if desirable[i + k] == 'r':
        temp[i] = 'p'
      elif desirable[i + k] == 'p':
        temp[i ] = 'r'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n, k = na()
    r, s, p = na()
    t = ns()

    memo = []
    ans = 0
    for i, tt in enumerate(t):
        if tt == "r":
            if len(memo) >= k:
                if memo[i-k] != "p":
                    memo.append("p")
                    ans += p
                else:
                    memo.append("r")
            else:
                memo.append("p")
                ans += p
        elif tt == "s":
            if len(memo) >= k:
                if memo[i-k] != "r":
                    memo.append("r")
                    ans += r
                else:
                    memo.append("s")
            else:
                memo.append("r")
                ans += r
        elif tt == "p":
            if len(memo) >= k:
                if memo[i-k] != "s":
                    memo.append("s")
                    ans += s
                else:
                    memo.append("p")
            else:
                memo.append("s")
                ans += s
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
r,s,p=map(int,input().split())
a=list(input())
b=[]
t=0
for i in range(k):
    if a[i]=='r':
        b.append('p')
        t+=p
    elif a[i]=='s':
        b.append('r')
        t+=r
    else:
        b.append('s')
        t+=s
for i in range(k,n):
    
    if a[i]=='r' and b[i-k]!='p':
        b.append('p')
        t+=p
    elif a[i]=='r' and b[i-k]=='p':
        b.append('r')
    elif a[i]=='s' and b[i-k]!='r':
        b.append('r')
        t+=r
    elif a[i]=='s' and b[i-k]=='r':
        b.append('s')
    elif a[i]=='p' and b[i-k]!='s':
        b.append('s')
        t+=s
    elif a[i]=='p' and b[i-k]=='s':
        b.append('p')

print(t)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def pin(type=int):
    return map(type,input().split())
N,K =pin()
R,S,P =pin()
T, =pin(str)


#Tに勝つ手を列挙する 
winT = []
win = "rpsr"
for i in range(N):
    for j in range(3):
        if T[i] ==win[j]:
            winT.append(win[j+1])
print(winT)

#K個前の手を使えない条件…？
print(K,"個前を使えない")
#i番目に使った手をi+K番目に使えない.使ったら消す
for i in range (N-K):
    if winT[i] == winT[i+K]:
        winT[i+K] = "0"
        print(i)
print(winT)

ans=0
for i in range(N):
    if winT[i]=="p":
        ans+=P
    elif winT[i]=="r":
        ans+=R
    elif winT[i]=="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()

#K個先が同じならK個先は勝てない(しょうがない)

#文字列のままだと操作しづらい(かつ遅い)のでリストにする
T = list(T)

for i in range(len(T)-K-1):    
    #K回先が同じ手ならK回先は勝負を捨てて得点の対象外とする
    if T[i] == T[i+K]:
        T[i+K] = 'n'

ans = R*T.count('s') + S*T.count('p') + P*T.count('r')

print(ans)

Submission status: Wrong Answer

Solution code:

#答えは合計点なのでどの手を選ぶかは厳密に考えなくてよい

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

T = input()

#K個先が同じならK個先は勝てない(しょうがない)

#文字列のままだと操作しづらい(かつ遅い)のでリストにする
T = list(T)

for i in range(len(T)-K-1):    
    #K回先が同じ手ならK回先は勝負を捨てて得点の対象外とする
    if T[i] == T[i+K]:
        T[i+K] = 'n'

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

#K個先が同じならK個先は勝てない(しょうがない)

T = list(T)

for i in range(len(T)-K-1):    
    #K回先が同じ手ならK回先は勝負を捨てて得点の対象外とする
    if T[i] == T[i+K]:
        T[i+K] = 'n'

ans = T.count('r')*P+T.count('s')*R+T.count('p')*S

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import floor, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
R, S, P = MAP()
T = input()

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

ideal = [win[x] for x in T]

ans = 0
for i in range(N):
  if i <= K:
    ans += point[ideal[i]]
  elif ideal[i-K] == ideal[i]:  # i の手を変える
    ideal[i] = None
  else:
    ans += point[ideal[i]]
print(ans)

Submission status: Wrong Answer

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

ans = []
for idx, t in enumerate(T):
    if t == 'r':
            ans.append(P)
    elif t == 's':
            ans.append(R)
    elif t == 'p':
            ans.append(S)

for i in range(N-K):
    if T[i] == T[i+K]:
        ans[i+K] = 0

print(sum(ans))

Submission status: Wrong Answer

Solution code:

#答えは合計点なのでどの手を選ぶかは厳密に考えなくてよい

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

T = input()

#K個先が同じならK個先は勝てない(しょうがない)

for i in range(len(T)-K-1):    
    #K回先が同じ手なら勝負は捨てて得点の対象外とする
    if T[i] == T[i+K]:
        T = T[:i+K] + 'n' + T[i+K+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()

ownPlays = ""

for i in range(N):
    if i - K >= 0:
        playsBackToKth = ownPlays[i - K]
        # if opponent plays s
        if T[i] == "s":
            if playsBackToKth == "r":
                ownPlays += "s"
            else:
                ownPlays += "r"

        elif T[i] == "p":
            if playsBackToKth == "s":
                ownPlays += "p"
            else:
                ownPlays += "s"

        elif T[i] == "r":
            if playsBackToKth == "p":
                ownPlays += "r"
            else:
                ownPlays += "p"
    else:
        if T[i] == "s":
            ownPlays += "r"
        elif T[i] == "p":
            ownPlays += "s"
        elif T[i] == "r":
            ownPlays += "p"

sum = 0
for i in range(N):
    if ownPlays[i] == "p" and T[i] != "p":
        sum += P
    elif ownPlays[i] == "s" and T[i] != "s":
        sum += S
    elif ownPlays[i] == "r" and T[i] != "r":
        sum += R

print(sum)

Submission status: Wrong Answer

Solution code:
n,k=list(map(int,input().split()))
r,p,s=list(map(int,input().split()))
t=input()
vic=""
ans=0
for i in t:
    if i=="r":
        vic+="p"
    if i=="p":
        vic+="s"
    if i=="s":
        vic+="r"
#print(vic[:k])
for i in vic[:k]:
    if i=="r":
        ans+=r
    elif i=="p":
        ans+=p
    elif i=="s":
        ans+=s
#print(vic)
#print(ans)
for i in range(k,n):
    #print(i,":",vic[i])
    if vic[i]==vic[i-k]:
        #print("lose")
        if not i==n-1:
            vic=vic[:i]+'n'+vic[i+1:]
    else:
        #print("win")
        if vic[i]=="r":
            ans+=r
        elif vic[i]=="p":
            ans+=p
        elif vic[i]=="s":
            ans+=s
        else:
            pass
            #print("wrong input")

    #print()

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
opt = {
    "r": "p",
    "s": "r",
    "p": "s"
}
ans = 0
prev = []
for i, x in enumerate(T):
    if i - K >= 0 and opt[x] == prev[i-K]:
        prev.append(x)
    else:
        prev.append(opt[x])

for i, x in enumerate(prev):
    if x == T[i]:
        pass
    else:
        ans += eval(x.upper())
print(ans)

Submission status: Wrong Answer

Solution code:
#D
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=str(input())
te=[]
score=0
for i in range(n):
  if i>=k and t[i]==t[i-k]:#k回前に相手が同じ手を出している場合
    score+=0
    te.append(t[i])
  else:
    if t[i]=='r':
      score+=p
      te.append('p')
    elif t[i]=='s':
      score+=r
      te.append('r')
    elif t[i]=='p':
      score+=s
      te.append('s')
print(score)

Submission status: Wrong Answer

Solution code:
#D
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=str(input())
score=0
te=[]
for i in range(n):
  aite=t[i]
  if aite=='r':
    if i<k: #k回前まで気にしなくていい
      score+=p
      te.append('p')
    else:
      if te[i-k]=='p':
        te.append('r')
      else:
        score+=p
        te.append('p')
  elif aite=='s':
    if i<k: #k回前まで気にしなくていい
      score+=r
      te.append('r')
    else:
      if te[i-k]=='r':
        te.append('s')
      else:
        score+=r
        te.append('r')
  elif aite=='p':
    if i<k: #k回前まで気にしなくていい
      score+=s
      te.append('s')
    else:
      if te[i-k]=='s':
        te.append('p')
      else:
        score+=s
        te.append('s')
print(score)

Submission status: Wrong Answer

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

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

for i in range(K):
    scores.append(0)

add_score = 0
for i in range(len(T)):
    if scores[i] == scores[i+K]:
        scores[i+K] = 0
        add_score += scores[i]
    else:
        add_score += scores[i]

print(add_score)

Submission status: Wrong Answer

Solution code:
N, K = (int(nk) for nk in input().split())
R, S, P = (int(rsp) for rsp in input().split())
T = input()
score = 0
win_dir = {'r':'p', 's':'r', 'p':'s'}
my_te = ""
count = 0

def get_score(player, com):
  if player == 'r' and com == 's':
    return R
  elif player == 's' and com == 'p':
    return S
  elif player == 'p' and com == 'r':
    return P
  else:
    return 0

for te in list(T):
  if count >= K:
    if my_te[count-K] == win_dir[te]:
      my_te += te
    else:
      my_te += win_dir[te]
  else:
    my_te += win_dir[te]
  score += get_score(my_te[count], te)
  count += 1
print(score)

Submission status: Wrong Answer

Solution code:
N, K = (int(nk) for nk in input().split())
R, S, P = (int(rsp) for rsp in input().split())
T = input()
score = 0
win_dir = {'r':'p', 's':'r', 'p':'s'}
my_te = ""
count = 0

def get_score(player, com):
  if player == com:
    return 0
  elif player == 'r' and com == 's':
    return R
  elif player == 's' and com == 'p':
    return S
  elif player == 'p' and com == 'r':
    return P
  else:
    return 0

for te in list(T):
  if K > count:
    score += get_score(win_dir[te], te)
    my_te += win_dir[te]
  else:
    if win_dir[te] == my_te[count-K]:
      my_te += te
    else:
      score += get_score(win_dir[te], te)
      my_te += win_dir[te]
  count += 1
print(score)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
p=[int(x) for x in input().split()]
T=[0 if x=='r' else (1 if x=='s' else 2) for x in input()]
B=[-1]*K

s=0
for i in range(N):
  v=(T[i]+2)%3
  if v!=B[i%K]:
    s+=p[v]
    B[i%K]=v
  else:
    B[i%K]=T[i]
    if i<N-K:
      if (T[i+K]+2)%3!=T[i]:
        B[i%K]=(T[i]+1)%3

print(s)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
p=[int(x) for x in input().split()]
T=[0 if x=='r' else (1 if x=='s' else 2) for x in input()]
B=[-1]*K

s=0
for i in range(N):
  v=(T[i]+2)%3
  if v!=B[i%K]:
    s+=p[v]
    B[i%K]=v
  else:
    B[i%K]=T[i]
    if i<N-K:
      if (T[i+K]+2)%3!=T[i]:
        B[i%K]=(T[i+K]+1)%3

print(s)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
p=[int(x) for x in input().split()]
T=[0 if x=='r' else (1 if x=='s' else 2) for x in input()]
B=[-1]*K

s=0
for i in range(N):
  v=(T[i]+2)%3
  if v!=B[i%K]:
    s+=p[v]
    B[i%K]=v
  else:
    B[i%K]=T[i]

print(s)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
d = {"r":p, "s":r, "p":s}
t = list(input())
dp = [0]*n
for i in range(n):
  if i>k and dp[i-k]==d[t[i]]:
    dp[i] = 0
    t[i] = "x"
  else:
    dp[i] = d[t[i]]
print(sum(dp))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
d = {"r":p, "s":r, "p":s}
t = input()
dp = [0]*n
for i in range(n):
  if i<k and dp[i-k]==d[t[i]]:
    dp[i] = 0
    t[i] = x
  else:
    dp[i] = d[t[i]]
print(sum(dp))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
r, p, s = map(int, input().split())
d = {"r":s, "p":r, "s":p}
t = input()
dp = [0]*n
for i in range(n):
  if i<k and dp[i-k]==d[t[i]]:
    dp[i] = 0
    t[i] = x
  else:
    dp[i] = d[t[i]]
print(sum(dp))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
#r, s, p = map(int, input().split())
p, r, s = map(int, input().split())
#h = {"r":p, "s":r, "p":s}
t = input()
lst = []
for i in range(k):
  lst.append([t[j] for j in range(len(t)) if j%k==i])
ans = 0
#print(lst)
for b in lst:
  tmp = ""
  for i in b:
    if i!=tmp:
      ans+=eval(i)
      tmp=i
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import functools

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
l = list(map(int, input().split()))
a = lcm_list(l)
if a % 2 == 0:
    a = a // 2
print(-(-m // a) // 2)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K= [int(i) for i in input().split()]
R,S,P= [int(i) for i in input().split()]
n=input()
C=N//K + 1
T = np.zeros((K,C),dtype = int)

for i in range(N):
        a,b = divmod(i,K)
        
        if n[i] =='r':
                if a == 0: T[b][a] = P
                elif T[b][a-1]!=P:T[b][a] = P
        elif n[i] =='s':         
                if a == 0: T[b][a] = R
                elif T[b][a-1]!=R:T[b][a] = R
        elif n[i] =='p':
                if a == 0: T[b][a] = S
                elif T[b][a-1]!=S:T[b][a] = S
                        
print(T.sum())

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K= [int(i) for i in input().split()]
R,S,P= [int(i) for i in input().split()]
n=input()
C=N//K + 1
T = np.zeros((K,C),dtype = int)

for i in range(N):
        a,b = divmod(i,K)
        
        if n[i] =='r':
                T[b][a] = P
                
        elif n[i] =='s':         
                T[b][a] = R
                
        elif n[i] =='p':
                T[b][a] = S
#print(T)
for i in range(K):
        for j in range(C):
                #if T[i][j] == 0: break
                if (j!=0) and (T[i][j] == T[i][j-1]):
                        T[i][j] = 0
                        
print(T.sum())

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K= [int(i) for i in input().split()]
R,S,P= [int(i) for i in input().split()]
n=input()



C=N//K + 1



T = np.zeros((K,C),dtype = int)

for i in range(N):
        a,b = divmod(i,K)
        
        if n[i] =='r':
                T[b][a] = P
                
        elif n[i] =='s':         
                T[b][a] = R
                
        elif n[i] =='p':
                T[b][a] = S
#print(T)
for i in range(K):
        for j in range(C):
                #if T[i][j] == 0: break
                if (j!=0) and (T[i][j] == T[i][j-1]):
                        T[i][j] = 0
                        
print(np.sum(T))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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



C=N//K + 1
T = np.zeros((K,C),dtype = int)

for i in range(N):
        a,b = divmod(i,K)
        
        if n[i] =='r':
                T[b][a] = P
                
        elif n[i] =='s':         
                T[b][a] = R
                
        elif n[i] =='p':
                T[b][a] = S
#print(T)
if N < K: print(np.sum(T)) 
else :
        for i in range(K):
                for j in range(C):
                        if T[i][j] == 0: break
                        if (j!=0) and (T[i][j] == T[i][j-1]):
                                T[i][j] = 0
                        
        print(np.sum(T))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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



C=N//K + 1
T = np.zeros((K,C),dtype = int)

for i in range(N):
        a,b = divmod(i,K)
        
        if n[i] =='r':
                T[b][a] = P
                
        elif n[i] =='s':         
                T[b][a] = R
                
        elif n[i] =='p':
                T[b][a] = S
        
if N < K: print(np.sum(T)) 
else :
        for i in range(K):
                for j in range(C):
                        if T[i][j] == 0: break
                        if j!=0 and T[i][j] == T[i][j-1]:
                                T[i][j] = 0
                        
        print(np.sum(T))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

N,K= [int(i) for i in input().split()]
R,S,P= [int(i) for i in input().split()]
n=input()
C=N//K + 1
T = np.zeros((K,C),dtype = int)
r=[]
for i in range(N):
        a,b = divmod(i,K)
        
        if n[i] =='r':
                #r.append('p')
                T[b][a] = P
        elif n[i] =='s':
                #r.append('r')
                T[b][a] = R
        elif n[i] =='p':
                #r.append('s')
                T[b][a] = S
        
        
for i in range(K):
        for j in range(C):
                if T[i][j] == 0: break
                if j!=0 and T[i][j] == T[i][j-1]:
                        T[i][j] = 0
                        
print(np.sum(T))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
wp, wr, ws = map(int, input().split())
hand = {"p":wp, "r":wr, "s":ws}
t = input()
lst = []
for i in range(k):
  lst.append([t[j] for j in range(len(t)) if j%k==i])
ans = 0
for b in lst:
  tmp = ""
  for i in b:
    if i==tmp:
      tmp=""
    else:
      ans+=hand[i]
      tmp=i
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(" ")]
texts = list(input())

def can_key(i, 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, p):
            score += p
            last_h.append(p)
        else:
            # score += s
            last_h.append(r)

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

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

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