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

Fixed submission:

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def main(inputs):
	x=int(inputs[0][0])
	n=x//500
	x-=n*500
	n1=x//5
	print(n*1000+n1*5)


if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

Buggy submission (verdict: Runtime Error):

def main(inputs):
	x=int(inputs[0][0])
	n=x//500
	x-=n*500
	n1=x//5
	print(n*1000+n1*5)


if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)
Problem p03220 (python)

Fixed submission:
N = int(input())
T,A = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
sub = [0 for i in range(N)]
for i in range(N):
    sub[i] = abs(A - (T - 0.006*H[i]))
print(sub.index(min(sub))+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
T,A = int(i) for i in input().split()
Hi = [int(i) for i in input().split()]
Ave = T - i*0.006 for i in Hi
Result = [abs(i) for i in (Ave - A)]
print(index(min(Result))+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
T,A = int(i) for i in input().split()
Hi = [int(i) for i in input().split()]
Ave = T - i*0.006 for i in Hi
Result = [abs(i) for i in Ave - A]
print(index(min(result)) + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
T,A = int(i) for i in input().split()
Hi = [int(i) for i in input().split()]
Ave = [T - i*0.006 for i in Hi]
Result = [abs(i) for i in Ave - A]
print(index(min(result)) + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
T,A = [float(i) for i in input().split()]
Hi = [float(i) for i in input().split()]
Ave = [T - i*0.006 for i in Hi]
Result = [abs(i) for i in Ave - A]
print(index(min(result)) + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
T,A = [int(i) for i in input().split()]
Hi = [int(i) for i in input().split()]
Ave = [T - i*0.006 for i in Hi]
Result = [abs(i) for i in Ave - A]
print(index(min(result)) + 1)
Problem p03455 (python)

Fixed submission:
a,b = map(int, input().split())
if (a * b) % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
if (a * b) % == 0:
  print("Evern")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = map(int(), input().split())
if (a * b) % 2 == 0:
  print ("Evern")
else:
  print ("Odd")
Problem p03493 (python)

Fixed submission:
s = input()
print(s.count("1"))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = [int(i) for i in input().split()]
ans = 0
while True:
    if [i for i in nums if i % 2 == 1]:
        break
    nums = [i//2 for i in nums]
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = [int(i) for i in input().split()]
ans = 0
while Ture:
  if [i for i in nums if i % 2 == 1]:
    break
  nums = [ i//2 for i in nums]
  ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
print(s.count(1))
Problem p03494 (python)

Fixed submission:
n = int(input())
nums = [int(i) for i in input().split()]
ans = 0
while True:
    if [i for i in nums if i % 2 == 1]:
        break
    nums = [i//2 for i in nums]
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = [int(i) for i in input().split()]
ans = 0
while Ture:
  if [i for i in if i % 2 == 1]:
    break
  nums = [ i//2 for i in nums]
  ans += 1
print(ans)
Problem p03644 (python)

Fixed submission:
N = int(input())
ans = 1
while True:
  if N < ans <<1:
    break
  ans<<=1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = [2**i for i in range(1,7)]
ans = [i - n for i in nums if (i - n) >= 0]
print(ans[0])
Problem p02719 (python)

Fixed submission:
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  n,k = list(map(int,input().split()))
  #a = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = n
  zen = n
  count = 0
  lis = []
  
  if k == 1:
    print(0)
  elif n <= abs(n-k):
    print(n)
  else:
    ans = n % k
    if ans > 2:
      while 1:
        hi = abs(ans-k)
        if hi < zen:
          zen = hi
          ans = hi

        else:
          print(ans)
          exit()
    else:
      print(ans)
    
      
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  n,k = list(map(int,input().split()))
  #a = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = n
  zen = n
  count = 0
  lis = []
  
  if k == 1:
    print(0)
  elif k == 2:
    if n % 2 = 0:
      print(2)
    else:
      print(3)
  else:  
    while 1:
      hi = abs(ans-k)
      if hi < zen:
        zen = hi
        ans = hi
        
      else:
        print(ans)
        exit()
      
if __name__ == '__main__':
  main()
Problem p02761 (python)

Fixed submission:
n,m = list(map(int,input().split()))
ans = [-1] * n
total = 0
  
for i in range(m):
  s,c = list(map(int,input().split()))
  if ans[s-1] != -1 and ans[s-1] != c:
    print(-1)
    exit()
  
  else:
    ans[s-1] = c
  
if ans[0] == 0 and n >= 2:
  print(-1)
  exit()
  
elif ans[0] == -1 and n >= 2:
  ans[0] = 1
  
for i in range(n):
  if ans[i] == -1:
    ans[i] = 0
    
a = 0  
for i in range(n-1, -1, -1):
  total += ans[i] * 10**a
  a += 1

print(total)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
ans = [-1] * n

if n == 1 and m == 0:
  print(0)
  
for i in range(m):
  s,c = list(map(int,input().split()))
  if ans[s-1] != -1 and ans[s-1] != c:
    print(-1)
    exit()
  
  else:
    ans[s-1] = c

if ans.count(-1) >= 2:
  print(-1)
  exit()
  
elif ans[0] == 0 and n >= 2:
  print(-1)
  exit()
  
elif ans[0] == -1:
    ans[0] = 1
    
elif ans[1] == -1:
  if n == 2:
    ans[1] = 1
  else:
    ans[1] = 0
    
elif ans[2] == -1:
  ans[2] = 0
  

total = ans[2] + ans[1] * 10 + ans[0] * 100

print(total)
Problem p02802 (python)

Fixed submission:
n,m=list(map(int,input().split()))
ac,wa=0,0
aclis=[0]*n
walis=[0]*n

for i in range(m):
  p,s=input().split()
  p = int(p)  
  if s == "AC" and aclis[p-1] == 0:
    aclis[p-1] = 1
    ac += 1
    wa += walis[p-1]
  elif s == "WA" and aclis[p-1] == 0:
    walis[p-1] += 1
print(ac,wa)

Buggy submission (verdict: Runtime Error):
n,m=list(map(int,input().split()))
ac,wa=0,0
aclis=[0]*n
walis=[0]*n

for i in range(m):
  p,s=input().split()
  p = int(p)  
  if s == "AC" and aclis[p-1] == 0:
    aclis[p-1] = 1
    ac += 1
    wa += wa[p-1]
  elif s == "WA" and aclis[p-1] == 0:
    wa[p-1] += 1
print(ac,wa)
Problem p02971 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

sot = sorted(a,reverse = True)
ans1 = sot[0]
ans2 = sot[1]

for i in a:
  if i != ans1:
    print(ans1)
  else:
    print(ans2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
  if i == 0:
    ans = max(a[1:n])
  elif i == n-1:
    ans = max(a[0:n-1])
  else:
    ans = max(a[0:i],a[i+1:n])
  print(ans)
Problem p02705 (python)

Fixed submission:
print(float(input())*2*3.14)

Buggy submission (verdict: Runtime Error):
N=input()
A=list(input().split(" "))
for n in range(1,int(N)):
    print(A.count(n))

Buggy submission (verdict: Runtime Error):
a,b=input().split()
c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
play_day=a-(b+c)
if play_day>=0:
    print(play_day)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
N,A=int(input()),input().split(" ")
for n in range(1,N):
    print(A.count(str(n)))
Problem p02706 (python)

Fixed submission:
a,b=map(int,input().split())
C=list(map(int,input().split()))
play_day=a-sum(C)
if play_day>=0:
    print(play_day)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c,d=map(int,input().split())
play_day=a-(c+d)
if play_day>=0:
    print(play_day)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
a,b=input().split()
c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
play_day=a-(b+c)
if play_day>=0:
    print(play_day)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c,d=map(int,input().split())
play_day=a-(c+d)
if play_day>=0:
    print(play_day)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c,d=map(int,input().split())
play_day=a-(c+d)
if play_day>=0:
    print(play_day)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c,d=map(int,input().split())
play_day=a-(c+d)
if play_day>0:
    print(play_day)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c,d=map(int,input().split())
play_day=a-(c+d)
if play_day>0:
    print(play_day)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c,d=map(int,input().split())
print(a-(c+d))

Buggy submission (verdict: Runtime Error):
([int(r) for r in input().split(" ")])-sum([int(r) for r in input().split(" ")])

Buggy submission (verdict: Runtime Error):
N=int(input())
M=int(input())
A=list(range(M+1))
play_day=N-sum(A)
if play_day>0:
    print(play_day)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N=int(input())
M=int(input())
A=list(range(M+1))
play_day=N-sum(A)
if play_day>0:
    print(play_day)
else:
    print("-1")
Problem p02705 (python)

Fixed submission:
import math
R = int(input(""))
C = 2 * math.pi * R
print(C)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
daytofinish = sum(A)
if N-daytofinish < 0:
    print(-1)
else:
    print(N-daytofinish)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
daystofinish = sum(A)
print(N-daystofinish)
N, M = map(int, input().split())
A = list(map(int, input().split()))
daystofinish = sum(A)
if N-daystofinish < 0:
    print(-1)
else:
    print(N-daystofinish)
Problem p02706 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))

x = n - sum(a)
print(x if x >= 0 else -1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
daystofinish = sum(A)
print(N-daystofinish)
N, M = map(int, input().split())
A = list(map(int, input().split()))
daystofinish = sum(A)
if N-daystofinish < 0:
    print(-1)
else:
    print(N-daystofinish)

Buggy submission (verdict: Runtime Error):
import math
R = int(input(""))
C = 2 * math.pi * R
print(C)
Problem p02755 (python)

Fixed submission:
import math
def main():
    a, b = map(int, input().split())
    ra = [math.ceil(i/0.08) for i in range(1, 102)]
    rb = [math.ceil(i/0.1) for i in range(1, 102)]
    x = ra[a-1] 
    while x < ra[a] :
        if int(x*0.1) == b:
            return x
        x+=1
    return -1



if __name__ == "__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def main():
    a, b = map(int, input().split())
    x = 13
    while x <= int(a/0.08):
        x+=1
        if int(x*0.08) == a:
            if int(x*0.1) == b:
                return x
    return -1



if __name__ == "__main__":
    print(main()
Problem p02780 (python)

Fixed submission:
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    e = [(p[j-1]+1)/2.for j in range(1, n+1)]
    s = [sum(e[:k])]
    for i in range(1, n-k+1):
        s.append(s[-1]-e[i-1]+e[k+i-1])
    ans = max(s)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    # list of expected value
    e = [(p[j-1]+1)/2.for j in range(1, n+1)]
    # cumulative sum for e
    c_s = np.cumsum(e)
    # sum of range k
    s = c_s[k:] - c_s[:n-k]
    # calculate max of s
    ans = max(s)

    print(ans)

if __name__ == "__main__":
    main()
Problem p03161 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())
    h = [int(x) for x in input().split()]
    # memo = [None for i in range(N)]

    # def rec(n):
    #     if memo[n-1] == None:
    #         if n <= 1:
    #             memo[n-1] = 0
    #         elif n == 2:
    #             memo[n-1] = abs(h[0]-h[1])
    #         else:
    #             memo[n-1] = min(abs(h[n-1]-h[j-1]) + rec(j) for j in range(max(0,n-K),n))
    #     return memo[n-1]

    # print(rec(N))

    dp = [-1]*N
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])

    for i in range(2,N):
        dp[i] = min(abs(h[i]-h[j]) + dp[j] for j in range(max(0,i-K),i))
    print(dp[N-1])

# if __name__ == "__main__":
main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

def main():
    N, K = map(int, input().split())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(N)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[0]-h[1])
            else:
                memo[n-1] = min(abs(h[n-1]-h[j-1]) + rec(j) for j in range(max(0,n-K),n))
        return memo[n-1]

    print(rec(N))

if __name__ == "__main__":
    main()
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-

a, b = map(int, input().split())

if (a % 2 == 0) | (b % 2 == 0) :
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a, b = map(int, input().split())

if (a % 2 == 0) | (b % 2 == 0) :
    print("Even)
else:
    print("Odd")
Problem p03493 (python)

Fixed submission:
a = str(input())

count = 0

for s in a:
  if int(s) == 1:
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
a = str(input())

count = 0

for s in a:
  if int(s) == 1:
    count++
print(count)
Problem p02981 (python)

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input.split())
print(min(N*A,B))
Problem p02795 (python)

Fixed submission:
h = int(input())
w = int(input())
n = int(input())
a = max(h,w)
b = a
count = 0
if h*w == n:
  print(h)
elif b >= n:
  print(1)
else:
 while b*count < n:
   count += 1
 print(count)

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
list_N = list(range(1,N+1))
grid.sort()
a = 0
count = 0
for j in range(N) :
  list_a = list(range(grid[j][0]-grid[j][1]+1, grid[j][0]+grid[j][1]-1))
  list_b = list(set(list_a) - set(list_N))
  if list_b == []:
    list_N = list(set(list_N) - set(list_a))
    count += 0
  else:
    count += 1
print(N - count)

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
list_N = list(range(1,N+1))
grid.sort()
a = 0
count = 0
for j in range(N) :
  list_a = list(range(grid[j][0]-grid[j][1]+1, grid[j][0]+grid[j][1]-1))
  list_b = list(set(list_a) - set(list_N))
  if list_b == []:
    list_N = list(set(list_N) - set(list_a))
    count += 0
  else:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
list_N = list(range(1,N+1))
grid.sort()
a = 0
count = 0
for i in range(N) :
  list_a = list(range(grid[i][0]-grid[i][1]+1, grid[i][0]+grid[i][1]-1))
  list_b = list(set(list_a) - set(list_N))
  if list_b == []:
    list_N = list(set(list_N) - set(list_a))
    count += 0
  else:
    count += 1
print(count)
Problem p02801 (python)

Fixed submission:
c = input()
alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
count1 = 0
count2 = 0
while count2 <= 26:
  if alp[count1] == c:
     count1 += 1
     count2 += 27
  else:
    count1 += 1
    count2 += 1
print(alp[count1])

Buggy submission (verdict: Runtime Error):
n, k, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
total_score = 0
while count <= n - 2:
  total_score += a[count]
  count += 1 
last_score = n * m - total_score
if last_score < 0:
  print(0) 
else:
  print(last_score)
Problem p03035 (python)

Fixed submission:
#coding:utf-8
A,B = map(int,input().split())
if  A >= 13:
    print(B)
elif 6 <= A and A <= 12:
    print(int(B / 2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
#coding:utf-8
A,B = map(int,input(),split())
if  A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B / 2)
print(0)
Problem p03059 (python)

Fixed submission:
#coding:utf-8
a,b,t =map(int,input().split())
x = t // a
print(b*x)

Buggy submission (verdict: Runtime Error):
#coding:utf-8
a,b,t = input().split()
x = t // a
print(b*x)

Buggy submission (verdict: Runtime Error):
x,y,z= input().split()

A =( z + 0.5) / x

print( A * y)

Buggy submission (verdict: Runtime Error):
X = list(int,input().split())

Y =( X[3] + 0.5) / X[1]

print( Y * X[2])
Problem p03473 (python)

Fixed submission:
#coding: utf-8

a = int(input())

print(24 - a + 24)

Buggy submission (verdict: Runtime Error):
#coding: utf-8

a = input()

print((24 - a) + 24)

Buggy submission (verdict: Runtime Error):
#coding: utf-8

a = input()

print(24 - a + 24)

Buggy submission (verdict: Runtime Error):
#coding: utf-8

print(24 - M + 24)

Buggy submission (verdict: Runtime Error):
#coding: utf-8

print(23 - M + 24)
Problem p02803 (python)

Fixed submission:
import copy
from collections import deque

#反省bfsだと計算量が多くなってしまうパターンだった。bfsが正解。
def dfs(x,y,z,grid,H,W):
    if(x-1>=0):
        if(grid[y][x-1]>z or grid[y][x-1]==0):
            grid[y][x-1]=z+1
            dfs(x-1,y,z+1,grid,H,W)
    if(x+1<W):
        if(grid[y][x+1]>z or grid[y][x+1]==0):
            grid[y][x+1]=z+1
            dfs(x+1,y,z+1,grid,H,W)
    if(y-1>=0):
        if(grid[y-1][x]>z or grid[y-1][x]==0):
            grid[y-1][x]=z+1
            dfs(x,y-1,z+1,grid,H,W)
    if(y+1<H):
        if(grid[y+1][x]>z or grid[y+1][x]==0):
            grid[y+1][x]=z+1
            dfs(x,y+1,z+1,grid,H,W)
    return 0
    
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(x,y,grid,H,W):
    dist=[[0 for _ in range(W)] for _ in range(H)]
    que=deque()
    que.append((y,x))
    dist[y][x]=1
    while(len(que)>0):
        y,x=que.popleft()
        for i in range(4):
            nx=x+dx[i]
            ny=y+dy[i]
            if(0 <= nx < W) and (0 <= ny < H) and grid[ny][nx]==0 and dist[ny][nx] == 0:
                que.append((ny,nx))
                dist[ny][nx]=dist[y][x]+1
    return( max([max(dist[i]) for i in range(H)]))
    
H,W=map(int,input().split())
grid=[]
tmp=[]
for i in range(H):
    S=str(input())
    tmp=[]
    for j in range(W):
        if(S[j]=="."):
            tmp.append(0)
        else:
            tmp.append(-1)
    grid.append(tmp)
ans=0
result=0
for i in range(W):
    for j in range(H):
        if(grid[j][i]==0):
                ans=bfs(i,j,grid,H,W)
                result=max(result,ans)
print(result-1)

Buggy submission (verdict: Runtime Error):
import copy
def dfs(x,y,z,grid,H,W):
    if(x-1>=0):
        if(grid[y][x-1]>z or grid[y][x-1]==0):
            grid[y][x-1]=z+1
            dfs(x-1,y,z+1,grid,H,W)
    if(x+1<W):
        if(grid[y][x+1]>z or grid[y][x+1]==0):
            grid[y][x+1]=z+1
            dfs(x+1,y,z+1,grid,H,W)
    if(y-1>=0):
        if(grid[y-1][x]>z or grid[y-1][x]==0):
            grid[y-1][x]=z+1
            dfs(x,y-1,z+1,grid,H,W)
    if(y+1<H):
        if(grid[y+1][x]>z or grid[y+1][x]==0):
            grid[y+1][x]=z+1
            dfs(x,y+1,z+1,grid,H,W)
    return 0


H,W=map(int,input().split())
grid=[]
tmp=[]
for i in range(H):
    S=str(input())
    tmp=[]
    for j in range(W):
        if(S[j]=="."):
            tmp.append(0)
        else:
            tmp.append(-1)
    grid.append(tmp)
ans=0
result=0
for i in range(W):
    for j in range(H):
        if(grid[j][i]==0):
            if(j-1>=0 and j+1<H and i-1>=0 and i+1<W):
                if(grid[j-1][i]+grid[j+1][i]+grid[j][i-1]+grod[i+1]<(-1)):
                        dataset=copy.deepcopy(grid)
                        dfs(i,j,1,dataset,H,W)
                        ans=max(dataset)
                        ans=max(ans)
                        result=max(result,ans)
            else:
                dataset=copy.deepcopy(grid)
                dfs(i,j,1,dataset,H,W)
                ans=max(dataset)
                ans=max(ans)
                result=max(result,ans)
print(result-1)
Problem p03081 (python)

Fixed submission:
#ゴーレム判定関数
#pos=位置
#s=文字列
def survive(pos,s,spell,move,N):
    for i in range(0,len(spell)):
        if(s[pos]==spell[i]):
            pos+=move[i]
        #ゴーレムが消えたか判定
        if(pos<0):
            return -1
        elif(pos>N-1):
            return 1
    return 0

N,Q=map(int,input().split())
s=str(input())
tmp1=""
tmp2=""
tmp=0
#AとかBとかそういう奴らがどのくらい動くのかをカウント
spell=[]
move=[]
for time in range(0,Q):
    tmp1,tmp2=map(str,input().split())
    spell.append(tmp1)
    if(tmp2=="L"):
        move.append(-1)
    elif(tmp2=="R"):
        move.append(1)
left_result=-1
right_result=N
#右にoutしていくやつのうちもっとも左のやつを探す
left=0
right=N-1
mid=0
judge=False
#何も右から出ていかないパターン
if(survive(N-1,s,spell,move,N)!=1):
    right_result=N
#全て右から出ていくパターン
elif(survive(0,s,spell,move,N)==1):
    right_result=0
else:
    while ((right+left)//2)!=mid:
        mid=(right+left)//2
        judge=survive(mid,s,spell,move,N)
        if(judge==1):
            right=mid
        else:
            left=mid
    right_result=right

#左にoutしていくやつのうちもっとも右のやつを探す
left=0
right=N-1
mid=0
judge=False
#何も左から出ていかないパターン
if(survive(0,s,spell,move,N)!=-1):
    left_result=-1
#全て左から出ていくパターン
elif(survive(N-1,s,spell,move,N)==-1):
    left_result=N-1
else:
    while ((right+left)//2)!=mid:
        mid=(right+left)//2
        judge=survive(mid,s,spell,move,N)
        if(judge==-1):
            left=mid
        else:
            right=mid
    left_result=left

ans=right_result-left_result-1
print(ans)

Buggy submission (verdict: Runtime Error):
#ゴーレム判定函数
#pos=位置
#s=文字列
def survive(pos,s,spell,move,N):
    for i in range(0,len(spell)):
        if(s[pos]==spell[i]):
            pos+=move[i]
        #ゴーレムが消えたか判定
        if(pos<0 or pos>N):
            return False
    return True
    
N,Q=map(int,input().split())
s=str(input())
tmp1=""
tmp2=""
tmp=0
#AとかBとかそういう奴らがどのくらい動くのかをカウント
spell=[]
move=[]
for time in range(0,Q):
    tmp1,tmp2=map(str,input().split())
    spell.append(tmp1)
    if(tmp2=="L"):
        move.append(-1)
    elif(tmp2=="R"):
        move.append(1)
left=-1
right=-1
#上と下から探す
for i in range(0,N):
    if(survive(i,s,spell,move,N)):
        left=i
        break
for j in range(0,N):
    if(survive(N-1-j,s,spell,move,N)):
        right=N-1-j
        break
ans=0
if(left<0 and right<0):
    ans=0
else:
    ans=right-left+1
print(ans)