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

Fixed submission:
from itertools import combinations
import numpy as np
        #買う本
N, M, X = map(int, input().split())
items = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out = 10**18
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            out = min(out, tmp[0])

if out == 10**18:
  print(-1)
else:
  print(out)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
import numpy as np
        #買う本
N, M, X = map(int, input().split())
items = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
out = 10**18
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = items[book_buy] 
        tmp             = np.sum(understand_now, axis=0)
        if np.all(tmp[1:] >= X):
            out = min(out, tmp[0])
            flag =True
if flag ==True:
    print(out)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
# 初期入力
from itertools import permutations
import math
import numpy as np 
import sys
input = sys.stdin.readline
N,M,X = (int(x) for x in input().split())
C = [list(map(int, input().split())) for i in range(N)]
all_per =[i for i in range(N)]

price_list =[]
price_sum=0
N_fact = math.factorial(N)
k=0
for t in permutations(all_per): #参考書を買う順番を全列挙
    understanding =np.zeros((N ,M),dtype=int)
    understanding_method =np.zeros(M,dtype=int)
    price_sum=0
    k=0
    for i in t:
        price_sum           +=C[i][0]
        understanding[k]    =C[i][1:]
        understanding_method = np.sum(understanding, axis=0)
        k +=1
        if np.all(X <= understanding_method ): #アルゴリズム理解度が全て目標値X以上か
            price_list.append(price_sum)
            break
print(min(price_list))

Buggy submission (verdict: Runtime Error):
# 初期入力
from itertools import permutations
import math
import numpy as np 
import sys
input = sys.stdin.readline
N,M,X = (int(x) for x in input().split())
C = [list(map(int, input().split())) for i in range(N)]
all_per =[i for i in range(N)]

price_list =[]
price_sum=0
N_fact = math.factorial(N)
k=0
for t in permutations(all_per): #参考書を買う順番を全列挙
    understanding =np.zeros((N ,M),dtype=int)
    understanding_method =np.zeros(M,dtype=int)
    price_sum=0
    k=0
    for i in t:
        price_sum           +=C[i][0]
        understanding[k]    =C[i][1:]
        understanding_method = np.sum(understanding, axis=0)
        k +=1
        if np.all(X <= understanding_method ): #アルゴリズム理解度が全て目標値X以上か
            price_list.append(price_sum)
            break
print(min(price_list))
Problem p02684 (python)

Fixed submission:
# 初期入力
from collections import Counter
from copy import deepcopy
import sys
input = sys.stdin.readline
N,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
connection ={}
for i,v in enumerate(A):
    connection[i+1] =v 

#巡回してるか
passed=[1]
nex =connection[1]
lap =[]
lap_num =0
pass_set =set(passed)
for i in range(1,N+1):
    passed.append(nex)
    if nex not in pass_set:
        pass_set.add(nex)
        nex =connection[nex]
    else:
        #lap =deepcopy(passed)
        break
#巡回している部分の町の数    
indx_s =passed.index(nex) +1
indx_f =len(passed)
lap_num =indx_f -indx_s

if indx_f < K:
    mod =(K -indx_s) % lap_num
    ans =passed[indx_s +mod]
else:
    ans =passed[K]
print(ans)

Buggy submission (verdict: Runtime Error):
# 初期入力
from collections import Counter
from copy import deepcopy
import sys
input = sys.stdin.readline
N,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
connection ={}
for i,v in enumerate(A):
    connection[i+1] =v 

#巡回してるか
passed=[1]
nex =connection[1]
lap =[]
lap_num =0
pass_set =set()
for i in range(1,N+1):
    passed.append(nex)
    if nex not in pass_set:
        pass_set.add(nex)
        nex =connection[nex]
    else:
        #lap =deepcopy(passed)
        break
#巡回している部分の町の数    
indx_s =passed.index(nex) +1
indx_f =len(passed)
lap_num =indx_f -indx_s

if indx_f < K:
    mod =(K -indx_s) % lap_num
    ans =passed[indx_s +mod]
else:
    ans =passed[K]
print(ans)

Buggy submission (verdict: Runtime Error):
# 初期入力
from collections import Counter
from copy import deepcopy
import sys
input = sys.stdin.readline
N,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
connection ={}
for i,v in enumerate(A):
    connection[i+1] =v 

