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

Fixed submission:
W = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

S = input()

for j in range(7):
    if W[j] == S:
        print(7-j)

Buggy submission (verdict: Runtime Error):
W = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
for j in range(7):
    if W[j] == input():
        print(7-j)
Problem p03327 (python)

Fixed submission:
N = int(input())
if 1 <= N <= 999:
    print("ABC")
else:
    print("ABD")

Buggy submission (verdict: Runtime Error):
N = input()
if 1 <= N <= 999:
    print("ABC")
else:
    print("ABD")
Problem p02597 (python)

Fixed submission:
n = int(input())
c = [l for l in input()]
ideal = ['R']*(c.count('R')) + ['W']*(c.count('W'))

w_to_r=0
r_to_w=0
for i_, c_ in zip(ideal, c):
  if (i_=='R') and (c_=='W'):
    w_to_r+=1
  if (i_=='W') and (c_=='R'):
    r_to_w+=1

print(max(w_to_r, r_to_w))

Buggy submission (verdict: Runtime Error):
n = int(input())
c = [l for l in input()]
max_idx = len(c)-1

if 'W' not in c:
  print(0)
else:
  most_left_white = c.index('W')
  tmp = c[::-1]
  most_right_red = max_idx - tmp.index('R')

  cnt = 0
  while most_left_white<most_right_red:
    c[most_left_white] = 'R'
    c[most_right_red] = 'W'

    most_left_white = c.index('W')
    tmp = c[::-1]
    most_right_red = max_idx - tmp.index('R')
    cnt+=1
  print(cnt)
Problem p02623 (python)

Fixed submission:
n, m, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for i, a in enumerate(sa):
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+r)
      
  
    
print(best)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
a_sum = 0
b_sum = sum(b_list)

j = m
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  if a_sum>k:
    break
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
    
  best = max(best,i+j+2)
      
  
    
print(best)

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

for i in range(1,n):
  a_list[i]=a_list[i-1]+a_list[i]
for i in range(1,n+1):
  b_list[i]=b_list[i-1]+b_list[i]

max_ = 0
for i in range(n):
  if k < a_list[n-i-1]:
    pass
  else:
    for j in range(m):
      if k-a_list[n-i-1] < b_list[m-j-1]:
        pass
      else:
        max_ = max(len(a_list[:n-i])+len(b_list[:m-j]), max_)
        break
print(max_)

Buggy submission (verdict: Runtime Error):
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

if sum(list_)<=k:
  print(len(list_))
else:
  left = 0
  right = len(list_)
  while abs(left-right)>1:
    mid = (left+right) // 2
    if sum(list_[:mid])<=k:
      left = mid
    else:
      right = mid

  print(len(list_[left]))
Problem p02629 (python)

Fixed submission:
n = int(input())
s=''
while n!=0:
  n-=1
  tmp=n%26
  s=chr(96+tmp+1)+s
  n//=26
print(s)

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

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

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

length=0
tmp = n
while True:
  if tmp-26**length < 26**(length+1):
    break
  length+=1
  tmp-=26**length

s = ['a']*(length+1)
maps = {'1':'a',
       '2':'b',
       '3':'c',
       '4':'d',
       '5':'e',
       '6':'f',
       '7':'g',
       '8':'h',
       '9':'i',
       '10':'j',
       '11':'k',
       '12':'l',
       '13':'m',
       '14':'n',
       '15':'o',
       '16':'p',
       '17':'q',
       '18':'r',
       '19':'s',
       '20':'t',
       '21':'u',
       '22':'v',
       '23':'w',
       '24':'x',
       '25':'y',
       '26':'z',
       }

keta = 1

while True:
  s[len(s)-keta] = maps[str(n%26)]
  n //= 26
  keta+=1
  if n==0:
    break
print(''.join(s))
Problem p02659 (python)

Fixed submission:
from decimal import Decimal

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

