Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02689 (python)

Fixed submission:
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
O = [0] + [1] * N
for _ in range(M):
    A, B = map(int, input().split())
    if H[A] <= H[B]:
        O[A] = 0
    if H[A] >= H[B]:
        O[B] = 0
print(sum(O))

Buggy submission (verdict: Runtime Error):

def main():
    N, M = map(int, input().split())
    H_list = [int(_) for _ in input().split()]

    # iso_list = []
    index_list = []
    for m in range(M):
        A, B = map(int, input().split())
        if H_list[A-1] > H_list[B-1]:
            index_list.append(B-1)
        elif H_list[A-1] < H_list[B-1]:
            index_list.append(A-1)
        elif H_list[A-1] == H_list[B-1]:
            index_list.append(A-1)
            index_list.append(B-1)
        # iso_list.append(A)
        # iso_list.append(B)        

    index_list = list(set(index_list))
    for i in index_list:
        del H_list[i]        

    # iso_list = list(set(iso_list))
    # iso_list = len(H_list - iso_list)
    
    # out = iso_list + 
    out = len(H_list)
    print(out)
main()

Buggy submission (verdict: Runtime Error):

def main():
    N, M = map(int, input().split())
    H_list = [int(_) for _ in input().split()]

    # iso_list = []
    index_list = []
    for m in range(M):
        A, B = map(int, input().split())
        if H_list[A-1] > H_list[B-1]:
            index_list.append(B-1)
        elif H_list[A-1] < H_list[B-1]:
            index_list.append(A-1)
        elif H_list[A-1] < H_list[B-1]:
            index_list.append(A-1)
            index_list.append(B-1)
        # iso_list.append(A)
        # iso_list.append(B)        

    index_list = list(set(index_list))
    for i in index_list:
        del H_list[i]        

    # iso_list = list(set(iso_list))
    # iso_list = len(H_list - iso_list)
    
    # out = iso_list + 
    out = len(H_list)
    print(out)
main()

Buggy submission (verdict: Runtime Error):

def main():
    N, M = map(int, input().split())
    H_list = [int(_) for _ in input().split()]

    # iso_list = []
    index_list = []
    for m in range(M):
        A, B = map(int, input().split())
        if H_list[A-1] > H_list[B-1]:
            index_list.append(B-1)
        elif H_list[A-1] < H_list[B-1]:
            index_list.append(A-1)
    
        # iso_list.append(A)
        # iso_list.append(B)        

    index_list = list(set(index_list))
    for i in index_list:
        del H_list[i]        

    # iso_list = list(set(iso_list))
    # iso_list = len(H_list - iso_list)
    
    # out = iso_list + 
    out = len(H_list)
    print(out)
main()
Problem p02695 (python)

Fixed submission:
import itertools

#19 choose 9
#92378

def main():
    N, M, Q = map(int, input().split())
    Q_l = []
    final_score = 0
    for i in range(Q):
        Q_l.append(list(map(int, input().split())))
    for A in itertools.combinations_with_replacement(range(1, M+1), N):
        score = 0
        for q in Q_l:
            if A[q[1]-1] - A[q[0]-1] == q[2]:
                score += q[3]
            final_score = max([final_score, score])
    print(final_score)
main()

Buggy submission (verdict: Runtime Error):
import itertools

#19 choose 9
#92378

def main():
    N, M, Q = map(int, input().split())
    Q = []
    final_score = 0
    for i in range(Q):
        Q.append(list(map(int, input().split())))
    for A in itertools.combinations_with_replacement(range(1, M+1), N):
        score = 0
        for q in Q:
            if A[q[1]-1] - A[q[0]-1] == q[2]:
                score += q[3]
            final_score = max([final_score, score])
    print(final_score)
main()

Buggy submission (verdict: Runtime Error):
import itertools

#19 choose 9
#92378

