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

Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
ans=[]
for i in range(h):
    ans.append(s[i])
    ans.append(s[i])
for i in range(h*2):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [input() for _ in range(w)]
ans=[]
for i in range(w):
    ans.append(s[i])
    ans.append(s[i])
for i in range(w*2):
    print(ans[i])
Problem p04001 (python)

Fixed submission:
s=input()
n=len(s)-1
l=[]
for i in range(n):
    l.append("+")
sum = 0

if len(s) < 2:
    sum = s

else:
    for i in range(2 ** n):
        plus = []
        tmp = ""
        ans = 0
        for j in range(n):
            if ((i>>j) & 1):
                plus.append(l[j])
            else:
                plus.append("")
        for i in range(n):
            tmp += s[i]+plus[i]
            if i == n-1:
                tmp+=s[i+1]
        tmp2 = tmp.split("+")
        for i in range(len(tmp2)):
            ans += int(tmp2[i])
        sum+=ans

print(sum)

Buggy submission (verdict: Runtime Error):
s=input()
n=len(s)-1
l=[]
for i in range(n):
    l.append("+")
sum = 0
for i in range(2 ** n):
    plus = []
    tmp = ""
    ans = 0
    for j in range(n):
        if ((i>>j) & 1):
            plus.append(l[j])
        else:
            plus.append("")
    for i in range(n):
        tmp += s[i]+plus[i]
        if i == n-1:
            tmp+=s[i+1]
    tmp2 = tmp.split("+")
    for i in range(len(tmp2)):
        ans += int(tmp2[i])
    sum+=ans
print(sum)
Problem p02983 (python)

Fixed submission:
l,r=map(int,input().split())
L=l%2019
R=r%2019
ans=2019
if l+2019<=r:
        print(0)
elif L>R:
        print(0)
else:
        for i in range(L,R+1):
              for j in range(i+1,R+1):
                        ans=min(ans,(i*j)%2019)
        print(ans)

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())
L=l%2019
R=r%2019
ans=2019
if l+2019<=r:
        print(0)
elif L>R:
        print(0)
else:
        for i in range(L,R+1):
                for j in range(i+1,R+!):
                        ans=min(ans,(i*j)%2019)
        print(ans)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a,b,c,d=map(int,input().split())
lcm=c*d//gcd(c,d)
nc=b//c-a//c
nd=b//d-a//d
nlcm=b//lcm-a//lcm
if a%c==0:
  nc+=1
if a%d==0:
  nd+=1
if a%lcm==0:
    nlcm+=1
print(b-a+1-nc-nd+nlcm)

Buggy submission (verdict: Runtime Error):
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
typedef long long ll;

int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  D=max(C,D),C=min(C,D);
  ll E=__gcd(C,D);
  ll lcm=C*D/E;
  ll F=(A-1)/C;
  ll G=B/C;
  ll H=(A-1)/D;
  ll I=B/D;
  ll J=(A-1)/lcm;
  ll K=B/lcm;
  cout<<(B-A+1)-(G-F)-(I-H)+(K-J)<<endl;
  return 0;
}
Problem p03206 (python)

Fixed submission:
d=int(input())
if d==25:
  print("Christmas")
elif d==24:
  print("Christmas Eve")
elif d==23:
  print("Christmas Eve Eve")
else:
  print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
d=int(input())
if d=25:
  print("Christmas")
elif d=24:
  print("Christmas Eve")
elif d=23:
  print("Christmas Eve Eve")
else:
  print("Christmas Eve Eve Eve")
Problem p03219 (python)

Fixed submission:
a,b=map(int,input().split())
print(int(a+b/2))

Buggy submission (verdict: Runtime Error):
81 58
Problem p03238 (python)

Fixed submission:
n=int(input())
if n==2:
  a=int(input())
  b=int(input())
if n==1:
  print("Hello World")
else:
  print(a+b)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
if n==1:
  print("Hello World")
else:
  print(a+b)
Problem p03355 (python)

Fixed submission:
s=input()
k=int(input())
n=len(s)
li=[]
for i in range(min(n,k)):
  for j in range(n-i):
    li.append(s[j:j+i+1])
