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

Fixed submission:
a = list(map(int,input().split()))
x = []
y = []
for i in range(a[1]):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
 
#s = str(2)
#print(s[-1])

def start(n):
  if n == 1:
    return 0
  else:
    return 10**(n-1)
    
flag = False
for i in range(start(a[0]),10**a[0]):
  s = str(i)
  flag = True
  for j in range(len(x)):
    if str(y[j]) != s[x[j]-(a[0]+1)]:
      flag = False
      break
  if flag:
    break
      

if flag:
  print(i)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
x = []
y = []
for i in range(a[1]):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)


for i in range(10**(a[0]-1),10**a[0]):
  s = str(i)
  flag = True
  for j in range(len(x)):
    if str(y[j]) != s[x[j]-4]:
      flag = False
      break
  if flag:
    break
      
#s = str(702)
#print(s[-1])
if flag:
  print(i)
else:
  print(-1)
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
La = sorted(list(map(int, input().split())), reverse=True)
Lb = sorted(list(map(int, input().split())), reverse=True)
Lc = sorted(list(map(int, input().split())), reverse=True)

L = La[:x]
L.extend(Lb[:y])
L.sort(reverse=False)
min = min(c, len(L))

for i in range(min):
    if L[i] < Lc[i]:
        L[i] = Lc[i]

print(sum(L))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
La = sorted(list(map(int, input().split())), reverse=True)
Lb = sorted(list(map(int, input().split())), reverse=True)
Lc = sorted(list(map(int, input().split())), reverse=True)

L = La[:x]
L.extend(Lb[:y])
L.sort(reverse=False)

for i in range(c):
    if L[i] < Lc[i]:
        L[i] = Lc[i]

print(sum(L))
Problem p02755 (python)

Fixed submission:
a, b = map(int, input().split())
import math
num = -1

for i in range(100000):
    if a == math.floor(i*0.08):
        if b == math.floor(i*0.1):
            num = i
            break
print(int(num))

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

for i in range(100000):
    if a == math.floor(i*0.08):
        if b == math.floor(i*0.1):
            num = i
            break
print(num)
Problem p02972 (python)

Fixed submission:
N = int(input())
A = [0]+[int(x) for x in input().split()]
res = [0]*(N+1)
sum_res = 0
for i in range(N):
    # 今見てるところ
    k = N-i
    tmp = 0
    for j in range(k,N+1,k):
       	tmp += res[j]
    res[k] = A[k] ^ tmp%2
    sum_res += res[k]
 