def main():
    N, M, Q = map(int, input().split())
    Q = []
    final_score = 0
    for i in range(Q):
        Q.append(list(map(int, input().split())))
    for A in itertools.combinations_with_replacement(range(1, M+1), N):
        score = 0
        for q in Q:
            if A[q[1]-1] - A[q[0]-1] == q[2]:
                score += q[3]
    out = max([final_score, score])
    print(out)
main()
Problem p02707 (python)

Fixed submission:
import math
def main():
    N = int(input())
    l = [int(_) for _ in input().split()]
    count_list = [0] * N
    for i in l:
        index = i - 1
        count_list[index] += 1

    for out in count_list:
        print(out)
main()

Buggy submission (verdict: Runtime Error):
import math
def main():
    N = map(int, input())
    l = [int(_) for _ in input().split()]
    count_list = [0] * N
    for i in l:
        index = i - 1
        count_list[index] += 1

    for out in count_list:
        print(out + '\n')
main()
Problem p02723 (python)

Fixed submission:
def main():
    s = input()
    if s[2]==s[3] and s[4]==s[5]:
            print('Yes')
    else:
        print('No')

main()

Buggy submission (verdict: Runtime Error):
def main():
    K, N = [int(_) for _ in input().split()]
    A = list(map(int, input().split()))
    mx = 0

    for i in range(N-1):
        dis = A[i+1]-A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    if (K-(se)) > mx:
        mx = K - se
    print(mx)
main()
Problem p02725 (python)

Fixed submission:
def main():
    K, N = [int(_) for _ in input().split()]
    A = list(map(int, input().split()))
    mx = 0

    for i in range(N-1):
        dis = A[i+1] - A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    
    if K-se > mx:
        mx = K - se
    print(K - mx)
main()

Buggy submission (verdict: Runtime Error):
def main():
    K, N = [int(_) for _ in input().split()]
    A = map(int, input().split())
    mx = 0

    for i in range(N-1):
        dis = A[i+1]-A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    if (k-(se)) > mx:
        mx = k - se
    print(mx)
main()
Problem p02879 (python)

Fixed submission:
def main():
    A, B = map(int, input().split())
    if A < 10 and B < 10:
        p = A * B
        print(p)
    else:
        print(-1)
main()

Buggy submission (verdict: Runtime Error):
def main():
    A, B = map(int, input().split())
    if A < 10 and B < 10:
        p = A * B
        print(p)
    else:
        print(p)
main()

Buggy submission (verdict: Runtime Error):
def main():
    A, B = map(int, input().split())
    if A <=10 and B <=10:
        p = A * B
        print(p)
    else:
        print(p)
main()
Problem p02880 (python)

Fixed submission:
import sys

def main():
    n = int(input())
    for i in range(1, 10, 1):
        if 1 <= n//i <= 9 and (n/i).is_integer():
            print('Yes')
            sys.exit()
    print('No')
    
main()

Buggy submission (verdict: Runtime Error):
import sys

def main():
    n = map(int, input().split())
    for i in range(1, 10, 1):
        if 1 <= n//i <= 9 and (n/i).is_integer():
            print('Yes')
            sys.exit()
    print('No')
main()

Buggy submission (verdict: Runtime Error):
import sys

def main():
    n = map(int, input().split())
    for i in range(1, 10, 1):
        if 1 <= n//i <= 9 and (n/i).is_integer():
            print('Yes')
            sys.exit()
        else:
            print('No')
main()

Buggy submission (verdict: Runtime Error):
def main():
    n = map(int, input().split())
    for i in range(1, 10):
        if 1 <= n//i <= 9 and (n/i).is_integer():
            print('Yes')
        else:
            print('No')
main()

Buggy submission (verdict: Runtime Error):
def main():
    n = map(int, input().split())
    for i in range(1, 10, 1):
        if 1 <= n//i <= 9:
            print('Yes')
        else:
            print('No')
main()
Problem p02659 (python)