li=set(li)
li=list(li)
li.sort()
print(li[k-1])

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
n=len(s)
li=[]
for i in range(min(n,k)):
  for j in range(n-i):
    li.append(s[j:j+i+1])
li.sort()
print(li[k])
Problem p03497 (python)

Fixed submission:
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
d=c.most_common()
ans=0
for i in range(min(k,len(d))):
  ans+=d[i][1]
print(n-ans)

Buggy submission (verdict: Runtime Error):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
d=c.most_common()
ans=0
for i in range(k):
  ans+=d[i][1]
print(n-ans)

Buggy submission (verdict: Runtime Error):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=collections.Counter(a)
cnt.most_common()
ans=0
for i in range(k):
  print(ans[i][1])
  ans+=cnt[i][1]
peint(ans)
Problem p03606 (python)

Fixed submission:
n=int(input())
l=[0]*n
r=[0]*n
for i in range(n):
  l[i],r[i]=map(int,input().split())
ans=0
for i in range(n):
  ans+=r[i]-l[i]+1
print(ans)

Buggy submission (verdict: Runtime Error):
2
6 8
3 3
Problem p03611 (python)

Fixed submission:
import collections

n=int(input())
a=list(map(int,input().split()))
m=max(a)
cnt=collections.Counter(a)
if m==0:
  print(len(a))