#巡回してるか
passed=[1]
nex =connection[1]
lap =[]
for i in range(1,N+1):
    passed.append(nex)
    c=Counter(passed)
    if 2  not in c.values():
        nex =connection[nex]
    else:
        lap =deepcopy(passed)
        indx_s =passed.index(nex) +1
        indx_f =len(lap)
        lap_num =indx_f -indx_s
        break

mod =(K -indx_s)//lap_num
ans =passed[indx_s +mod]
print(ans)
Problem p02690 (python)

Fixed submission:
# 初期入力
import sys
import math
#input = sys.stdin.readline
X = int(input())
limit =10**5
a=0
b=0
for b in range(-1*limit ,limit):
    a5 =X+pow(b,5)
    if 0 <= a5: 
        a=math.pow(a5,0.2)
        a_int =int(a)
        dif =a_int**5 -b**5 -X
        if abs(dif)<10**(-5):
            break
    else:
        continue
print(a_int,b)

Buggy submission (verdict: Runtime Error):
X = int(input())
y =120
a ={i**5 for i in range(-y,y)}
ans_a =0
ans_b =0
for b in range(-y,y):
    if X +b**5 in a:
        #ans_a =int( (X +b**5 +1)**0.2 )
        ans_a =int( (X +b**5 )**0.2 )
        ans_b =b
        break
print(ans_a,ans_b)

Buggy submission (verdict: Runtime Error):
X = int(input())
y =2*10**2
a ={i**5 for i in range(-y,y)}
ans_a =0
ans_b =0
for b in range(-y,y):
    if X +b**5 in a:
        #ans_a =int( (X +b**5 +1)**0.2 )
        ans_a =int( (X +b**5 )**0.2 )
        ans_b =b
        break
print(ans_a,ans_b)

Buggy submission (verdict: Runtime Error):
X = int(input())
a ={i**5 for i in range(-10**5,10**5)}
ans_a =0
ans_b =0
for b in range(-10**5,10**5):
    if X +b**5 in a:
        #ans_a =int( (X +b**5 +1)**0.2 )
        ans_a =int( (X +b**5 )**0.2 )
        ans_b =b
        break
print(ans_a,ans_b)
Problem p02719 (python)

Fixed submission:
# 初期入力
N,K = (int(x) for x in input().split(" "))

#
zeroika = 0
if K <N:
    zeroika = N//K
else:
    zeroika = 1
N1 =abs(N-K*zeroika) #N1がマイナスになって初めてABS、そこまではKの倍数単調に減る
while N1<N:
    N =N1
    N1 =abs(N-K)
    #print(N1,end=" ")
print(N)

Buggy submission (verdict: Runtime Error):
# 初期入力
N,K = (int(x) for x in input().split(" "))

#
zeroika = N//K
N1 =abs(N-K*zeroika) #N1がマイナスになって初めてABS、そこまではKの倍数単調に減る
    N =N1
    N1 =abs(N-K)
    #print(N1,end=" ")
print(N)
Problem p02727 (python)

Fixed submission:
#heapq p,qの最小値側にrの最大値入れていく。
import heapq 

#初期入力
X,Y,A,B,C = (int(x) for x in input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))


# ソート⇒無色と比較
p.sort()
q.sort()
r.sort(reverse=True)

ans_sum =sum(p[-X:]) + sum(q[-Y:])
p_hq = p[-X:]
q_hq = q[-Y:]
heapq.heapify(p_hq)
heapq.heapify(q_hq)
p_change =heapq.heappop(p_hq)
q_change =heapq.heappop(q_hq)
count_p =0
count_q =0
for i in r: #rは大きい順
    if p_change <= q_change and p_change < i:
        if  count_p < X:
            heapq.heappush(p_hq,i)
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =heapq.heappop(p_hq)
    elif p_change > q_change and q_change < i:
        if  count_q < Y:
            heapq.heappush(q_hq,i)
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =heapq.heappop(q_hq)
print(ans_sum)

Buggy submission (verdict: Runtime Error):
from collections import deque 
#from copy import copy
#初期入力
X,Y,A,B,C = (int(x) for x in input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))


# ソート⇒無色と比較
p.sort()
q.sort()
r.sort()