print(int(a*b))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(a*(b*100) // 100)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(int(a*b))
Problem p02688 (python)

Fixed submission:
n, k = map(int, input().split())
n_list = [1]*n
for _ in range(k):
  _ = input()
  for i in list(map(int, input().split())):
    n_list[i-1] = 0
print(sum(n_list))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
n_list = [1]*n
for _ in range(k):
  _ = input()
  for i in range(list(map(int, input().split()))):
    n_list[i-1] = 0
print(sum(n_list))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
n_list = [1]*n
for _ in range(b):
  _ = input()
  for i in range(list(map(int, input().split()))):
    n_list[i-1] = 0
print(sum(n_list))
Problem p02819 (python)

Fixed submission:
a = int(input())

def factorization(n):
    arr = []
    tmp = n

    for i in range(2, int(n**0.5//1)+1):
        if tmp%i==0:
            cnt = 0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    if tmp!=1:
        arr.append([tmp,1])
    if arr==[]:
        arr.append([n,1])
    return arr

while True:
  arr = factorization(a)
  if (len(arr)==1) & (arr[0][1]==1):
    print(a)
    break
  a+=1

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

def factorization(n):
    arr = []
    tmp = n

    for i in range(2, int(n**0.5//1)+1):
        if tmp%i==0:
            cnt = 0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    if tmp!=1:
        arr.append([tmp,1])
    if arr==[]:
        arr.append([n,1])
    return arr

while True:
  arr = factorization(a)
  if (len(arr)==1) & (arr[1]==1):
    print(a)
    break
  a+=1
Problem p02933 (python)

Fixed submission:
n = int(input())
s= input()
if n<3200:
  print("red")
else:
  print(s)

Buggy submission (verdict: Runtime Error):
n = inr(input())
s= input()
if n<=3200:
  print("red")
else:
  print(s)

Buggy submission (verdict: Runtime Error):
n = inr(input())
s= input()
if n<=:
  print("red")
else:
  print(s)
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
stairs = [1]*(n+1)
for _ in range(m):
  stairs[int(input())] = -1

flg = False
for i in range(2,n+1):
  if stairs[i]==-1:
    pass
  elif stairs[i-1]==-1 and stairs[i-2]==-1:
    flg=True
    break
  elif stairs[i-1]==-1:
    stairs[i] = stairs[i-2]
  elif stairs[i-2]==-1:
    stairs[i] = stairs[i-1]
  else:
    stairs[i] = stairs[i-1] + stairs[i-2]
if flg:
  print(0)
else:
  print(stairs[-1]%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
breaks = []
for _ in range(m):
  breaks.append(int(input())-1)
stairs = [0 for _ in range(n)]

if n == 1:
  print(1)
else:
  if 0 not in breaks:
    stairs[0]=1

  if 1 not in breaks:
    stairs[1]=1  

  for i in range(n):
    if i+1 not in breaks:
      if i+1>=n:
        pass
      else:
        stairs[i+1]=stairs[i]+stairs[i+1]
    if i+2 not in breaks:
      if i+2>=n:
        pass
      else:
        stairs[i+2]=stairs[i]+stairs[i+2]
    if len(n)>3:
      if sum(stairs[-3:]) == 0:
        break

  print(stairs[-1]%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
breaks = []
for _ in range(m):
  breaks.append(int(input())-1)
stairs = [0 for _ in range(n)]

if 0 not in breaks:
  stairs[0]=1

if 1 not in breaks:
  stairs[1]=1  

for i in range(n):
  if i+1 not in breaks:
    if i+1>=n:
      pass
    else:
      stairs[i+1]=stairs[i]+stairs[i+1]
  if i+2 not in breaks:
    if i+2>=n:
      pass
    else:
      stairs[i+2]=stairs[i]+stairs[i+2]
      
print(stairs[-1]%1000000007)
Problem p03075 (python)

Fixed submission:
import numpy as np

posi_list = []
for _ in range(5):
  posi_list.append(int(input()))
k = int(input())

flag=True
for i in range(5):
  temp_posi_list = posi_list.copy()
  posi = temp_posi_list[i]
  del temp_posi_list[i]
  temp_posi_list = np.array(temp_posi_list)
  max_dist = max(np.abs(temp_posi_list - posi))
  if max_dist > k:
    flag=False
    break
if flag:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
posi_list = []
for _ in range(5):
  posi_list.append(int(input()))
k = int(input())

flag=True
for i in range(5):
  temp_posi_list = posi_list.copy()
  posi = temp_posi_list[i]
  del temp_posi_list[i]
  temp_posi_list = np.array(temp_posi_list)
  max_dist = max(np.abs(temp_posi_list - posi))
  if max_dist > k:
    flag=False
    break
if flag:
  print("Yay!")
else:
  print(":(")
Problem p03315 (python)

Fixed submission:
S = list(input())
p_cnt = S.count("+")
m_cnt = S.count("-")
print(int(p_cnt - m_cnt))

Buggy submission (verdict: Runtime Error):
S = list(map(int,input().split()))
p_cnt = S.count("+")
m_cnt = S.count("-")
print(int(p_cnt - m_cnt))
Problem p02833 (python)

Fixed submission:
N = int(input())
M = 10
ans = 0

if N % 2 == 0:
  while N >= M:
    ans += N//M
    M *= 5
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
M = 10
ans = 0

if N % 2 == 0
  while N > M:
    ans += N//M
    M *= 5
print(ans)
Problem p03272 (python)

Fixed submission:
N,i=map(int,input().split())
print(N-i+1)

Buggy submission (verdict: Runtime Error):
N,i=map(int,input())
print(N-i+1)
Problem p03618 (python)

Fixed submission:
A = input()

Alphabet = list("abcdefghijklmnopqrstuvwxyz")

N = len(A)
ans = N*(N-1)/2 + 1

for i in Alphabet:
  z = 0
  for j in range(len(A)):
    if i == A[j]:
      z+=1
  if z>1:
    ans -= z*(z-1)/2
    
print(int(ans))

Buggy submission (verdict: Runtime Error):
A = input()
ans = 1
for i in range(len(A)):
  for j in range(j,len(A)):
    if A[i] != A[j]:
      ans += 1
      
print(ans)

Buggy submission (verdict: Runtime Error):
A = input()
ans = 1
for i in range(len(A)):
  for j in range(len(j,A)):
    if A[i] != A[j]:
      ans += 1
      
print(ans)
Problem p02661 (python)

Fixed submission:
def main():
    N = int(input())
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        minMed = A[N//2]
        maxMed = B[N//2]
        print(int(maxMed-minMed)+1)
    else:
        minMed = A[N//2-1] + A[N//2]
        maxMed = B[N//2-1] + B[N//2]
        print(int(maxMed-minMed)+1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        minMed = A[N/2]
        maxMed = B[N/2]
        print(int(maxMed-minMed)+1)
    else:
        minMed = A[N//2-1] + A[N//2]
        maxMed = B[N//2-1] + B[N//2]
        print(int(maxMed-minMed)+1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A,B = [],[]
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        minMed = A[N/2]
        maxMed = B[N/2]
        print(int(maxMed-minMed)+1)
    else:
        minMed = A[N//2-1] + A[N//2]
        maxMed = B[N//2-1] + B[N//2]
        print(minMed,maxMed)
        print(int(maxMed-minMed)+1)

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

Fixed submission:
# -*- coding: utf-8 -*-
import itertools
n = int(input())
print(len(list(itertools.product(range(1,n+1), repeat=3))))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from itertools import combination_with_replacement

n = int(input())
print(len(list(combination_with_replacement(n, 3))))
Problem p02831 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

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

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print((a*b)//math.gcd(a, b))

Buggy submission (verdict: Runtime Error):
import math

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

print(int((a*b)/math.gcd(a, b)))
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
a = set(a)
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1
for i in range(2,n+1):
    if i not in a:
        dp[i] = dp[i-1]+dp[i-2]
print(dp[-1]%mod)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ls=[int(input()) for i in range(m)]

if 1 in ls:
    steps=[1,0]
else:
    steps=[1,1]

for this_step in range(2,n+1):
    if this_step in ls:
        ap=0
    else:
        ap=steps[-1]+steps[-2]
    steps.append(ap)
    print(steps)

print(steps[-1]%1000000007)
Problem p02785 (python)

Fixed submission:
s = [list(map(int,input().split())) for i in range(2)]
t = s[0]
N = t[0]
K = t[1]
H = s[1]
if K > N:
    print(0)
else:
    H.sort()
    H[N - K:N]=[]
    print(sum(H))

Buggy submission (verdict: Runtime Error):
s = [list(map(int,input().split())) for i in range(2)]
t = s[0]
N = t[0]
K = t[1]
H = s[1]
for i in range(K):
    a = max(H)
    H.remove(a)
print(sum(H))
Problem p03835 (python)

Fixed submission:
def Sumofnum(K,S):
    A = min(K,S) + 1
    a = max(S - 2*K, 0)
    c = 0
    for x in range (a,A):
        B = min(S - x,K) + 1
        b = max(S - x - K,0)
        for y in range (b,B):
            c = c + 1
    print(c)
    
s = list(map(int,input().split()))
K = s[0]
S = s[1]
Sumofnum(K,S)

Buggy submission (verdict: Runtime Error):
def Sumofnum(K,S):
    A = min(K,S) + 1
    a = max(S - 2*K, 0)
    c = 0
    for x in range (a,A):
        B = min(S - x,K) + 1
        b = max(S - x - K,0)
        for y in range (b,B):
            c = c + 1
    print(c)
    
s = list(map(int,input().split()))
Sumofnum(K,S)
Problem p02781 (python)

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

keta = len(n)

# dp0 = ヨユーなやつ, dp1 = ギリなやつ
dp0 = [[0 for j in range(keta+1)] for i in range(keta+1)]
dp1 = [[0 for j in range(keta+1)] for i in range(keta+1)]

dp1[0][0] = 1

for i in range(keta):
    for j in range(keta+1):
        # ギリギリのやつ(dp1)の処理
        if n[i] == '0': # i+1桁目が0の場合
            dp1[i+1][j] = dp1[i][j] # 真上からスライド
        else: # i+1桁目が1~9の場合
            if j < keta:
                dp1[i+1][j+1] = dp1[i][j] # 左上からスライド
        
        # ヨユーなやつ(dp0)の処理
        if n[i] == '0': # i+1桁目が0の場合
            # i桁目がヨユーな状態ではi+1桁目には何でも入れられる
            dp0[i+1][j] += dp0[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp0[i][j] * 9 # i+1桁目に1~9を入れた場合
            # i桁目までギリだったときの、i+1桁目のヨユーなやつのカウント
                # 何もない(ギリである0しか入れられないため)
        else: # i+1桁目が1~9の場合
            # i桁目がヨユーな状態ではi+1桁目には何でも入れられる
            dp0[i+1][j] += dp0[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp0[i][j] * 9 # i+1桁目に1~9を入れた場合
            # i桁目までギリだったときの、i+1桁目のヨユーなやつのカウント
            dp0[i+1][j] += dp1[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp1[i][j] * (ord(n[i])-ord('0')-1) # i+1桁目にrange(1, n[i])を入れた場合

if k > keta:
    print(0)
else:
    print(dp0[keta][k] + dp1[keta][k])

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

keta = len(n)

# dp0 = ヨユーなやつ, dp1 = ギリなやつ
dp0 = [[0 for j in range(keta+1)] for i in range(keta+1)]
dp1 = [[0 for j in range(keta+1)] for i in range(keta+1)]

dp1[0][0] = 1

for i in range(keta):
    for j in range(keta+1):
        # ギリギリのやつ(dp1)の処理
        if n[i] == '0': # i+1桁目が0の場合
            dp1[i+1][j] = dp1[i][j] # 真上からスライド
        else: # i+1桁目が1~9の場合
            if j < keta:
                dp1[i+1][j+1] = dp1[i][j] # 左上からスライド
        
        # ヨユーなやつ(dp0)の処理
        if n[i] == '0': # i+1桁目が0の場合
            # i桁目がヨユーな状態ではi+1桁目には何でも入れられる
            dp0[i+1][j] += dp0[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp0[i][j] * 9 # i+1桁目に1~9を入れた場合
            # i桁目までギリだったときの、i+1桁目のヨユーなやつのカウント
                # 何もない(ギリである0しか入れられないため)
        else: # i+1桁目が1~9の場合
            # i桁目がヨユーな状態ではi+1桁目には何でも入れられる
            dp0[i+1][j] += dp0[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp0[i][j] * 9 # i+1桁目に1~9を入れた場合
            # i桁目までギリだったときの、i+1桁目のヨユーなやつのカウント
            dp0[i+1][j] += dp1[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp1[i][j] * (ord(n[i])-ord('0')-1) # i+1桁目にrange(1, n[i])を入れた場合

print(dp0[keta][k] + dp1[keta][k])
Problem p02851 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] % k

if k == 1:
    print(0)
    exit()

ruiseki = [0]
for i in range(n):
    ruiseki.append((a[i]+ruiseki[-1])%k)

mini = 0
dic = {}
ans = 0
for j in range(1, n+1):
    if j-k+1 > mini:
        dic[(ruiseki[mini]-mini)%k] -= 1
        mini += 1
    if (ruiseki[j-1]-(j-1))%k in dic:
        dic[(ruiseki[j-1]-(j-1))%k] += 1
    else:
        dic[(ruiseki[j-1]-(j-1))%k] = 1
    if (ruiseki[j]-j)%k in dic:
        ans += dic[(ruiseki[j]-j)%k]
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] % k

ruiseki = [0]
for i in range(n):
    ruiseki.append((a[i]+ruiseki[-1])%k)

mini = 0
dic = {}
ans = 0
for j in range(1, n+1):
    if j-k+1 > mini:
        dic[(ruiseki[mini]-mini)%k] -= 1
        mini += 1
    if (ruiseki[j-1]-(j-1))%k in dic:
        dic[(ruiseki[j-1]-(j-1))%k] += 1
    else:
        dic[(ruiseki[j-1]-(j-1))%k] = 1
    if (ruiseki[j]-j)%k in dic:
        ans += dic[(ruiseki[j]-j)%k]
print(ans)
Problem p02863 (python)

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

lst.sort(key=lambda x: x[0])
a, b = [], []
for i in range(n):
    lsti = lst[i]
    a.append(lsti[0])
    b.append(lsti[1])

# DPテーブルの作成
dp = [[-1 for i in range(t)] for j in range(n+1)]
for i in range(t):
    dp[0][i] = 0

# DPテーブルの更新
for i in range(n):
    for j in range(t):
        if j >= a[i]:
            dp[i+1][j] = max(dp[i][j-a[i]]+b[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

# 答え(最大となる合計価値)
kouho = []
for i in range(n):
    kouho.append(dp[i][t-1]+b[i])
kouho.append(dp[n][t-1])
print(max(kouho))

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

class Item:

    def __init__(self, value, weight):
        self.value = value
        self.weight = weight
        self.density = value / weight

    def __str__(self):
        return f'weight = {self.weight}, value = {self.value}'


class Knapsack:

    def __init__(self, weight_limit):
        self.weight_limit = weight_limit
        self.weight = 0
        self.value = 0
        self.items = []

    def add(self, item):
        if self.weight + item.weight <= self.weight_limit:
            self.weight += item.weight
            self.value += item.value
            self.items.append(item)

    def show(self):
        return self.value


def buildItems():
    lst = []
    weights = []
    values = []
    for i in range(n):
        lsti = list(map(int, input().split()))
        lst.append(lsti)
    lst.sort(key= lambda x: x[1])
    saidai = lst.pop()[1]
    for i in range(n-1):
        weights.append(lst[i][0])
        values.append(lst[i][0])
    return [Item(*params) for params in zip(values, weights)], saidai


def testGreedys(weight_limit=t-1):
    def packing(greedy):
        knapsack = Knapsack(weight_limit)
        for item in sorted(items, key=greedy, reverse=True):
            knapsack.add(item)
        return knapsack.show()

    items, saidai = buildItems()
    ans1 = packing(lambda item: item.value)    # 高価値優先
    ans2 = packing(lambda item: -item.weight)  # 軽量優先
    ans3 = packing(lambda item: item.density)  # 高密度優先
    print(max(ans1, ans2, ans3)+saidai)

if __name__ == '__main__':
    testGreedys()
Problem p02912 (python)

Fixed submission:
import heapq
import numpy as np

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

a.sort()
a = np.array(a)
a = -1 * a
a = list(a)
heapq.heapify(a)

for i in range(m):
    temp = heapq.heappop(a)
    temp = int(temp/2)
    heapq.heappush(a, temp)

print(-1 * sum(a))

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

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

a.sort()

a = deque(a)

for i in range(m):
    saidai = a.pop()
    sounyu = saidai // 2
    bisect.insort(a, sounyu)

print(sum(a))
Problem p02948 (python)

Fixed submission:
import heapq

n, m = map(int, input().split())
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])

lst.sort(key=lambda x:(x[1]), reverse=True)
lst.sort(key=lambda x:(x[0]), reverse=False)

ans = 0
ind = 0
kouho = []
for i in range(1, m+1):
    tugi = True
    while tugi:
        if ind >= n:
            break
        if lst[ind][0] == i:
            heapq.heappush(kouho, -lst[ind][1])
            ind += 1
        else:
            tugi = False
    try:
        ans += heapq.heappop(kouho) * (-1)
    except:
        IndexError

print(ans)

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

n, m = map(int, input().split())
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])

lst.sort(key=lambda x:(x[1]), reverse=True)
lst.sort(key=lambda x:(x[0]), reverse=False)

ans = 0
ind = 0
kouho = deque([])
for i in range(1, m+1):
    tugi = True
    while tugi:
        if ind >= n:
            break
        if lst[ind][0] == i:
            bisect.insort(kouho, lst[ind][1])
            ind += 1
        else:
            tugi = False
    if kouho != deque([]):
        ans += kouho.pop()

print(ans)

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

n, m = map(int, input().split())
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])

lst.sort(key=lambda x:(x[1]), reverse=True)
lst.sort(key=lambda x:(x[0]), reverse=False)

ans = 0
ind = 0
kouho = deque([])
for i in range(1, m+1):
    tugi = True
    while tugi:
        if ind >= n:
            break
        if lst[ind][0] == i:
            bisect.insort(kouho, lst[ind][1])
            ind += 1
        else:
            tugi = False
    if kouho != []:
        ans += kouho.pop()

print(ans)