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

Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = []
v = 0
for _ in range(M):
    a, b = map(int, input().split())
    l = sum([1 << (int(v) - 1) for v in input().split()])
    L.append([a, b, l])
    v = v | l
if v != (1 << N) - 1:
     print(-1)
     exit()

dp = [[10 ** 18 for _ in range(1 << N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(M):
     for j in range(1 << N):
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

          dp[i + 1][j | L[i][2]] =  min(dp[i + 1][j | L[i][2]], dp[i][j] + L[i][0])

print(dp[M][(1 << N) - 1])

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

L = [None] * M
for i in range(M):
    A, B, = map(int, input().split())
    C = [int(v) for v in input().split()]
    
    L[i] = (A, C)

ans = 10 ** 18
for i in range(1 << N):
    t = set()

    for j in range(N):
        if (i >> j) & 1:
            t.add(j)

    m = set([v for v in range(1, N + 1)])
    score = 0
    for p in t:
        a = L[p]
        score += a[0]
        m = m - set(a[1])

    if len(m) == 0:
        ans = min(ans, score)

if ans == 10 ** 18:
    print(-1)
else:
    print(ans)
Problem p03006 (python)

Fixed submission:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
L = [[int(v) for v in input().split()] for _ in range(N)]

m = {}
for i in range(N):
    for j in range(N):
        if i != j:
            x, y = L[i]
            x2, y2 = L[j]

            key = (x - x2, y - y2)

            if m.get(key) == None:
                m[key] = 0
            m[key] += 1

if m == {}:
    print(1)
    exit()
print(N - max(m.values()))

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
L = [[int(v) for v in input().split()] for _ in range(N)]

m = {}
for i in range(N):
    for j in range(i, N):
        if i != j:
            x, y = L[i]
            x2, y2 = L[j]

            key = (x - x2, y - y2)

            if m.get(key) == None:
                m[key] = 0
            m[key] += 1

print(N - max(m.values()))
Problem p03231 (python)

Fixed submission:
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
S = list(input().strip())
T = list(input().strip())

def gcd(x, y):
    if y > x:
        x, y = y, x
    if x % y == 0:
        return y
    return gcd(y, x % y)

l = N * M // gcd(N, M)

# m = [None] * l
m = {}

for i in range(N):
    m[i * (l // N)] = S[i]

for i in range(M):
    index = i * (l // M)
    if m.get(index) == None:
        m[index] = T[i]
    elif m[index] == T[i]:
        pass
    else:
        print(-1)
        exit()

print(l)

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
S = list(input().strip())
T = list(input().strip())

def gcd(x, y):
    if y > x:
        x, y = y, x
    if x % y == 0:
        return y
    return gcd(y, x % y)

l = N * M // gcd(N, M)

m = [None] * l

for i in range(N):
    m[i * (l // N)] = S[i]

for i in range(M):
    index = i * (l // M)
    if m[index] == None:
        m[index] = T[i]
    elif m[index] == T[i]:
        pass
    else:
        print(-1)
        exit()

print(l)
Problem p03311 (python)

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

N = int(input())
l = list(map(int, input().split()))

for i in range(len(l)):
    l[i] = i - l[i] + 1

l.sort()
t = l[int(len(l) / 2)]

for i in range(len(l)):
    l[i] = abs(l[i] - t)
    
print(sum(l))

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

N = int(input())
l = list(map(int, input().split()))

for i in range(len(l)):
    l[i] = i - l[i] + 1

l.sort()
t = l[math.ceil(len(l) / 2)]

for i in range(len(l)):
    l[i] = abs(l[i] - t)
    
print(sum(l))
Problem p03854 (python)

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

S = list(reversed(input().strip()))
P = [list(reversed(v)) for v in ["dream", "dreamer", "erase", "eraser"]]

n = 0
while n < len(S):
    if S[n:n+5] == P[0] or S[n:n+5] == P[2]:
        n += 5
    elif S[n:n+7] == P[1]:
        n += 7
    elif S[n:n+6] == P[3]:
        n += 6
    else:
        print("NO")
        exit()
        
print("YES")

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

S = list(input().strip())
P = [list(v) for v in ["dream", "dreamer", "erase", "eraser"]]

n = 0
i = 0
his = deque()
while True:
    v = P[i]
    
    p = S[n:n+len(v)]
    if p == v:
        xx = S[n+len(v):]
        if xx == []:
            print("YES")
            exit()
        else:
            his.append([n, i + 1])
            n += len(v)
            i = 0
    else:
        i += 1
        if i == 4:
            if len(his) == 0:
                break
            else:
                n, i = his.pop()
                
print("NO")

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

S = list(input().strip())
P = [list(v) for v in ["dream", "dreamer", "erase", "eraser"]]

def dfs(n):
    if len(S[n:]) == 0:
        return True
    
    for v in P:
        if S[n:n+len(v)] == v:
            if dfs(n + len(v)):
                return True
    
    return False

if dfs(0):
    print("YES")
else:
    print("NO")
Problem p03994 (python)

Fixed submission:
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, = map(int, input().split())
S = [ord(v) - ord("a") for v in input().strip()]
N, = map(int, input().split())

for i in range(len(S)):
    c = 26 - S[i]
    if S[i] == 0:
        continue
    if c <= N:
        N -= c
        S[i] = 0

S[-1] += N % 26

print("".join([chr(ord("a") + v) for v in S]))

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, = map(int, input().split())
S = [ord("z") - ord(v) + 1 for v in input().strip()]
N, = map(int, input().split())

for i in range(len(S)):
    if S[i] <= N:
        N -= S[i]
        S[i] = 26

S[-1] -= N

print("".join([chr(ord("z") - v + 1) for v in S]))
Problem p04045 (python)

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

N, K = map(int, input().split())
L = [v for v in input().split()]

for n in range(N, 200000):
    s = list(str(n))
    
    f = False
    for c in s:
        if c in L:
            f = True
    if f:
        continue
            
    print("".join(s))
    exit()

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

N, K = map(int, input().split())
L = [int(v) for v in input().split()]
no = [v for v in range(10) if v not in L]

s = list(map(int, str(N)))

for i in range(len(s)):
    if i == 0:
        if s[i] in L:
            s[i] = min([v for v in no if v != 0 and v > s[i]])
    else:
        if s[i] in L:
            s[i] = min([v for v in no if v > s[i]])
            
print("".join(map(str, s)))
Problem p02658 (python)

Fixed submission:
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
prod=1
for i in range(0,n):
  prod=prod*A[i]
  #print(prod)
  if(prod==0):
      break
  if(prod>1000000000000000000):
    prod=-1
    break
print(prod)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[int(i) for i in input().split()]
prod=1
for i in range(0,N):
  prod=prod*A[i]
  if(prod>1000000000000000000):
    prod=-1
    break
print(prod)
Problem p02780 (python)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))
fac = [0] * 735477
fac[0] = 1
if (N >= 1):
    for i in range(1, 1010): fac[i] = i + 1 + fac[i - 1]
# 期待値
#print(p, fac[:max(p)])
exp = [0] * 735477
for i in range(N):
    exp[i] = fac[p[i] - 1] / p[i]
# print(exp)

Ans = 0
ans = [0] * 735477
ans[0] = sum(exp[:K])
for i in range(1, N - K + 1):
    if(i + K == N + 1): break
    ans[i] = ans[i - 1] - exp[i - 1] + exp[i + K - 1]
    # print(ans[i])
    #print(exp[i: i + K])
print(max(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
p = list(map(int, input().split()))
fac = [0] * 3010
fac[0] = 1
if (N >= 1):
    for i in range(1, 1010): fac[i] = i + 1 + fac[i - 1]
# 期待値
#print(p, fac[:max(p)])
exp = [0] * 3010
for i in range(N):
    exp[i] = fac[p[i] - 1] / p[i]
# print(exp)

Ans = 0
ans = [0] * 3000
ans[0] = sum(exp[:K])
for i in range(1, N - K + 1):
    if(i + K == N + 1): break
    ans[i] = ans[i - 1] - exp[i - 1] + exp[i + K - 1]
    # print(ans[i])
    #print(exp[i: i + K])
print(max(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
p = list(map(int, input().split()))
fac = [0] * 1010
fac[0] = 1
if (N >= 1):
    for i in range(1, 1010): fac[i] = i + 1 + fac[i - 1]
# 期待値
#print(p, fac[:max(p)])
exp = [0] * 1010
for i in range(N):
    exp[i] = fac[p[i] - 1] / p[i]
#print(exp)

Ans = 0
ans = [0] * N
ans[0] = sum(exp[:K])
for i in range(1, N - K + 1):
    if(i + K == N + 1): break
    ans[i] = ans[i - 1] - exp[i - 1] + exp[i + K - 1]
    #print(ans[i])
    #print(exp[i: i + K])
print(max(ans))
Problem p02995 (python)

Fixed submission:
from fractions import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = A // C, A // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), A // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
if(A % C != 0): ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from fraction import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = A // C, A // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), A // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
if(A % C != 0): ans += 1
print(ans)
Problem p03106 (python)

Fixed submission:
a, b, k = map(int, input().split())
if (a == 1 or b == 1):
    print(1)
    exit(0)
div = []
ans = 0
for i in range(1, max(a, b) + 1):
    if (a % i == 0 and b % i == 0):
        div.append(i)
div.reverse()
print(div[k - 1])

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
if (a == 1 or b == 1):
    print(1)
    exit(0)
div = []
ans = 0
for i in range(1, max(a, b)):
    if (a % i == 0 and b % i == 0):
        div.append(i)
div.reverse()
print(div[k - 1])
Problem p03262 (python)

Fixed submission:
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(X - x[0])
if (N == 1):
   print(ans)
   exit(0)
for i in range(1, len(x)):
    ans = gcd(abs(x[i] - x[i - 1]), ans)
print(ans)

Buggy submission (verdict: Runtime Error):
#提出の際にmathをfractionsにする(2020/1/17現在)
from math import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(X - x[0])
if (N == 1):
   print(ans)
   exit(0)
for i in range(1, len(x)):
    ans = gcd(abs(x[i] - x[i - 1]), ans)
print(ans)

Buggy submission (verdict: Runtime Error):
#提出の際にmathをfractionsにする(2020/1/17現在)
from math import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
if (N == 1):
   print(x[0])
   exit(0)
ans = abs(X - x[0])
for i in range(1, len(x)):
    ans = gcd(abs(x[i] - x[i - 1]), ans)
print(ans)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
first = len(s)
for i in range(len(s)):
  if s[i] != '1': first = i; break
if s[0] != '1': print(s[0]); exit(0)
print(1) if k <= first else print(s[first])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
if (s[0] != '1'):
    print(s[0])
    exit(0)
first = s.find('1')
print(1) if k < first else print(s[first+1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
if (s[0] != '1'):
    print(s[0])
    exit(0)
first = s.find('1')
print(1) if k <= first or first == len(s) else print(s[first + 1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
if (s[0] != '1'):
  print(s[0])
  exit(0)
first = s.find('1')
print(1) if k <= first else print(s[first + 1])
Problem p03370 (python)

Fixed submission:
n, x = map(int, input().split())
m = [int(input()) for i in range(n)]
ans, x = n, x - sum(m)
while (x - min(m) >= 0):
    x -= min(m)
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
m = [int(input()) for i in range(n)]
ans, x = n, x - sum(m)
while (x - min(m) >= 0):
    x, ans -= min(m), ans + 1
print(ans)
Problem p03474 (python)

Fixed submission:
a, b = map(int, input().split())
s = input()
flag = True
if (s[a] != '-'): flag = False
for i in range(a + b - 1):
    if (i == a): pass
    elif s[i] == '-': flag = False
print('Yes') if flag else print('No')

Buggy submission (verdict: Runtime Error):
import sys
a, b = map(int, input().split())
s = input()
flag = 0
for i in range(len(a + b - 1)):
    if (s[a]) == '-': flag = True
    if (s[not a] == '-'):
        print('No')
        sys.exit()
print('Yes') if flag else print('No')
Problem p03632 (python)

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

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if (b <= c or d <= a): print(0)
elif (b <= d or c <= a): print(max(abs(a - d) - abs(a - c) - abs(b - d), abs(b - c) - abs(a - c) - abs(b - d)))
else: print(max(abs(a - b) - abs(a - c) - abs(b - d), abs(c - d) - abs(a - c) - abs(b - d))
Problem p03633 (python)

Fixed submission:
import fractions
N = int(input())
T = [int(input()) for i in range(N)]
a = T[0]
for i in range(1, N):
    b = T[i]
    a = a * b // fractions.gcd(a, b)
print(a)

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if (b <= c or d <= a): print(0)
if (b < d or c < a): print(max(abs(a - d) - abs(a - c) - abs(b - d), abs(b - c) - abs(a - c) - abs(b - d)))
if((a - d) * (b - c) < 0): print(max(abs(a - b) - abs(a - c) - abs(b - d), abs(c - d) - abs(a - c) - abs(b - d)))
Problem p03695 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
color = [0] * 9
for p in a:
    if p >= 3200: color[8] += 1
    else: color[p // 400] += 1
small = len([c for c in color[0:8] if c > 0])
big = small + color[8]
if not small: small += 1
print(small, big)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
color = [0] * 8
for p in a:
    if p >= 3200: color[8] += 1
    else: color[p // 400] += 1
small = len([c for c in color[0:8] if c > 0])
big = small + color[8]
if not small: small += 1
print(small, big)
Problem p03731 (python)

Fixed submission:
N, T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = T
for i in range(0, N-1):
  ans += min(t[i+1]-t[i],T)
print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = T
wait = 0
start = 0
for i in range(1, N):
    if (t[i] - t[i - 1] >= T):
        ans += wait + T
        start = t[i]
        wait = 0
    else:
      wait = t[i] - start
        if (wait > T):
            ans, wait = ans + T, wait - T
print(ans + wait)
Problem p03740 (python)

Fixed submission:
x, y = map(int, input().split())
print('Alice') if abs(x - y) > 1 else print('Brown')

Buggy submission (verdict: Runtime Error):
x, y = input().split()
print('Alice') if (x + y) > 1 else print('Brown')
Problem p04030 (python)

Fixed submission:
# -*- coding: UTF-8 -*-
s = input()
ans = ''
for c in s:
    if c == 'B':
      ans = ans[:-1]
    else:
      ans += c

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: UTF-8 -*-
s = input()
a = []
for c in s:
    if (c == '0'):
        a.append('0')
    elif (c == '1'):
        a.append('1')
    else:
        a.pop()

answer = ''.join(a)
print(answer)
Problem p04044 (python)

Fixed submission:
# -*- coding: UTF-8 -*-
N, L = map(int, input().split())
a = [input() for i in range(N)]
a.sort()
b = "".join(a)
print(b)

Buggy submission (verdict: Runtime Error):
# -*- coding: UTF-8 -*-
L, N = map(int, input().split())
a = [input() for i in range(N)]
a.sort()
b = "".join(a)
print(b)

Buggy submission (verdict: Runtime Error):
# -*- coding: UTF-8 -*-
L, N = map(int, input().split())
a = list(input() for i in range(N))
a.sort()
b = "".join(a)
print(b)

Buggy submission (verdict: Runtime Error):
# -*- coding: UTF-8 -*-
L, N = map(int, input().split())
a = list(input() for i in range(N))
a.sort()
b = " ".join(a)
print(b)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
a,b=int(input().split())

print(a*b)
Problem p02730 (python)

Fixed submission:
import sys

s = str(input())
n = len(s)
left = s[0:int((n-1)/2)]
right = s[int(((n+3)/2)-1):n]
l = len(left)

for i in range(int((n-1)/2)):
    if s[i] == s[n-1-i]:
        continue
    else:
        print("No")
        sys.exit()

for i in range(int((n-1)/4)):
    if left[i] == left[l-1-i] and right[i] == right[l-1-i]:
        continue
    else:
        print("No")
        sys.exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
As = list(map(int, input().split()))

number_counter = {}
for i in As:
    if str(i) in number_counter:
        number_counter[str(i)] += 1
    else:
        number_counter[str(i)] = 1
# 自分の数字以外の方法の合計は一緒。

howmanyways_in_number_by_default = {}
for k, v in number_counter.items():
    if v == 1:
        howmanyways_in_number_by_default[k] = 0
    else:
        howmanyways_in_number_by_default[k] = (v*(v-1))/2

for i in range(n):
    ways = 0
    # 自分以外の通りから自分のとこを引く
    for k, v in howmanyways_in_number_by_default.items():
        if int(k) == As[i]:
            ways += ((number_counter[str(As[i])]-1)*(number_counter[str(As[i])]-2))/2
        else:
            ways += v

    print(int(ways))
Problem p02657 (python)

Fixed submission:
x,y = map(int,input().split())
print(x*y)

Buggy submission (verdict: Runtime Error):
from decimal import Decimal


def main():
    A, B = map(Decimalt,input().split())

    print(int(A*B))
    return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from decimal import Decimal


def main():
    A, B = map(Decimalt,input().split())
    print(int(A*B))

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

Fixed submission:
N = input()
A = list(map(int,input().split()))
def main(A):
    if 0 in A:
        print(0)
        return

    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return

    print(prod)

main(A)

Buggy submission (verdict: Runtime Error):
def main ():
	N = int(input())
	A = list(map(int,input().split()))
	if 0 in A:
    	print (0)
		return

    prod = 1
    for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1) return
	print(prod)

main ()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    A = list(map(int,input().split()))

    if 0 in A:
        print(0)
        return

prod = 1
for a in A:
    prod *= a
    if prod > 1000000000000000000:
        print(-1)
        return

print(prod)

main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    A = list(map(int,input().split()))

    if 0 in A:
        print(0)
        return

prod = 1
for a in A:
    prod *= a
    if prod > 10000000000000000000:
        print(-1)
        return

print(prod)

main()

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vals(N);
  for (int i = 0; i < N;i++){
    cin >> vals.at(i);
  }
  int prod = std::accumulate(vals.begin(), vals.end(), 1, [](int init, int v) { return init * v; });
  if (prod > pow(10, 18)){
    cout << "-1" << endl;
  }
  else cout << prod << endl;
}
Problem p02787 (python)

Fixed submission:
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

start = float('inf')
minimum = float('inf')
for i in range(N):
  start = min(start, magic[i][0])
  minimum = min(minimum, magic[i][1])

for i in range(1, start + 1):
  dp[i] = minimum

for i in range(start + 1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split(' '))
magic = [[0 for _ in range(3)] for j in range(N)]
for i in range(N):
  temp_a, temp_b = map(int, input().split())
  magic[i][0] = temp_a
  magic[i][1] = temp_b
#   magic[i][2] = temp_a / temp_b

dp = [float('inf')] * (H + 1)
dp[0] = 0

start = float('inf')
minimum = float('inf')
for i in range(N):
  start = min(start, magic[i][0])
  minimum = min(minimum, magic[i][1])

for i in range(1, start + 1):
  dp[i] = minimum

for i in range(1, H + 1):
  for j in range(N):
    if i >= magic[j][0]:
      dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i])
    else:
      dp[i] = min(magic[j][1], dp[i])

print(dp[H])
Problem p02995 (python)

Fixed submission:
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(x, y):
  return (x * y) // gcd(x, y)
A, B, C, D = map(int, input().split(' '))
can_dived_c = B // C - (A - 1) // C
can_dived_d = B // D - (A - 1) // D
can_dived_both = B // lcm(C, D) - (A - 1) // lcm(C, D)
res = B - (A - 1) - can_dived_c - can_dived_d + can_dived_both
print(res)

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
  return (x * y) // math.gcd(x, y)
A, B, C, D = map(int, input().split(' '))
res = 0
can_dived_c = B // C - (A - 1) // C
can_dived_d = B // D - (A - 1) // D
can_dived_both = B // lcm(C, D) - (A - 1) // lcm(C, D)
res = B - (A - 1) - can_dived_c - can_dived_d + can_dived_both
print(res)