p_dq =deque(p[A-X:])
q_dq =deque(q[B-Y:])
ans_sum =sum(p[A-X:]) + sum(q[B-Y:])
p_change =p_dq.popleft()
q_change =q_dq.popleft()
count_p =0
count_q =0
for i in r:
    if p_change < q_change:
        if i > p_change and count_p < X:
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =p_dq.popleft()

    elif p_change > q_change and count_q < Y:
        if i > q_change:
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =q_dq.popleft()
print(ans_sum)
Problem p02755 (python)

Fixed submission:
A,B =map(int,input().split())
 
# 元の価格ｘ,8%  y、１０％
import math
x = math.ceil(A/0.08)
x_1 = math.ceil((A+1)/0.08 )
y = math.ceil(B/0.1)
y_1 = math.ceil( (B+1)/0.1 )

x_2 = {i for i in range(int(x),int(x_1) ) }
y_2 = {i for i in range(int(y),int(y_1) ) }
moto_nedan = x_2 & y_2
if len(moto_nedan) == 0:
    print("-1")
else:
    print(min(moto_nedan))

Buggy submission (verdict: Runtime Error):
A,B =map(int,input().split())
 
# 元の価格ｘ,8%  y、１０％
x = A/0.08
x_1 =(A+1)/0.08
y = B/0.1
y_1 = (B+1)/0.1

x_2 = {i for i in range(int(x),int(x_1) if i<=100)}
y_2 = {i for i in range(int(y),int(y_1) if i<=100)}
moto_nedan = x_2 & y_2
if len(moto_nedan) == 0:
    print("-1")
else:
    print(min(moto_nedan))
Problem p02802 (python)

Fixed submission:
# 初期入力
N,M = (int(x) for x in input().split(" "))
S = []

#　問題種類をキー、ac,waを値の辞書
mondai_acwa ={i:list() for i in range(1,N+1) }
q_id =0
result =""
for i in range(M):
    q_id_str,result = (x for x in input().split())
    mondai_acwa[int(q_id_str)].append(result)

# ACが初めてでた時のindex＝その問題のWAの数（各問題）
ac_sum=0
wa_sum=0

for i,v_wa in mondai_acwa.items():
    if 0 < len(v_wa):
        if "AC" in v_wa: #ACがないときはWAも数えない
            ac_i =v_wa.index("AC") 
            ac_sum +=1
            wa_sum += ac_i
print(ac_sum,wa_sum)

Buggy submission (verdict: Runtime Error):
# 初期入力
N,M = (int(x) for x in input().split(" "))
S = []

#　問題種類をキー、ac,waを値の辞書
mondai_acwa ={i:list() for i in range(1,N+1) }
q_id =0
result =""
for i in range(M):
    q_id_str,result = (x for x in input().split())
    mondai_acwa[int(q_id_str)].append(result)

# ACのindexを検索（各問題）
count_wa=0
ac_index =[]
ac_sum=0
for i,v_wa in mondai_acwa.items():
    if 0 < len(v_wa):
        ac_i =v_wa.index("AC")
        ac_index.append(ac_i)
        ac_sum +=1
print(ac_sum,sum(ac_index))
Problem p02814 (python)

Fixed submission:

# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
lcm         =lcm_list(A)
han_lcm     =lcm//2
han_lcm_num =M//han_lcm
han_lcm_num =(han_lcm_num +1)//2 #偶数を除く

#半公倍数がA自身の中にある時は✖
if han_lcm in A:
    han_lcm_num =0
#半公倍数がaiで割り切れるときは✖
for a in A:
    if han_lcm % a ==0:
        han_lcm_num =0
print(han_lcm_num)

Buggy submission (verdict: Runtime Error):
#素因数分解にsympy を使ってみる（素数の列挙）
import sympy
import math
def soinsu_bunkai(m,sosu_list):
    pf={}
    for i in sosu_list:
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf

#初期入力
N,M= (int(x) for x in input().split())
A= list(map(int, input().split()))

#ai<10**9 だから
ai_root =int(math.sqrt(10**9)) +1
sosu_list = list(sympy.primerange(2, ai_root))


y ={}
for i in A:
    x_dic =soinsu_bunkai(i,sosu_list) 
    for k,v in x_dic.items():
        if k not in y:
            y[k] = v
            if y[k] < v:
                y[k] = v
#半＿最小公倍数
han_saisyo_kobaisu =1
for i,v in y.items():
    han_saisyo_kobaisu *= i*v