Fixed submission:
a, b = input().split()
a = int(a)
b = round(float(b) * 100)
print(a * b // 100)

Buggy submission (verdict: Runtime Error):
n, m =map(double,input().split()) 

M = 10000*m
a = n * M
ans = float(a / 10000)
print(round(ans))

Buggy submission (verdict: Runtime Error):
n, m =map(double,input().split()) 

M = 10000*m
a = n * M
ans = float(a / 10000)
print(int(ans))
Problem p02699 (python)

Fixed submission:
s, w  = map(int,input().split())
if s <= w:
    print("unsafe")
else :
    print("safe")

Buggy submission (verdict: Runtime Error):
In [93]: s, w  = map(int,input().split()) 
    ...: if s <= w: 
    ...:     print("unsafe") 
    ...: else : 
    ...:     print("safe")

Buggy submission (verdict: Runtime Error):
In [93]: s, w  = map(int,input().split()) 
    ...: print("{} {}".format(s,w)) 
    ...: if s <= w: 
    ...:     print("unsafe") 
    ...: else : 
    ...:     print("safe")
Problem p02707 (python)

Fixed submission:
n =int(input())
s = list(map(int,input().split()))
l =[0]*n
i = 0
while i < n-1 :
     l[s[i]-1] += 1
     i += 1
for _ in range(n):
     print(l[_])

Buggy submission (verdict: Runtime Error):
n =int(input())
s = list(map(int,input().split()))
l =[0]*n
while i < n-2 :
     l[s[i]-1] += 1
     i += 1
for _ in range(n):
     print(l[_])

Buggy submission (verdict: Runtime Error):
n, m =map(int,input().split())
s = list(map(int,input().split()))
a = [input() for __ in range(n)]

n =int(input())
s = list(map(int,input().split()))
l =[0]*n
print(l)
while i < n-2 :
     l[s[i]-1] += 1
     i += 1
for _ in range(n):
     print(l[_])
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-1, i-1 )) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-

Buggy submission (verdict: Runtime Error):

from scipy.special import comb

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( comb( r_cnt+1, i, exact = True ) * comb( b_cnt-1, i-1, exact = True )) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( comb( r_cnt+1, i, exact = True ) * comb( b_cnt-1, i-1, exact = True )) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from scipy.special import cmb

# 入力データのinput
N, K = map(int, input().split())

r_cnt = N - K
b_cnt = K

# 1. 赤ボールを並べる
# 2. 青ボールを置く位置のパターン数を求める
#    置ける場所は赤ボールの両端とボールの間

# 3. 青ボールの個数をどのように分けるかのパターン数を求める
#    青ボールの個数を分ける線の数を求める

for i in range(1, K+1):
    print(( cmb( r_cnt+1, i, exact = True ) * cmb( b_cnt-1, i-1, exact = True )) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from scipy.special import cmb

# 入力データのinput
N, K = map(int, input().split())

r_cnt = N - K
b_cnt = K

# 1. 赤ボールを並べる
# 2. 青ボールを置く位置のパターン数を求める
#    置ける場所は赤ボールの両端とボールの間

# 3. 青ボールの個数をどのように分けるかのパターン数を求める
#    青ボールの個数を分ける線の数を求める

for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-1, i-1 )) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n-r,r )
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

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

r_cnt = N - K
b_cnt = K



for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-1, i-1 )) % (10**9+7))
Problem p02847 (python)