print(sum_res)
print(' '.join([str(i) for i,x in enumerate(res) if x==1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0]+[int(x) for x in input().split()]
dp = [0]*(N+1)
res = 0
for i in range(N):
    k = N-i
    if k < N//2:
        l = N//k
        dp[k] = A[k]-sum([dp[k*j] for j in range(2,l+1)])%2
    else:
        dp[k] = A[k]
    res += dp[k]
     
print(res)
print(' '.join([i for i,x in enumerate(dp) if x==1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0]+[int(x) for x in input().split()]
dp = [0]*(N+1)
res = 0
for i in range(N):
    # 今見てるところ
    k = N-i
    if k < N//2:
        dp[k] = A[k]-sum([x for i,x in enumerate(dp[k+1:]) if i%k==0])%2
    else:
        dp[k] = A[k]
    res += dp[k]

print(res)
print(' '.join([i for i,x in enumerate(dp) if x==1]))

Buggy submission (verdict: Runtime Error):
# 明らかにTLEする
N = int(input())
A = [0]+[int(x) for x in input().split()]
dp = [0]*(N+1)
res = 0
for i in range(N):
    k = N-i
    if k < N//2:
        dp[k] = A[k]-sum([x for i,x in enumerate(dp[k+1:]) if i%k==0])%2
    else:
        dp[k] = A[k]
    res += dp[k]

print(res)
print('0'.join([i for i,x in enumerate(dp) if x==1]))
Problem p03048 (python)

Fixed submission:
R,G,B,N = [int(i) for i in input().split()]
num = 0
box = sorted([R,G,B], key=lambda x:-x)
nums = [N//b for b in box]
for i in range(nums[0]+1):
    if (nums[0]-i)*box[0] + nums[1]*box[1] + nums[2]*box[2] < N:
        break
    for j in range(nums[1]+1):
        resj = (nums[0]-i)*box[0] + (nums[1]-j)*box[1]
        if resj + nums[2]*box[2] < N:
            break
        if resj > N:
            continue
        if (N-resj)%box[2]!=0:
            continue
        num += 1
print(num)

Buggy submission (verdict: Runtime Error):
R,G,B,N = [int(i) for i in input().split()]
num = 0
box = sorted([R,G,B], key=lambda x:-x)
nums = [N//b for b in box]
for i in range(nums[0]+1):
	if (nums[0]-i)*box[0] + nums[1]*box[1] + nums[2]*box[2] < N:
		break
	for j in range(nums[1]+1):
		resj = (nums[0]-i)*box[0] + (nums[1]-j)*box[1]
		if resj + nums[2]*box[2] < N:
			break
		if resj > N:
            continue
        if (N-resj)%box[2]!=0:
            continue
        num += 1
print(num)
Problem p03074 (python)

Fixed submission:
N, K = [int(i) for i in input().split()]
S = input()
arr_0,arr_1 = [],[]
val = 1
temp = S[0]
if temp == '0':
    arr_1 += [0]
for s in S[1:]+"_":
    if s == temp:
        val+=1
    else:
        if temp=="1":
            arr_1 += [val]
        else:
            arr_0 += [val]
        val = 1
    temp = s
if S[-1] == "0":
    arr_1 += [0]

max_ = sum(arr_0[:K]+arr_1[:K+1])
for i in range(1, len(arr_0)-K+1):
    if (arr_0[i+K-1]+arr_1[i+K]) > (arr_0[i-1]+arr_1[i-1]):
        tmp = sum(arr_0[i:i+K])+sum(arr_1[i:i+K+1])
        if tmp > max_:
            max_ = tmp
print(max_)

Buggy submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
S = input()
arr = []
val = 1
temp = S[0]
if temp == '1':
    arr += [0]
for s in S[1:]:
    if s == temp:
        val+=1
    else:
        arr += [val]
        val = 1
    temp = s
if val != 0:
    arr += [val]

print(max([sum(arr[i:i+K*2+1]) if i%2!=0 else sum(arr[i:i+K*2]) for i in range(len(arr)-(K*2)+1)]))
Problem p03136 (python)

Fixed submission:
input()
Ls = [int(i) for i in input().split()]
max_arg = Ls.index(max(Ls))
sum_ = sum([v for i,v in enumerate(Ls) if i != max_arg])
print("Yes" if Ls[max_arg] < sum_ else "No")

Buggy submission (verdict: Runtime Error):
import numpy as np
N = input()
Ls = np.array([int(i) for i in input().split()])
max_arg = np.argmax(Ls)
sum_ = sum([v for i,v in enumerate(Ls) if i != max_arg])
print("Yes" if Ls[max_arg] < sum_ else "No")

Buggy submission (verdict: Runtime Error):
import numpy as np
input()
Ls = np.array([int(i) for i in input().split()])
max_arg = np.argmax(Ls)
sum_ = sum([v for i,v in enumerate(Ls) if i != max_arg])
print("Yes" if Ls[max_arg] < sum_ else "No")
Problem p02741 (python)

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
k = int(input())

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[k-1])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3 ## -*- python -*-
import math

t = input().split()
a = int(t[0])
b = int(t[1])
c = int(t[2])

ans = "No"
if math.sqrt(a)+math.sqrt(b) < math.sqrt(c):
    ans = "Yes"
print(ans)
Problem p02743 (python)

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-

t = input().split()
a = int(t[0])
b = int(t[1])
c = int(t[2])

ans = "No"
z = c-a-b
if z > 0 and 4 * a * b < z*z:
    ans = "Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3 ## -*- python -*-
import math

t = input().split()
a = int(t[0])
b = int(t[1])
c = int(t[2])

ans = "No"
if math.sqrt(a)+math.sqrt(b) < math.squrt(c):
    ans = "Yes"
print(ans)
Problem p03828 (python)

Fixed submission:
import collections
import itertools
import functools
import math

s = set([])
if __name__ == "__main__":
    n = int(input())
    m = math.factorial(n)
    res = 1
    for j in range(2, n + 1):
        tmp = 1
        while m % j == 0:
            m = m//j
            tmp += 1
        res *= tmp
    print(res % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import collections
import itertools
import functools
import math

s = set([])
if __name__ == "__main__":
    n = math.factorial(int(input()))
    prims = (n + 1) * [0]
    p = 2
    while n >= p*p:
        if n % p == 0:
            prims[p] += 1
            n = n // p
        else:
            p += 1
    prims[n] += 1
    print(functools.reduce(lambda x, y: x * (y + 1), prims, 1) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import collections
import itertools
import functools
import math

s = set([])
if __name__ == "__main__":
    n = math.factorial(int(input()))
    prims = (n + 1) * [0]
    p = 2
    while n >= p*p:
        if n % p == 0:
            prims[p] += 1
            n = n // p
        else:
            p += 1
    prims[n] += 1
    print(functools.reduce(lambda x, y: x * (y + 1), prims, 1) % 10**9 + 7)

Buggy submission (verdict: Runtime Error):
import collections
import itertools
import functools
import math

s = set([])
if __name__ == "__main__":
    n = math.factorial(int(input()))
    prims = (n + 1) * [0]
    p = 2
    while n >= p*p:
        if n % p == 0:
            prims[p] += 1
            n = n // p
        else:
            p += 1
    prims[n] += 1
    print(functools.reduce(lambda x, y: x * (y + 1), prims, 1))
Problem p03861 (python)

Fixed submission:
if __name__ == "__main__":
    a, b, x = map(int, input().split())
    z = (b) // x
    z -= (a - 1) // x
    print(z)

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    a, b, x = map(int, input().split())
    if x > b:
        print(0)
    else:
        found = False
        i = a
        counter = 0
        while i < b + 1:
            if not found and i % x != 0:
                i += 1
            else:
                i += x
                counter += 1
    print(counter)

Buggy submission (verdict: Runtime Error):
from math import ceil
if __name__ == "__main__":
    a, b, x = map(int, input().split())
    if x > b:
        print(0)
    else:
        found = False
        i = a
        counter = 0
        while i < b + 1:
            if not found and i % x != 0:
                i += 1
            else:
                break
    print(ceil((b  + 1 - i)/x))
Problem p03607 (python)

Fixed submission:
n = int(input())
m = set()
while n:
    x = int(input())
    if x in m:
        m.remove(x)
    else:
        m.add(x)
    n -= 1
print(len(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
m = set()
while n:
    x = int(input())
    if x in m:
        m.remove(x)
    else:
        m.add(x)
print(len(m))
Problem p02742 (python)

Fixed submission:
h,w = map(int,input().split())
 
if h == 1 or w == 1:
    print(1)
elif h % 2 == 0:
    print(int(h*w/2))
elif h % 2 == 1 and w % 2 == 0:
    print(int(h*w/2))
else:
    print(int(h*(w//2)+h//2+1))

Buggy submission (verdict: Runtime Error):
if h == 1 or w == 1:
    print(1)
elif h % 2 == 0:
    print(int(h*w/2))
elif h % 2 == 1 and w % 2 == 0:
    print(int(h*w/2))
else:
    print(int(h*(w//2)+h//2+1))
Problem p02747 (python)

Fixed submission:
w = input()
 
if w == 'hi' or w == 'hihi' or w == 'hihihi' or w == 'hihihihi'or w == 'hihihihihi':
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import itertools
import sys
input = sys.stdin.readline
 
n,t = map(int,input().split())
l_a0 = []
l_a1 = []
 
for i in range(n):
    tmp = list(map(int,input().split()))
    if tmp[0] == 0:
        l_a0.append(tmp[1]+1)
    else:
        l_a1.append(tmp)
 
l_a0.sort()
l_a1.sort(reverse=True, key=lambda x: x[0]/(x[1]+1))

dp = [t*10] * 30 
dp[0] = 0

for a, b in l_a1:
        for num in range(28, -1, -1):
            candidate = (dp[num]+1) * (a+1) + b
            if candidate < dp[num+1]:
                dp[num+1] = candidate
dp = [i for i in dp if i <= t]

ans = [0]
for i in range(len(dp)):
    spendtime = dp[i]
    tmp = i
    for j in range(len(l_a0)):
        if spendtime + l_a0[j] <= t:
            spendtime += l_a0[j]
            tmp += 1
        else:
            break
    ans.append(tmp)
    
print(max(ans))
Problem p02761 (python)

Fixed submission:
n,m = map(int,input().split())
 
c = []
for i in range(m):
    c.append(list(map(int,input().split())))
 

ans = -1
if n == 1 and m == 0:
    ans = 0
elif m == 0 and n != 1:
    ans = pow(10,n-1)
elif n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = c[0][1]
            break
else:            
 for i in range(pow(10,n-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i
         break
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
 
c = []
for i in range(m):
    c.append(list(map(int,input().split())))
 
max = 0
for i in range(m):
    if c[i][0] >= max:
        max = c[i][0]
 
ans = -1
if n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = c[0][1]
else:            
 for i in range(pow(10,max-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i
         break
print(ans)

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

c = []
for i in range(m):
    c.append(list(map(int,input().split())))

max = 0
for i in range(m):
    if c[i][0] >= max:
        max = c[i][0]

ans = -1
if n == 1:
    tmp = 0
    for i in range(m):
        if c[i][1] == c[0][1]:
            tmp += 1
        if tmp == m:
            ans = c[0][1]
else:            
 for i in range(pow(10,max-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i

print(ans)

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

c = []
for i in range(m):
    c.append(list(map(int,input().split())))

max = 0
for i in range(m):
    if c[i][0] >= max:
        max = c[i][0]

ans = -1
for i in range(pow(10,max-1),pow(10,n)):
    tmp = 0
    for j in range(m):
        if str(i)[c[j][0]-1] == str(c[j][1]):
            tmp += 1
    if tmp == m:
         ans = i

print(ans)
Problem p03471 (python)

Fixed submission:
n,y = map(int,input().split())

a,b,c = (-1,-1,-1)
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            a,b,c = (i,j,n-i-j)
            break

print(a,b,c)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import sys

n,y = map(int,input().split())

sys.setrecursionlimit(n**2 +1)
@lru_cache(maxsize = n +1)
def depth(a,b):
    if a+b <= n:
        if (y-10000*a-5000*b)/1000 == n-a-b:
            print(a,b,n-a-b)
            exit()
        else:
            depth(a+1,b)
            depth(a,b+1)
   

if depth(0,0) ==None:
    print(-1,-1,-1)
else:
    print(depth(0,0))
Problem p03574 (python)

Fixed submission:
H, W = map(int, input().split())
#左右に'.'を余分に付けて標準入力からリストを作成
grid = [list('.'+input()+'.') for i in range(H)]
#上下にも付けてやる
grid.insert(0, list('.' * (W + 2)))
grid.append(list('.' * (W + 2)))
#答えを入れるリスト
ans = []
 
#付け足した行列はカウントしない
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '#':
      ans.append('#')
    else:
      #8方向にある'#'の数をカウント
      #付け足したのは'.'なので条件分岐は不要
      #str型で出力しなければjoinできない
      ans.append(str((grid[i-1][j-1:j+2]+grid[i][j-1:j+2]+grid[i+1][j-1:j+2]).count('#')))
  #一行終わったので改行を入れる
  ans.append('\n')
print(''.join(ans)) #リストをつないで出力

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
#左右に'.'を余分に付けて標準入力からリストを作成
grid = [list('.'+input()+'.') for i in range(H)]
#上下にも付けてやる
grid.insert(0, list('.' * (W + 2)))　#上
grid.append(list('.' * (W + 2)))　#下
#答えを入れるリスト
ans = []

#付け足した行列はカウントしない
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '#':
      ans.append('#')
    else:
      #8方向にある'#'の数をカウント
      #付け足したのは'.'なので条件分岐は不要
      #str型で出力しなければjoinできない
      ans.append(str((grid[i-1][j-1:j+2]+grid[i][j-1:j+2]+grid[i+1][j-1:j+2]).count('#')))
  #一行終わったので改行を入れる
  ans.append('\n')
print(''.join(ans)) #リストをつないで出力
Problem p02718 (python)

Fixed submission:
m = input()
b = input()
x = int(0)
a = list()

n, m = m.split(' ')
n = int(n)
m = int(m)

b = b.split(' ')
for i in range(len(b)):
    a.append(int(b[i]))

list.sort(a, reverse = True)

for i in range(len(a)):
    x += int(a[i])

for i in range(m):
    if int(a[i]) < x / (4 * m):
        print('No')
        exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
m = input()
a = input()
x = int(0)
y1, y2 = int(0)

n, m = m.spilit()

for i in range(0, len(a), 2):
    x += int(a[i])
    y2 = y1 if y1 < int(a[i]) else y2
    y1 = int(a[i]) if y1 < int(a[i]) else y1

if not y1 // 4 * m or y2 // 4 * m:
    print('Yes')

else:
    print('No')
Problem p02731 (python)

Fixed submission:
l=float(input())
print((l/3)**3)

Buggy submission (verdict: Runtime Error):

l=input()
print((l/3)^3)
Problem p02885 (python)

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

c=a-2*b
if c<0:
    c=0
    
print(c)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int, input().split()))
l=sorted([x for x in set(l) if l.count(x)<4])
ans=0
x=[]
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,(n-sum((x>l[j]+l[i]) for x in l))):
            if (l[i]<(l[j]+l[k])and l[j]<(l[i]+l[k]) and x.count([l[i],l[j],l[k]])==0):
                x.append([l[i],l[j],l[k]])
                ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int, input().split()))
l=sorted([x for x in set(l) if l.count(x)<4])
ans=0
x=[]
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,(n-sum((x>l[j]+l[i]) for x in l))):
            if (l[i]<(l[j]+l[k])and l[j]<(l[i]+l[k]) and x.count([l[i],l[j],l[k]])==0):
                x.append([l[i],l[j],l[k]])
                ans+=1

print(ans)
Problem p02888 (python)

Fixed submission:
def triangles(a): 
    n = len(a) 
    a.sort() 
    count = 0
    for i in range(0,n-2):
        k=i+2
        for j in range(i+1,n): 
            while (k < n and a[i] + a[j] > a[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
    return count
n=int(input())
a=list(map(int,input().split()))
print(triangles(a))

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int, input().split()))
l=sorted([x for x in set(l) if l.count(x)<4])
ans=0
x=[]
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,(n-sum((x>l[j]+l[i]) for x in l))):
            if (l[i]<(l[j]+l[k])and l[j]<(l[i]+l[k]) and x.count([l[i],l[j],l[k]])==0):
                x.append([l[i],l[j],l[k]])
                ans+=1

print(ans)
Problem p02981 (python)

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



print(min([b,n*a]))

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())
ans=2019
for i in range(l,r+1):
    for j in range(i+1,r+1):
        ans=min((i*j)%2019,ans)
        
        
print(ans)
Problem p02719 (python)

Fixed submission:
# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    N=N%K
    print(min(N, K-N))

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

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    print(math.gcd(N,K))

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

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

if N==0 or N%K==0:
    print("0")
else:
    print(math.gcd(N,K))
Problem p03163 (python)

Fixed submission:
N, W = (int(n) for n in input().split())
w, v = [], []
for _ in range(N):
    w_, v_ = (int(n) for n in input().split())
    w.append(w_)
    v.append(v_)

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for w_ in range(W + 1):
        if w_ >= w[i]:
            dp[i + 1][w_] = max(dp[i][w_], dp[i][w_ - w[i]] + v[i])
        else:
            dp[i + 1][w_] = dp[i][w_]

print(dp[N][W])

Buggy submission (verdict: Runtime Error):
N, weight_capacity = (int(n) for n in input().split())
weights, values = [], []
for _ in range(N):
    w, v = (int(n) for n in input().split())
    weights.append(w)
    values.append(v)

def knapsack_dp(weight_capacity, weights, values):
    """Solve knapsack problem by dynamic programming"""
    N = len(weights)
    dp = [[0] * (weight_capacity + 1) for _ in range(len(weights) + 1)]

    for i in range(N + 1):
        for w in range(weight_capacity + 1):
            if w >= weights[i]:
                dp[i + 1][w] = max(dp[i][w], dp[i][w - weights[i]] + values[i])
            else:
                dp[i + 1][w] = dp[i][w]

    return dp[N][weight_capacity]

print(knapsack_dp(weight_capacity, weights, values))
Problem p03472 (python)

Fixed submission:
N, H = map(int, input().split())
B = []
a_max = 0
for i in range(N):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    B.append(b)

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
        break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)

Buggy submission (verdict: Runtime Error):
N, H = map(int, input().split())
B = []
a_max = 0
for i in range(N):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    B.append(b)

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
	break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)

Buggy submission (verdict: Runtime Error):
N, H = map(int, input().split())
B = []
a_max = 0
for i in range(N):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    B.append(b)

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
	break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)
Problem p03473 (python)

Fixed submission:
print(48-int(input()))

Buggy submission (verdict: Runtime Error):
Q = int(input())


M = 10**5 + 5
primes = [True] * M
primes[0] = False
primes[1] = False


for i in range(2, M):
    if primes[i]:
        for j in range(2, M//i):
            primes[i*j] = False

cnt = [0] * M

for i in range(3, M):
    cnt[i] = cnt[i-1]
    if primes[i] and primes[(i+1)//2]:
        cnt[i] += 1

for q in range(Q):
    l, r = map(int, input().split())
    print(cnt[r] - cnt[l-1])
Problem p03476 (python)

Fixed submission:
Q = int(input())

M = 10**5+5
primes = [True] * M
primes[0] = False
primes[1] = False


for i in range(2, M):
    if primes[i]:
        for j in range(2, (M-1)//i+1):
            primes[i*j] = False

# print(primes)                                                                    
cnt = [0] * M

for i in range(3, M):
    cnt[i] = cnt[i-1]
    if primes[i] and primes[(i+1)//2]:
        cnt[i] += 1
# print(cnt)                                                                       
queues = []
for q in range(Q):
    l, r = map(int, input().split())
    queues.append((l, r))

for l, r in queues:
    print(cnt[r] - cnt[l-1])

Buggy submission (verdict: Runtime Error):
Q = int(input())

M = 10**5+5
primes = [True] * M
primes[0] = False
primes[1] = False


for i in range(2, M):
    if primes[i]:
        for j in range(2, M//i+1):
            primes[i*j] = False

print(primes)
cnt = [0] * M

for i in range(3, M):
    cnt[i] = cnt[i-1]
    if primes[i] and primes[(i+1)//2]:
        cnt[i] += 1
print(cnt)
queues = []
for q in range(Q):
    l, r = map(int, input().split())
    queues.append((l, r))

for l, r in queues:
    print(cnt[r] - cnt[l-1])