han_saisyo_kobaisu //=2

#半公倍数の数( Mの中に半最小公倍数の数→偶数を削除のためさらに2で割る)
han_kobaisu_num =( M // han_saisyo_kobaisu +1 )//2
print(han_kobaisu_num)
Problem p02837 (python)

Fixed submission:
from itertools import product
#初期入力
N = int(input())
testimony ={j:[-1 for i in range(N)] for j in range(1,N+1)}
A=[]
for i in range(1,N+1):
    a = int(input())
    A.append(a)
    for j in range(a):
        x,y = list(map(int, input().split()))
        testimony[i][x-1] =y

#各人が正直か不親切かを仮定する。仮定(Assumption)が矛盾するか、判定を全探索

assumption_correct =[]
for assumption in product([1,0], repeat=N):
    count_2=0
    for i in range(N):      #証言する人        
        if assumption[i] ==1:
            count =0 
            for j in range(N):  #証言受けた人 
                         
                if testimony[i+1][j] ==assumption[j]:
                    count +=1
            if count == A[i]:
                count_2 +=1
    if count_2 ==sum(assumption):
        assumption_correct.append(sum(assumption))
print(max(assumption_correct))

Buggy submission (verdict: Runtime Error):
# 初期入力
N = int(input())
A = list(map(int, input().split()))


x = [  A[i]^A[j] for i in range(N-1) for j in range(i+1,N) ]
kotae =sum(x) % (10**9 +7)
print(kotae)
Problem p02900 (python)

Fixed submission:
# 初期入力
A,B = (int(x) for x in input().split())

#素因数分解
def soinsu_bunkai(m):
    pf={}

    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf
# 入力値A,Bを素因数分解
A_soinsu =soinsu_bunkai(A)
B_soinsu =soinsu_bunkai(B)

#共通の素数を探す
kyotu_soinsu ={}
a_sosu ={i for i in A_soinsu.keys()}
b_sosu ={i for i in B_soinsu.keys()}
kotae = a_sosu & b_sosu

print(len(kotae)+1) # 素数「１」を足す

Buggy submission (verdict: Runtime Error):
#公約数を求める
def kouyakusu(x1,x2):
    cf=[1]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

#約数 #商と割る数をタプルで返す
def yakusu_tapulu(n):# 商と割る数 両方を返す
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            syou,amari =divmod(n,i)
            divisors.append((syou,i))
    return divisors

#公約数の約数をタプルで作る。互いに素だから要素数は「１」
x_yakusu =[]
x_kouyaku = kouyakusu(A,B) #公約数のリスト
x_yakusu =[yakusu_tapulu(i) for i in x_kouyaku  if len(yakusu_tapulu(i)) ==1]
print(len(x_yakusu))
Problem p02922 (python)

Fixed submission:
# 初期入力
A,B = (int(x) for x in input().split())

#
import math
tapp_num = math.ceil( (B-1)//(A-1) )
#print(tapp_num)


sasikomiguti_misiyou=0
if B==1:
    print(0)
elif B<=A:
    print(1)
else:        
    sasikomiguti_misiyou =(tapp_num -1)*(A) +A
    if B <= sasikomiguti_misiyou-1:
        print(tapp_num)
    else:
        print(tapp_num +1)

Buggy submission (verdict: Runtime Error):
# 初期入力
A,B = (int(x) for x in input().split())

#
import math
tapp_num = (B//(A-1))
sasikomiguti_misiyou=0
if B<=A:
    print(1)
else:        
    sasikomiguti_misiyou =A +(tapp_num -1)*(A-1)
    if B <= sasikomiguti_misiyou:
        print(tapp_num)
    else:
Problem p02983 (python)

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline
L,R = (int(x) for x in input().split())

mod_L =L %2019
mod_R =R %2019
ans =0
xx=[]
if 2018 <= R -L:
    ans =0
elif mod_R < mod_L:
    ans =0
elif mod_L==0 :
    ans =0
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            x =i*j %2019
            xx.append(x)
    ans =min(xx)
print(ans)

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
L,R = (int(x) for x in input().split())

mod_L =L %2019
mod_R =R %2019
ans =0
if 2018 <= R -L:
    ans =0
elif mod_R < mod_L:
    ans =0
elif:
    mod_L==0 :
    ans =0
else:
    ans =mod_L *(mod_L +1)
print(ans)
Problem p03061 (python)

Fixed submission:
"""参考
@ct158603292321　　2019年05月03日に更新
qiita AtCoder ABC125 解説
https://qiita.com/ct158603292321/items/4cddafa5c2500a657ccf
"""
#約数
def make_divisors(n): #約数をリストで返す
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_np =np.array(A)

#list(A)の内、任意で2つ選び約数の和集合（公約数ではない）
div_A_2 =make_divisors(A[0]) + make_divisors(A[1])
ans =[]
for i in div_A_2:
    aa= np.count_nonzero(A_np %i ==0) #iで割り切れる要素を数える
    if aa >=N-1:
        ans.append(i)
print(max(ans))

Buggy submission (verdict: Runtime Error):
"""半分くらいWA"""
# 最大公約数(mathは3.5以降) 
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return  fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm_list(numbers):
    return reduce(lcm_base, numbers)
def lcm_fukusu(*numbers):
    return reduce(lcm_base, numbers)

# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))

#Aの隣り合う要素の最大公約数
ans =[]
if N==2:
    ans =max(A)
    print(ans)
    exit()
else:
    for i in range(N-1):
        ans.append(lcm_fukusu(A[i],A[i+1]))
    ans.append(lcm_fukusu(A[0],A[-1])) #len(A) ==3の時必要
    ans =list(set(ans))
    ans.sort()

if len(ans) ==1:
    print(ans[0])
elif len(ans) ==2:
    print(ans[1])
else:
    ans1=[]
    for i in ans[1:3]:
        aa= np.count_nonzero(np.array(A) %i ==0) #iで割り切れる要素を数える
        if aa >=N-1:
            ans1.append(i)
    ans =max(ans1)
    print(ans)
Problem p03086 (python)

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline
S =input().strip()

#ACGTが連続しているか判定
count =0
count_list=[0]
for i in S:
    if i in "ACGT":
        count +=1
        count_list.append(count)
    else:
        count =0
print(max(count_list))

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
S =input().strip()

#ACGTが連続しているか判定
count =0
count_list=[]
for i in S:
    if i in "ACGT":
        count +=1
    else:
        count_list.append(count)
        count =0
print(max(count_list))
Problem p03111 (python)

Fixed submission:
#全探索をA,B,C一度で分けた
# RE 1   ac 19

# 初期入力
import copy
from itertools import combinations
import sys
input = sys.stdin.readline  #文字列では使わない
N,A,B,C = (int(i) for i in input().split())
l =[0]*N
for i in range(N):
    l[i] = int(input())

# A,B,Cどの竹を選ぶかcombination
mp=[]
for na in range(1,N-1):
    for ja in combinations(l,na):

        l_b =copy.copy(l)
        for i2 in ja:
            if i2 in l_b:
                l_b.remove(i2)
        for nb in range(1,N):
            for jb in combinations(l_b ,nb):

                l_c =copy.copy(l_b)
                for i3 in jb:
                    if i3 in l_c:
                        l_c.remove(i3)
                for nc in range(1,N+1):
                    for jc in combinations(l_c ,nc):
                        
                        # MPの消費量＝（求める長さー今回選んだ竹の長さ合計）+10*（合成魔法の回数)
                        AA =abs(A-sum(ja)) +10*(na-1)
                        BB =abs(B-sum(jb)) +10*(nb-1)
                        CC =abs(C-sum(jc)) +10*(nc-1)
                        mp.append(AA +BB +CC)


print(min(mp))

Buggy submission (verdict: Runtime Error):
#全探索をA,B,C一度で分けた
# TLE   ac 

# 初期入力
import heapq
from itertools import combinations
import sys
input = sys.stdin.readline  #文字列では使わない
N,A,B,C = (int(i) for i in input().split())
l =[0]*N
for i in range(N):
    l[i] = int(input())

# A,B,Cどの竹を選ぶかcombination
mp=[]
for na in range(1,N-1):
    for ja in combinations(l,na):

        l_b =list(set(l) -set(ja))
        for nb in range(1,N):
            for jb in combinations(l_b ,nb):

                l_c =list(set(l_b) -set(jb) )
                for nc in range(1,N+1):
                    for jc in combinations(l_c ,nc):
                        
                        # MPの消費量＝（求める長さー今回選んだ竹の長さ合計）+10*（合成魔法の回数)
                        AA =abs(A-sum(ja)) +10*(na-1)
                        BB =abs(B-sum(jb)) +10*(nb-1)
                        CC =abs(C-sum(jc)) +10*(nc-1)
                        mp.append(AA +BB +CC)


print(min(mp))
Problem p03162 (python)

Fixed submission:
"""
参考 Xenous
if sortを少なくし、maxで処理
""" 
# 初期入力
N = int(input())
a=[]
b=[]
c=[]
for i in range(N):
    a1,b1,c1 = (int(x) for x in input().split())
    
    a.append(a1)
    b.append(b1)
    c.append(c1)

dp_A = [0]*(N) ;dp_A[0] =a[0] 
dp_B = [0]*(N) ;dp_B[0] =b[0] 
dp_C = [0]*(N) ;dp_C[0] =c[0] 


#
for i in range(0,N-1):
    dp_A[i+1] = max(dp_B[i] + a[i+1] , dp_C[i] + a[i+1])
    dp_B[i+1] = max(dp_A[i] + b[i+1] , dp_C[i] + b[i+1])
    dp_C[i+1] = max(dp_A[i] + c[i+1] , dp_B[i] + c[i+1])
print(max (dp_A[N-1],dp_B[N-1],dp_C[N-1]) )

Buggy submission (verdict: Runtime Error):
# 初期入力
N = int(input())
import numpy as np
koufuku = np.array( [list(map(int, input().split())) for i in range(N)] ,dtype=int)
dp_ko = [0]*(N+1) 

dp_ko[0] = max( koufuku[0,:] ) , np.argmax(koufuku[0,:]) 

#
for i in range(N-1):
    
    tomorr_i = np.argmax(koufuku[i+1,:]) # 翌日の最大値のindex
    tomorr_ko = np.max(koufuku[i+1,:] ) # 翌日の最大値
    if tomorr_i != dp_ko[i][1]: # 翌日最大値のindex not 当日の保存していたindex(当日の最大値とは限らない)
        dp_ko[i+1] = dp_ko[i][0] + tomorr_ko , tomorr_i # 累積＋翌日の最大値 , 翌日のindex
    else:
        tomorr_no2 = np.sort( koufuku[i+1,:] )[-2] # 翌日2番目に大きい値
        tomorr_no2_i = koufuku[i+1,:].argsort()[-2] # 翌日2番目に大きい値のindex
        dp_ko[i+1] = dp_ko[i][0] + tomorr_no2 , tomorr_no2_i 

print(dp_ko[N-1][0])
Problem p03240 (python)

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
h_list =[0]*N

for i in range(N):
    x,y,h= (int(i) for i in input().split())
    xyh[i] =x,y,h
    h_list[i] =h

from bisect import bisect_right
xyh.sort(key =lambda x:x[2])
h_list.sort()
ind =bisect_right(h_list,0)
from collections import defaultdict
H =defaultdict(set)

for x,y,h in xyh[ind:]:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
if len(xyh[ind:]) ==1:
    print(*xyh[-1])
else:
    for k,v in H.items():
    
        if len(v)==1:
            vv =v.pop()
            if 0 <= vv :
                print(*k,vv)
            elif vv <0:
                print(*k,0)

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
xyh =[0]*N
for i in range(N):
    xyh[i] = tuple(int(i) for i in input().split())

from collections import defaultdict
H =defaultdict(set)
for x,y,h in xyh:
    for cx in range(101):
        for cy in range(101):
            xx =x -cx
            yy =y -cy
            if cx <=x and cy <=y:
                H[(cx,cy)].add( (h +xx +yy) )
            elif cx >x and cy <=y:
                 H[(cx,cy)].add( (h -xx +yy) )
            elif cx <=x and cy >y:
                 H[(cx,cy)].add( (h +xx -yy) )
            elif cx >x and cy >y:
                 H[(cx,cy)].add( (h -xx -yy) )
            
#print(xyh)
#H.sort(key =lambda x:x[1])
for k,v in H.items():
    if len(v)==1:
        if 0 <= v[0] <=10**9:
            print(*k,*v)
        elif v[0] <0:
            print(*k,0)
        elif 10**9 <v[0]:
            print(*k,10**9)