Fixed submission:
day=['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-day.index(input()))

Buggy submission (verdict: Runtime Error):
day=['SUN','MON','TUE','WED','THU','FRY','SAT']
print(7-day.index(input()))
Problem p02699 (python)

Fixed submission:
s,w=map(int,input().split())
print('unsafe' if w>=s else 'safe')

Buggy submission (verdict: Runtime Error):
s=input()
count=0
for i in range(len(s)-3):
    for j in range(i+4,len(s)+1):
        if int(s[i:j])%2019==0:
            count+=1
            i=j
print(count)
Problem p02819 (python)

Fixed submission:
x=int(input())

def isprime(n):
    if n==1:
        return False
    else:
        for i in range(2,int(n**0.5)+1):
            if n%i==0:
                return False
        return True
        
while True:
    if isprime(x):
        print(x)
        exit()
    else:
        x+=1

Buggy submission (verdict: Runtime Error):
import sympy
n=int(input())
if sympy.isprime(n)==True:
    print(n)
else:
    print(sympy.nextprime(n))

Buggy submission (verdict: Runtime Error):
import sympy
from sympy import nextprime
x=int(input())
print(nextprime(x))

Buggy submission (verdict: Runtime Error):
from sympy import nextprime
x=int(input())
print(nextprime(x))

Buggy submission (verdict: Runtime Error):
from sympy import nextprime
print(nextprime(int(input())))
Problem p02831 (python)

Fixed submission:
import fractions

a,b=map(int,input().split())
def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

print(lcm(a,b))

Buggy submission (verdict: Runtime Error):
import math

a,b=map(int,input().split())
def lcm(x,y):
    return (x*y)//math.gcd(x,y)

print(lcm(a,b))
Problem p02629 (python)

Fixed submission:
n = int(input())
l = list()
name_dict = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j', 10:'k', 11:'l', 12:'m', 13:'n', 14:'o', 15:'p', 16:'q', 17:'r', 18:'s', 19:'t', 20:'u', 21:'v', 22:'w', 23:'x', 24:'y', 25:'z'}
name = ''

while n != 0:
	n -= 1
	l.append(n%26)
	n = n//26

if l != []:
	for i in reversed(l):
		name += name_dict[i]

print(name)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list()
name_dict = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e', 6:'f', 7:'g', 8:'h', 9:'i', 10:'j', 11:'k', 12:'l', 13:'m', 14:'n', 15:'o', 16:'p', 17:'q', 18:'r', 19:'s', 20:'t', 21:'u', 22:'v', 23:'w', 24:'x', 25:'y', 26:'z'}
name = ''

while n != 0:
	l.append(n%26)
	n = n//26

if l != []:
	for i in reversed(l):
		name += name_dict[i]

print(name)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list()
name_dict = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e', 6:'f', 7:'g', 8:'h', 9:'i', 10:'j', 11:'k', 12:'l', 13:'m', 14:'n', 15:'o', 16:'p', 17:'q', 18:'r', 19:'s', 20:'t', 21:'u', 22:'v', 23:'w', 24:'x', 25:'y', 26:'z'}
name = ''

while n != 0:
	l.append(n%26)
	n = n//26

for i in reversed(l):
	name += name_dict[i]

print(name)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list()
name_dict = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e', 6:'f', 7:'g', 8:'h', 9:'i', 10:'j', 11:'k', 12:'l', 13:'m', 14:'n', 15:'o', 16:'p', 17:'q', 18:'r', 19:'s', 20:'t', 21:'u', 22:'v', 23:'w', 24:'x', 25:'y', 26:'z'}
name = ''

while n != 0:
	l.append(n%26)
	n = n//26

for i in reversed(l):
	name += name_dict[i]

print(name)
Problem p02659 (python)

Fixed submission:
tmp = [i for i in input().split()]

a = int(tmp[0])
b = int(float(tmp[1]) * 1000)

result = a*b//1000
print(result)

Buggy submission (verdict: Runtime Error):
a = [float(i) for i in input().split()]
print(int(a))
Problem p02689 (python)

Fixed submission:
from collections import defaultdict

def check(p: int, h: list, ways: dict):
    for w in ways[p]:
        if h[p] <= h[w]:
            return False
    return True


def main():
    tmp = [int(i) for i in input().split()]
    n = tmp[0]
    m = tmp[1]

    ways = defaultdict(set)
    h = [0] + [int(i) for i in input().split()]
    for _ in range(m):
        tmp = [int(i) for i in input().split()]
        ways[tmp[0]].add(tmp[1])
        ways[tmp[1]].add(tmp[0])
    
    cnt = 0
    for i in range(1, n+1):
        if check(i, h, ways):
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

visited = [False for _ in range(100001)]


def dfs(p: int, n: int, h: list, ways: dict, result: dict):
    if visited[p]:
        return
    
    visited[p] = True
    result[h[p-1]] += 1

    for w in ways[p]:
        dfs(w, n, h, ways, result)


def main():
    tmp = [int(i) for i in input().split()]
    n = tmp[0]
    m = tmp[1]

    ways = defaultdict(set)
    h = [int(i) for i in input().split()]
    for _ in range(m):
        tmp = [int(i) for i in input().split()]
        ways[tmp[0]].add(tmp[1])
        ways[tmp[1]].add(tmp[0])
    
    cnt = 0
    for i in range(1, n+1):
        result = defaultdict(int)
        dfs(i, n, h, ways, result)
        if len(result) > 0:
            h_max = max(list(result.keys()))
            cnt += result[h_max]
    print(cnt)

if __name__ == '__main__':
    main()
Problem p02627 (python)

Fixed submission:
a = input()
if ord(a) >= ord('a') and ord(a) <= ord('z'):
    print("a")
else:
    print("A")

Buggy submission (verdict: Runtime Error):
a = input()
if ord(a) >= 'a' and ord(a) <= 'z':
    print("a")
else:
    print("A")
Problem p02659 (python)

Fixed submission:
from decimal import Decimal

C, D = map(Decimal, input().split())
print(int(C*D))

Buggy submission (verdict: Runtime Error):
from decimal import *
c, d = list(map(decimal, input().split()))
print(int(c * d))

Buggy submission (verdict: Runtime Error):
number = list(map(float, input().split()))
print('{}'.format(math.floor(number[0] * number[1])))

Buggy submission (verdict: Runtime Error):
number = list(int(input()), float(input()))
print('{}'.format(int(number[0] * number[1])))

Buggy submission (verdict: Runtime Error):
number = list(map(int, input().split()))
print('{}'.format(int(number[0] * number[1])))

Buggy submission (verdict: Runtime Error):
number = list(map(int, input()))
print('{}'.format(int(number[0] * number[1])))
Problem p02676 (python)

Fixed submission:
k = int(input())
s = input()

slist = list(s)
if len(slist) > k:
  l = ''
  for i in range(k):
    l += slist[i]
  print(l + '...')
else:
  print(s)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = input()

slist = list(s)
if len(slist) > k:
  l = ''
  for i in range(k):
    k += slist[i]
  print('...' + l)
else:
  print(s)
Problem p02693 (python)

Fixed submission:
k=int(input())
a,b=map(int,input().split())
c=0
for i in range(a,b+1):
  if(i%k==0):
    c=c+1
if(c==0):
  print("NG")
else:
  print("OK")

Buggy submission (verdict: Runtime Error):
from math import floor
a,b,n=map(int,input().split())
if(n<b):
  print(floor((a*n)/b))
else:
  if(n%b<(n/2)):
    for i in range(0,(n%b)+1):
      print(floor((a*(n-1-i))/b)-(a*floor((n-1-i)/b)))
  else:
    print(floor((a*(n))/b)-(a*floor((n)/b)))

Buggy submission (verdict: Runtime Error):
k=int(input())
a,b=map(int,input().split())
count=0
for i in range(a,b+1):
  if(i%k==0):
    c=c+1
if(c==0):
  print("NG")
else:
  print("OK")
Problem p03012 (python)

Fixed submission:
import numpy as np
N = int(input())
W_list = [int(i) for i in input().split(" ")]
ans = np.abs(W_list[0] - np.sum(W_list[1:N]))
for j in range(2, N):
    difference = np.abs(np.sum(W_list[:j]) - np.sum(W_list[j:N]))
    if difference < ans:
        ans = difference
    else:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
W_list = [int(i) for i in input().split(" ")]
ans = np.abs(W_list[0] - np.sum(W_list[1:N]))
sum_list = np.sum(W_list)
sum_front = 0
for j in range(2, N):
  	sum_front += W_list[j]
    difference = np.abs(sum_list - 2 * sum_front)
    if difference < ans:
        ans = difference
    else:
        break
 
print(ans)
Problem p03135 (python)

Fixed submission:
T, X = map(int, input().split(" "))
print(T / X)

Buggy submission (verdict: Runtime Error):
T, X = int(map, input().split(" "))
print(T / X)
Problem p02771 (python)

Fixed submission:
b = list(map(int,input().split()))

if len(set(b)) == 2:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
a = [input() for i in range(n)]
b = sorted(list(set(a)))
d = {}
for i in b:
    t = a.count(i)
    d.setdefault(t,[])
    d[t].append(i)

for i in d[max(d.keys())]:
    print(i)
Problem p02819 (python)

Fixed submission:
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n=int(input())

x=n
for i in range(n,10**6): 
   if is_prime(i):
       break


print (i)

Buggy submission (verdict: Runtime Error):
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n=int(input())

x=n
for i in range(n,10**5): 
   if is_prime(i):
       break


print (i)
Problem p02820 (python)

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

# d={'r':0,'s':0,'p':0}
d={}
ans=0
c=0
for i in t:

    if c >= k:
        x =d[c-k]
        y = c+k
        if i =='r':
            if x == 'p':
                if  y < n and t[y] == 's':
                    d[c]='s'
                else:
                    d[c]='r'
            else:
                ans += p ; d[c]='p'
        elif i == 's': 
            if x == 'r':
               if y < n and t[y] == 'p' :
                    d[c]='p'
               else:
                    d[c]='s'
            else:
                ans += r;d[c]='r'
        elif i == 'p': 
            if x == 's':
               if  y < n and t[y] == 'r':
                    d[c]='r'
               else:
                    d[c]='p'
            else:
                ans += s;d[c]='s'

    else:
        if i =='r':
            ans += p ; d[c]='p'
        elif i == 's': 
            ans += r;d[c]='r'
        elif i == 'p': 
            ans += s;d[c]='s'

    c+=1


print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())