else:
  ans=[0]*(m-1)
  for j in range(m-1):
    ans[j]=cnt[j]+cnt[j+1]+cnt[j+2]
  print(max(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=max(a)
cnt=[0]*(m+1)
for i in range(m+1):
  cnt[i]=a.count(i)
ans=[0]*(m-1)
for j in range(m-1):
  ans[j]=cnt[j]+cnt[j+1]+cnt[j+2]
print(max(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=max(a)
cou=[0]*m
for i in range(m):
  cou[i]=a.count(i-1)+a.count(i)+a.count(i+1)
print(max(cou))
Problem p03632 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
if b<=c or d<=a:
  print(0)
elif a<c:
  print(min(d,b)-c)
else:
  print(min(b,d)-a)

Buggy submission (verdict: Runtime Error):
0 33 66 99
Problem p03760 (python)

Fixed submission:
o=input()
e=input()
O=len(o)
E=len(e)
ans=''
if O==E:
  for i in range(O):
    ans+=o[i]+e[i]
if O+1==E:
  for i in range(O):
    ans+=o[i]+e[i]
  ans+=e[-1]
if O-1==E:
  for i in range(E):
    ans+=o[i]+e[i]
  ans+=o[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
o=input()
e=input()
O=len(o)
E=len(e)
ans=''
if O==E:
  for i in range(O):
    ans+=o[i]+e[i]
if O+1==E:
  for i in range(O):
    ans+=o[i]+e[i]
  ans+=e[-1]
if O-1==E:
  for i in range(O):
    ans+=o[i]+e[i]
  ans+=o[-1]
print(ans)
Problem p03829 (python)

Fixed submission:
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ans=0
if a>=b:
  print(b*(n-1))
else:
  d=b//a
  
  for i in range(n-1):
    if x[i+1]-x[i]>d:
      ans+=b
    else:
      ans+=(x[i+1]-x[i])*a
  print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
if a>=b:
  print(b*n)
else:
  d=b//a
  ans=0
  for i in range(n-1):
    if x[i+1]-x[i]>d:
      ans+=b
    else:
      ans+=(x[i+1]-x[i])*a
print(ans)
Problem p03844 (python)

Fixed submission:
a,op,b=input().split()
if op=='+':
  print(int(a)+int(b))
else:
  print(int(a)-int(b))

Buggy submission (verdict: Runtime Error):
a,op,b=input().split()
if op='+':
  print(int(a)+int(b))
else:
  print(int(a)-int(b))
Problem p03963 (python)

Fixed submission:
n,k=map(int,input().split())
if n==1:
  print(k)
else:
  print(k*(k-1)**(n-1))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  
  if (n==1){
    cout<<k<<endl;
  }
  else {
    cout<<k*pow(k-1,n-1)<<endl;
  }
}
Problem p04011 (python)

Fixed submission:
n=int(input())
k=int(input())
x=int(input())
y=int(input())
print(min(n,k)*x+max(0,n-k)*y)

Buggy submission (verdict: Runtime Error):
n=int(input())
k=int(input())
x=int(input())
y=int(input())
print(k*x+(max(0,n-k)*y)
Problem p04030 (python)

Fixed submission:
s=input()
ans=[]
for i in range(len(s)):
  if s[i]=='0':
    ans.append(0)
  elif s[i]=='1':
    ans.append(1)
  elif ans==[]:
    continue
  else:
    ans.pop()
for j in range(len(ans)):
  print(ans[j],end='')

Buggy submission (verdict: Runtime Error):
s=input()
ans=[]
for i in range(len(s)):
  if s[i]=='0':
    ans.append(0)
  elif s[i]=='1':
    ans.append(1)
  else:
    ans.pop()
for j in range(len(ans)):
  print(ans[j],end='')
Problem p03071 (python)

Fixed submission:
a, b = map(int, input().split())
print(max(a, b)*2-(a!=b))

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
high = h[0]
ans = 1
for i in range(1,n):
    if high <= h[i]:
        ans += 1
        high = h[i]

print(ans)
Problem p02761 (python)

Fixed submission:
N, M = input().split(" ")
N = int(N)
M = int(M)

s = []
c = []

one_list = []
two_list = []
three_list = []

for i in range(M):
    tmp_s, tmp_c = input().split(" ")
    tmp_s = int(tmp_s)
    tmp_c = int(tmp_c)
    s.append(tmp_s)
    c.append(tmp_c)
    if tmp_s == 1:
        one_list.append(tmp_c)
    elif tmp_s == 2:
        two_list.append(tmp_c)
    elif tmp_s == 3:
        three_list.append(tmp_c)
    else:
        print("Error")


if len(set(one_list)) > 1:
    print(-1)
    exit()

if len(set(two_list)) > 1:
    print(-1)
    exit()

if len(set(three_list)) > 1:
    print(-1)
    exit()

result = ""
for i in range(N):
    result += "-"

str_list = list(result)
for i in range(M):
    str_list[s[i] - 1] = str(c[i])

if N > 1:
    if str_list[0] == "0":
        print(-1)
        exit()

str_list = list("".join(str_list).replace("-", "0"))
if N != 1:
    if str_list[0] == "0":
        str_list[0] = "1"

print("".join(str_list))

Buggy submission (verdict: Runtime Error):
N, M = input().split(" ")
N = int(N)
M = int(M)

s = []
c = []

one_list = []
two_list = []
three_list = []

for i in range(M):
    tmp_s, tmp_c = input().split(" ")
    tmp_s = int(tmp_s)
    tmp_c = int(tmp_c)
    s.append(tmp_s)
    c.append(tmp_c)
    if tmp_s == 1:
        one_list.append(tmp_c)
    elif tmp_s == 2:
        two_list.append(tmp_c)
    elif tmp_s == 3:
        three_list.append(tmp_c)
    else:
        print("Error")

if len(set(one_list)) > 1:
    print(-1)
    exit()

if len(set(two_list)) > 1:
    print(-1)
    exit()

if len(set(three_list)) > 1:
    print(-1)
    exit()


result = ""
for i in range(N):
    result += "0"


str_list = list(result)
for i in range(M):
    str_list[s[i] - 1] = str(c[i])

while str_list[0] == "0":
    str_list = str_list[1:]


print("".join(str_list))
Problem p03067 (python)

Fixed submission:
A, B, C = (int(i) for i in input().split())
 
if((A<C) and (C<B)):
    print("Yes")
elif((B<C) and (C<A)):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A, B, C = (int(i) for i in input().split())

if((A<C) and (C<B)):
    print("Yes")
elif((B<C) and (C<A)):
    print("Yes")
else:
    print("No")
A, B, C = (int(i) for i in input().split())

if((A<C) and (C<B)):
    print("Yes")
elif((B<C) and (C<A)):
    print("Yes")
else:
    print("No")
Problem p03087 (python)

Fixed submission:
N, Q = (int(i) for i in input().split())
S = input()

AC_list = [0] * (N+1)
 
val=0
for i in range(N-1):
    if(S[i+1]=="C"):
        if(S[i]=="A"):
            val +=1

    AC_list[i+1] = val
AC_list[i+2] = val

for i in range(Q):
    l, r = (int(_) for _ in input().split())
    if(r!=N):
        if(S[r-1]=="A" and S[r]=="C"):
            print(AC_list[r]-AC_list[l-1]-1)
        else:
            print(AC_list[r]-AC_list[l-1])
    else:
        print(AC_list[r]-AC_list[l-1])

Buggy submission (verdict: Runtime Error):
N, Q = (int(i) for i in input().split())
S = input()

AC_list = [0] * (N+1)
 
val=0
for i in range(N-1):
    if(S[i+1]=="C"):
        if(S[i]=="A"):
            val +=1

    AC_list[i+1] = val
AC_list[i+2] = val

for i in range(Q):
    l, r = (int(_) for _ in input().split())
    if(S[r-1]=="A" and S[r]=="C"):
        print(AC_list[r]-AC_list[l-1]-1)
    else:
        print(AC_list[r]-AC_list[l-1])

Buggy submission (verdict: Runtime Error):
N, Q = (int(i) for i in input().split())
S = input()

AC_list = [0] * N
 
val=0
for i in range(N-1):
    if(S[i+1]=="C"):
        if(S[i]=="A"):
            val +=1

    AC_list[i] = val

for i in range(Q):
    l, r = (int(_) for _ in input().split())
    if(AC_list[r-1]==1 and S[r]=="C"):
        print(val[r-1]-1)
    else:
        print(val[r-1])

Buggy submission (verdict: Runtime Error):
N, Q = (int(i) for i in input().split())
S = input()

AC_list = [0] * N
 
val=0
for i in range(N-1):
    if(S[i+1]=="C"):
        if(S[i]=="A"):
            val +=1

    AC_list[i] = val

for i in range(Q):
    l, r = (int(_) for _ in input().split())
    if(AC_list[r-1]==1 and S[r]=="C"):
        print(val[r-1]-1)
    else:
        print(val[r-1])
Problem p03089 (python)

Fixed submission:
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')

Buggy submission (verdict: Runtime Error):
N = int(input())
B = list(map(int,input().split()))
 
ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')
N = int(input())
B = list(map(int,input().split()))

ans = []
while B:
    for i,a in reversed(list(enumerate(B))):
        if i+1 == a:
            ans.append(a)
            del B[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')
Problem p03238 (python)

Fixed submission:
year = int(input())

if(year==1):
    print("Hello World")
else:
    a = int(input())
    b = int(input())

    print(int(a+b))

Buggy submission (verdict: Runtime Error):
N = int(input())
xyh = []

for i in range(N):
    xyh.append([int(i) for i in input().split()])

for x in range(101):
    for y in range(101):

        ##Reference Height##

        for i in range(len(xyh)):
            if(xyh[i][2] != 0):
                reference_index = i
        height = abs(x - xyh[reference_index][0]) + \
            abs(y - xyh[reference_index][1]) + xyh[reference_index][2]
        ####################

        counter = 0

        for n in range(N):
            if(xyh[n][2]==0):
                if not (height <= abs(x - xyh[n][0]) +
                        abs(y - xyh[n][1]) + xyh[n][2]):
                    counter += 1

            else:
                if not (height == abs(x - xyh[n][0]) +
                        abs(y - xyh[n][1]) + xyh[n][2]):
                    counter += 1

        if(counter == 0):
            print("{} {} {}".format(x, y, height))
Problem p03262 (python)

Fixed submission:
import numpy as np
from fractions import gcd

N, X = (int(i) for i in input().split())
x = np.array([int(i) for i in input().split()])

diff = abs(x-X)
intermediate_gcd = diff[0]

for i in range(len(x)-1):
    intermediate_gcd = gcd(intermediate_gcd, diff[i+1])

print(intermediate_gcd)

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

N, X = (int(i) for i in input().split())
x = np.array([int(i) for i in input().split()])

diff = abs(x-X)
intermediate_gcd = diff[0]

for i in range(len(x)-1):
    intermediate_gcd = math.gcd(intermediate_gcd, diff[i+1])

print(intermediate_gcd)
Problem p03274 (python)

Fixed submission:
import numpy as np

N, K = (int(i) for i in input().split())
x = np.sort(np.array([int(i) for i in input().split()]))

result = []
if(N==1):
    print(np.abs(x[0]))

else:
    for i in range(N - K + 1):
        left = x[i]
        right = x[i + K - 1]

        if (left * right < 0):
            if (np.abs(left) < np.abs(right)):
                diff = np.abs(left) * 2 + np.abs(right)
            else:
                diff = np.abs(left) + np.abs(right) * 2

        else:
            diff = np.max([np.abs(left), np.abs(right)])

        result.append(diff)

    print(np.min(result))

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

N, K = (int(i) for i in input().split())
x = np.sort(np.array([int(i) for i in input().split()]))

result = []
if(N==1):
    print(x[0])
else:
    for i in range(N - K + 1):
        left = x[i]
        right = x[i + K - 1]

        if (left * right < 0):
            if (np.abs(left) < np.abs(right)):
                diff = np.abs(left) * 2 + np.abs(right)
            else:
                diff = np.abs(left) + np.abs(right) * 2

        else:
            diff = np.max([left, right])

        result.append(diff)

#print(result)
print(np.min(result))

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

N, K = (int(i) for i in input().split())
x = np.sort(np.array([int(i) for i in input().split()]))

result = []
if(N==1):
    print(x[0])
    exit()
else:
    for i in range(N - K):
        left = x[i]
        right = x[i + K - 1]

        if (left * right < 0):
            if (np.abs(left) < np.abs(right)):
                diff = np.abs(left) * 2 + np.abs(right)
            else:
                diff = np.abs(left) + np.abs(right) * 2

        else:
            diff = np.max([left, right])

        result.append(diff)

print(np.min(result))
Problem p03493 (python)

Fixed submission:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:14:39 2017

@author: Kanoh
"""

#Placing Marbles
input_line1 = raw_input()#標準入力
total=0
counter=0
for i in range(len(input_line1)):
    if(int(input_line1[i])==1):
        counter=counter+1
        
print counter

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:24:31 2017

@author: Kanoh
"""
import numpy as np
N = int(raw_input())#標準入力
A = raw_input()#標準入力
A_split=A.split(" ")
A_int=np.zeros((N))

for i in range(int(N)):
    A_int[i]=int(A_split[i])

counter=0
checker=0
while 1 :
    for i in range(N):
        if((A_int[i]%2)!=1) and((A_int[i])>1):
            A_int[i]=A_int[i]/2
        else:
            checker=1
    if(checker==1):
        break
    else:
        counter=counter+1
    
print counter

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:24:31 2017

@author: Kanoh
"""
import numpy as np
N = int(raw_input())#標準入力
A = raw_input()#標準入力
A_split=A.split(" ")
A_int=np.zeros((N))

for i in range(int(N)):
    A_int[i]=int(A_split[i])

counter=0
checker=0
while 1 :
    for i in range(N):
        if(A_int[i]%2)!=1:
            A_int[i]=A_int[i]/2
        else:
            checker=1
    if(checker==1):
        break
    else:
        counter=counter+1
    
print counter
Problem p02783 (python)

Fixed submission:
H,A = map(int,input().split())

q,mod= divmod(H,A)

if mod > 0:
  q += 1
  
print(int(q))

Buggy submission (verdict: Runtime Error):
H,A = map(int,input.split())
q,mod= divmod(H,A)

if mod >0:
  q +=1
  
print(q)
Problem p02787 (python)

Fixed submission:
import sys
input = sys.stdin.readline
INF = float('INF')


def main():
    H, N = map(int, input().split())
    skills = [None] * N
    max_a = 0
    for i in range(N):
        a, b = map(int, input().split())
        if a > max_a:
            max_a = a
        skills[i] = (a, b)

    # dpの配列準備
    # インデックス→体力、中身→その体力を削るための最小MP
    dp = [INF] * (H + max_a + 1)
    dp[0] = 0

    # 各体力を削る最小MPをDPで更新していく
    for i in range(H):
        # そのHPをちょうど削る攻撃がない場合はそれ以降の行動を計算できないので飛ばす1
        if dp[i] == INF:
            continue

        # そうでない場合は、次の攻撃をシミュレーション
        for a, b in skills:
            # 攻撃した場合の累計消費MPを算出
            mp = dp[i] + b
            # その攻撃をした場合に削れる体力に割り当てられている消費MPと比較
            # より少ない消費MPで削れることがわかった場合は更新
            if mp < dp[i + a]:
                dp[i + a] = mp

    # 更新が終わったので、倒せるダメージのうち、累計消費MPが一番少ないものを出力
    print(min(dp[H:]))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readlin
INF = float('INF')


def main():
    H, N = map(int, input().split())
    skills = [None] * N
    max_a = 0
    for i in range(N):
        a, b = map(int, input().split())
        if a > max_a:
            max_a = a
        skills[i] = (a, b)

    # dpの配列準備
    # インデックス→体力、中身→その体力を削るための最小MP
    dp = [INF] * (H + max_a + 1111
    dp[0]=0


    # 各体力を削る最小MPをDPで更新していく
    for i in range(H):
        # そのHPをちょうど削る攻撃がない場合はそれ以降の行動を計算できないので飛ばす1
        if dp[i] == INF:
            continue

        # そうでない場合は、次の攻撃をシミュレーション
        for a, b in skills:
            # 攻撃した場合の累計消費MPを算出
            mp=dp[i] + b
            # その攻撃をした場合に削れる体力に割り当てられている消費MPと比較
            # より少ない消費MPで削れることがわかった場合は更新
            if mp < dp[i + a]:
                dp[i + a]=mp

    # 更新が終わったので、倒せるダメージのうち、累計消費MPが一番少ないものを出力
    print(min(dp[H:]))


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

Fixed submission:
import sys
input = sys.stdin.readline

def calc(n, a, b, ans, move):
    if (b-a)%2 == 0:
        return ans + (b-a)//2
    else:
        if move == 1:
            a += move
        else:
            b += move
        return calc(n, a, b, ans+1, move)
            
        

def main():
    N,A,B = (int(x) for x in input().split())

    if (B-A)%2 == 0:
        print((B-A)//2)
    else:
        left = A - 1
        right = N - B
        
        if left <= right:
            print(calc(N, 1, B-left, left, -1))
        else:
            print(calc(N, A+right, N, right, 1))        



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    N,A,B = (int(x) for x in input().split())


    def calc(n, a, b, ans):
        if abs(a-b)%2 == 0:
            return ans + (abs(a-b)//2)
        else:
            if min(a,b) - (n - max(a,b)) <= 0:
                a -= 1 if not a==1 else 0
                b -= 1 if not b==1 else 0
            else:
                a += 1 if not a==n else 0
                b += 1 if not b==n else 0
            ans += 1
            return calc(n,a,b,ans)



    # お互いに近づくのが最高のパターン
    if abs(A-B)%2 == 0:
        print(abs(a-b)//2)
        quit()
    
    # どちらかの端に寄ってから考えるパターン
    # 寄るための試合数
    left = min(A,B) -1
    right = N - max(A,B) - 1
    
    # 左によるパターン
    if left - right <= 0:
        print(calc(N, 1, B-left, left))
    else:
        print(calc(N, A+right, N, right))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)

def main():
    N,A,B = (int(x) for x in input().split())
    
    def calc(n, a, b, ans):
        if abs(a-b)%2 == 0:
            return ans + (abs(a-b)//2)
        else:
            if min(a,b) - (n - max(a,b)) <= 0:
                a -= 1 if not a==1 else 0
                b -= 1 if not b==1 else 0
            else:
                a += 1 if not a==n else 0
                b += 1 if not b==n else 0
            ans += 1
            return calc(n,a,b,ans)
            
    print(calc(N,A,B,0))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N,A,B = (int(x) for x in input().split())

def calc(n, a, b, ans):
    if abs(a-b)%2 == 0:
        return ans + (abs(a-b)//2)
    else:
        if min(a,b) - (n - max(a,b)) <= 0:
            a -= 1 if not a==1 else 0
            b -= 1 if not b==1 else 0
        else:
            a += 1 if not a==n else 0
            b += 1 if not b==n else 0
        ans += 1
        return calc(n,a,b,ans)
        
print(calc(N,A,B,0))
Problem p02787 (python)

Fixed submission:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Buggy submission (verdict: Runtime Error):
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [0] * (h + 1)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])