# d={'r':0,'s':0,'p':0}
d={}
ans=0
c=0
for i in t:

    if c >= k:
        x =d[c-k]
        if i =='r':
            if x == 'p':
                if t[c+k] == 's':
                    d[c]='s'
                else:
                    d[c]='r'
            else:
                ans += p ; d[c]='p'
        elif i == 's': 
            if x == 'r':
               if t[c+k] == 'p':
                    d[c]='p'
               else:
                    d[c]='s'
            else:
                ans += r;d[c]='r'
        elif i == 'p': 
            if x == 's':
               if t[c+k] == 'r':
                    d[c]='r'
               else:
                    d[c]='p'
            else:
                ans += s;d[c]='s'

    else:
        if i =='r':
            ans += p ; d[c]='p'
        elif i == 's': 
            ans += r;d[c]='r'
        elif i == 'p': 
            ans += s;d[c]='s'

    c+=1


print(ans)
Problem p03053 (python)

Fixed submission:
from collections import deque

h,w = map(int,input().split())
m = [input() for _ in range(h)]
vm  = [[-1] * w for _ in range(h) ]

q = deque()

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            q.append((i,j))
            vm[i][j]=0

while q:
    y,x = q.popleft()
    d = vm[y][x]

    for i,j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        yi , xj = y + i , x + j
        if yi >= 0 and xj >= 0 and yi < h and xj < w and vm[yi][xj] == -1 :
            vm[yi][xj] = d +  1
            q.append([yi,xj])
            

print(d)

Buggy submission (verdict: Runtime Error):
from collections import deque

h,w = map(int,input().split())
m = [input() for _ in range(h)]
vm  = [[-1] * w for _ in range(h) ]

q = deque()

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            q.append((i,j))
            vm[i][j]=0

while q:
    y,x = q.popleft()
    d = vm[y][x]

    for i,j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        yi , xj = y + i , x + j
        if yi >= 0 and xj >= 0 and yi < h and xj < w and vm[yi][xj] == -1 :
            vm[yi][xj] = d +  1
            q.append([yi,xj])a

print(d)