Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import factorial
def kumiawase_num(n, r): # 組み合わせ n「C」r
    if  n<r or n==0:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

# 初期入力
X,Y = (int(x) for x in input().split())

#NUMPYで連立方程式を解く
from numpy.linalg import solve
left = [[2,1],
        [1,2]]
right = [X,Y]
x,y =solve(left, right)
if x == int(x) and y ==int(y):
    a,b =int(x),int(y)
    if b<a:
        a,b=b,a
else:
    a=b=0
# (1,2)と(2,1)の数がわかったので、その組み合わせ
kotae = kumiawase_num(a+b,a) 
syou,amari =divmod(kotae,10**9 +7)
print(amari)

Fixed submission:
def cmb(n, r, p): # 組み合わせの総数 109+7 で割ったあまりを求める Satoooh Blog 2020/02/27 4分 
    N = 10 ** 6  # N は必要分だけ用意する
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p



# 初期入力
X,Y = (int(x) for x in input().split())

# X+Y が3の倍数、かつY=2XとY=X/2の間にある必要あり
kotae =0
if (X+Y) %3 !=0 or X*2< Y or Y*2 <X :
    a =b =0
else: #a(1,2) + b(2,1)=(X,Y)  の連立法手式を解く　X,Yは入力値
    b=(2*X -Y)//3
    a=X-2*b

    # (1,2)と(2,1)の数がわかったので、その組み合わせ
    if b<a:
        a,b = b,a
    #kotae = kumiawase_num(a+b,a) 
    mod =10**9 +7
    kotae = cmb(a+b,a,mod ) 
    
print(kotae)
Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N = int(input())
S =input()
S_list =[i for i in S]

#
keizoku =True
count_list =[0,1]
for i in range(N):
    for j in range(len(S)-1):
        if S[j] == S[j+1]:
            del S_list[j]
            S="".join(S_list)
            break
print(len(S))

Fixed submission:
# 初期入力
N = int(input())
S =input()
S_list =[i for i in S]

#
S_2 =[]
S_2.append(S[0])
for i in range(N):
    for j in range(len(S)-1):
        if S[j] != S[j+1]:
            S_2.append(S[j+1])
    S="".join(S_2)
    break
print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
import numpy as np
N,K,Q = (int(x) for x in input().split())
A = [int(input()) for i in range(Q)] 


#
point_i =np.full(N,K) #要素数、N   初期値,K

for i in A:
    point_i = point_i -1
    point_i[i-1] +=1

for i in point_i:
    if 0 < i:
        print("Yes")
    else:
        print("No")

Fixed submission:
# 初期入力
import numpy as np
N,K,Q = (int(x) for x in input().split())
A = [int(input()) for i in range(Q)] 


#
point_i =np.full(N,K) #参加者ごとのポイント　要素数、N   初期値,K

for i in A: #正解した人のポイント加算する
    #point_i = point_i -1
    point_i[i-1] +=1
#print(point_i)

point_i -= Q #全員、全問題数分のポイント減算

for i in point_i:
    if 0 < i:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

#
a_waribiki = np.zeros((N,M+1),dtype=np.int64)
a_waribiki[:,0] =A # 割引しない場合を代入

# 各商品を１からM回割引券使った場合の金額
for i in range(1,M+1): 
    a_waribiki[:,i] =a_waribiki[:,i-1] //2

# 各商品に何枚割引券使うか
from itertools import combinations
n_waribiki = [i for i in range(M+N-1)]
x_list_2 =[]
if N-1 ==0:
    x_list_2.append([M])
else:
    for t in combinations(n_waribiki, N-1):
        t_list = list(t)
        t_list.append(M+N-1)
        x_list=[]
        for i in range(1,len(t_list)):
            x= t_list[i] -t_list[i-1]-1
            x_list.append(x)
        x_list.append(t[0])
        x_list_2.append(x_list)
        #print(t_list)
        #print(t,end=" ")

#[割引券を何枚使うか」を利用し、金額計算
x_np = np.array(x_list_2)
kotae = []
for i in x_np:
    a_sum =0
    for j,v in enumerate(i):
        a_sum += a_waribiki[j,v]
    kotae.append(a_sum)
print(min(kotae))

Fixed submission:
# 初期入力
N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
A =list(map(lambda x:x*(-1),A))     #最大値を取り出すため―１を掛ける
import heapq  # heapqライブラリのimport
heapq.heapify(A)  #         リストを優先度付きキューへ
m=0
for i in range(M):
    a=heapq.heappop(A)  #       最大値の取り出し
    a //=-2             # 負の値を2で割り切り捨てると、絶対値が大きくなる。
    heapq.heappush(A, -a) #正の値で2で割り、戻すとき負にする
    #print(A)

A_sum =sum(A)
A_sum *=(-1)
print(A_sum)

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

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

#
a_waribiki = np.zeros((N,M+1),dtype=np.int64)
a_waribiki[:,0] =A # 割引しない場合を代入

# 各商品を１からM回割引券使った場合の金額
for i in range(1,M+1): 
    a_waribiki[:,i] =a_waribiki[:,i-1] //2

# 各商品に何枚割引券使うか
from itertools import combinations
n_waribiki = [i for i in range(M+N-1)]
x_list_2 =[]
for t in combinations(n_waribiki, N-1):
    t_list = list(t)
    t_list.append(M+N-1)
    x_list=[]
    for i in range(1,len(t_list)):
        x= t_list[i] -t_list[i-1]-1
        x_list.append(x)
    x_list.append(t[0])
    x_list_2.append(x_list)
    #print(t_list)
    #print(t,end=" ")

#[割引券を何枚使うか」を利用し、金額計算
x_np = np.array(x_list_2)
kotae = []
for i in x_np:
    a_sum =0
    for j,v in enumerate(i):
        a_sum += a_waribiki[j,v]
    kotae.append(a_sum)
print(min(kotae))

Fixed submission:
# 初期入力
N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
A =list(map(lambda x:x*(-1),A))     #最大値を取り出すため―１を掛ける
import heapq  # heapqライブラリのimport
heapq.heapify(A)  #         リストを優先度付きキューへ
m=0
for i in range(M):
    a=heapq.heappop(A)  #       最大値の取り出し
    a //=-2             # 負の値を2で割り切り捨てると、絶対値が大きくなる。
    heapq.heappush(A, -a) #正の値で2で割り、戻すとき負にする
    #print(A)

A_sum =sum(A)
A_sum *=(-1)
print(A_sum)
Buggy python 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:

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 python submission (verdict: Time Limit Exceeded):
# 初期入力
N = int(input())

N_list =[i for i in range(1,N+1)]
ans =sum(N_list) -N
print(ans)

Fixed submission:
# 初期入力
N = int(input())

#N_list =[i for i in range(1,N+1)]
N_list_sum =N*(N+1)//2
ans =N_list_sum -N
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

# 初期入力
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
H = list(map(int, input().split()))

#
differ =0
ans="Yes"
max_h   =max(H)
max_index =H.index(max_h)
#最大値-1 と最大値の右側の最小値を比較,この時はfor不要
if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        print(ans)
        sys.exit()

dq    =deque(H)
before  =dq.popleft()
for i in range(N-1):
    after   =dq.popleft()
    differ    =after - before
    #differ = H[i+1] -H[i]
    if differ <-1:      #右側が小さのは１までOK
        ans ="No"
        break
    elif differ ==-1:
        if before -1 > min(dq) :
            ans ="No"
            break
        else:
            before = after
    else:
        before = after

print(ans)

Fixed submission:

# 初期入力
from collections import deque
import sys
#input = sys.stdin.readline
N = int(input())
H = list(map(int, input().split()))

#
differ =0
ans="Yes"
max_h   =max(H)
max_index =H.index(max_h)
#最大値-1 と最大値の右側の最小値を比較,この時はfor不要
if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        print(ans)
        sys.exit()

dq    =deque(H)
before  =dq.popleft()
for i in range(N-1):
    after   =dq.popleft()
    differ    =after - before
    #differ = H[i+1] -H[i]
    if differ <-1:      #右側が小さのは１までOK
        ans ="No"
        break
  
    else:
        before = after

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

#
differ =0
ans="Yes"
max_h=max(H)
max_index =H.index(max_h)
#最大値-1 と最大値の右側の最小値を比較,この時はfor不要
if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        #print(ans)
        exit

for i in range(N-1):

    differ = H[i+1] -H[i]
    if differ <-1:      #右側が小さのは１までOK
        ans ="No"
        break
    elif differ ==-1:
        if H[i]-1 > min(H[i:]) :
            ans ="No"
            break
print(ans)

Fixed submission:

# 初期入力
from collections import deque
import sys
#input = sys.stdin.readline
N = int(input())
H = list(map(int, input().split()))

#
differ =0
ans="Yes"
max_h   =max(H)
max_index =H.index(max_h)
#最大値-1 と最大値の右側の最小値を比較,この時はfor不要
if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        print(ans)
        sys.exit()

dq    =deque(H)
before  =dq.popleft()
for i in range(N-1):
    after   =dq.popleft()
    differ    =after - before
    #differ = H[i+1] -H[i]
    if differ <-1:      #右側が小さのは１までOK
        ans ="No"
        break
  
    else:
        before = after

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np 
import sys
input = sys.stdin.readline
N = int(input())
a =[0]+ list(map(int, input().split()))
a_np =np.array(a)
for i in range(N,0,-1):
    a_np[i] =np.sum(a_np[i::i]) %2

print(np.sum(a_np))
a_np =np.delete(a_np,0)
for i,v in enumerate(a_np):
    if v==1:
        print(i+1,end=" ")

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
a =[0]+ list(map(int, input().split()))
for i in range(N,0,-1):
    a[i] =sum(a[i::i]) %2
print(sum(a))
del a[0]
for i,v in enumerate(a):
    if v==1:
        print(i+1,end=" ")
Buggy python 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)

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 python submission (verdict: Runtime Error):
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = [[int(i)] for i in input().split()]
A_np =np.array(A)

#numpyで連立方程式を解く
mat_1 =np.zeros((N,N),dtype=int)
for i in range(N):
    mat_1[i,i]=1
    mat_1[i,(i+1)%N]=1 #余りをとらないと、i=N-1の時エラーになる
x =np.linalg.solve(mat_1,A_np)*2

#表示
for i in x:
    print(int(i[0]),end=" ")

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

mt_rain =[0]*N
mt_all =sum(A)
dam_even = sum(A[1::2]) #偶数番目のダムの増えた水
mt_rain[0] = mt_all - 2*dam_even #1番目の山の降水量

#2番目の山以降
for i in range(1,N):
    mt_rain[i] =2*A[i-1] -mt_rain[i-1]
print(*mt_rain)
Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N,M = (int(x) for x in input().split())
A = [int(input()) for i in range(M)]


#
mod_9 = 10**9 +7
dp =[0]*(N +1)
dp[0] = 1
if 1 not in A:
    dp[1] =1
for i in range(N-1):
    if i+2 in A:
        dp[i+2] = 0
    else:
        dp[i+2] = dp[i+1] + dp[i] 
        dp[i+2] %= mod_9
kotae =dp[N] # % mod_9
print(kotae )

Fixed submission:
# 初期入力
N,M = (int(x) for x in input().split())
A = set([int(input()) for i in range(M)])


#
mod_9 = 10**9 +7
dp =[0]*(N +1)
dp[0] = 1
if 1 not in A:
    dp[1] =1
for i in range(N-1):
    if i+2 in A:
        dp[i+2] = 0
    else:
        dp[i+2] = dp[i+1] + dp[i] 
        dp[i+2] %= mod_9
kotae =dp[N] # % mod_9
print(kotae )

Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N,M = (int(x) for x in input().split())
A = [int(input()) for i in range(M)]


#
mod_9 = 10**9 +7
dp =[0]*(N +1)
dp[0] = 1
if 1 not in A:
    dp[1] =1
for i in range(N-1):
    if i+2 not in A:
        dp[i+2] = dp[i+1] + dp[i] 
        dp[i+2] %= mod_9
kotae =dp[N] # % mod_9
print(kotae )

Fixed submission:
# 初期入力
N,M = (int(x) for x in input().split())
A = set([int(input()) for i in range(M)])


#
mod_9 = 10**9 +7
dp =[0]*(N +1)
dp[0] = 1
if 1 not in A:
    dp[1] =1
for i in range(N-1):
    if i+2 in A:
        dp[i+2] = 0
    else:
        dp[i+2] = dp[i+1] + dp[i] 
        dp[i+2] %= mod_9
kotae =dp[N] # % mod_9
print(kotae )
Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
V = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

#どの宝石を選ぶか全探索
v_c_sum=[]
from itertools import combinations
for i in range(N+1):
    for t in combinations(range(N), i):
        v =np.sum(V[list(t)])
        c =np.sum(C[list(t)])
        v_c_sum.append(v-c)
print(max(v_c_sum))

Fixed submission:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
V = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

#どの宝石を選ぶか全探索
v_c_sum=0
for i in range(N):
    if 0 < V[i] -C[i]:
        v_c_sum +=V[i] - C[i]
print(v_c_sum)

Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

#どの宝石を選ぶか全探索
v_c_sum=[]
from itertools import combinations
for i in range(N+1):
    for t in combinations(range(N), i):
        v=0
        c=0
        for j in t:
            v +=V[j]
            c +=C[j]
        v_c_sum.append(v-c)
print(max(v_c_sum))
#print(v_c_sum)

Fixed submission:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
V = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

#どの宝石を選ぶか全探索
v_c_sum=0
for i in range(N):
    if 0 < V[i] -C[i]:
        v_c_sum +=V[i] - C[i]
print(v_c_sum)
Buggy python 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)

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 python 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))

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 python submission (verdict: Time Limit Exceeded):
# 初期入力
import sys
input = sys.stdin.readline
N,Q = (int(x) for x in input().split())
S =input().strip()
l =[]
r =[]
for i in range(Q):
    l1,r1 = (int(x) for x in input().split())
    l.append(l1 -1)
    r.append(r1-2) #"AC"のAの位置と比べるため－２

# ACのindex(左端)
import re
import numpy as np
x =[m.start() for m in re.finditer('AC', S)]
x =np.array(x)
#
for i in range(Q):
    ans = np.count_nonzero( (x >=l[i]) & (x <=r[i]) )
    print(ans)

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline
N,Q = (int(x) for x in input().split())
S =input().strip()
l =[]
r =[]
for i in range(Q):
    l1,r1 = (int(x) for x in input().split())
    l.append(l1 -1) #indexは０始まりだからー１
    r.append(r1 -1) #"AC"のAの位置と比べるため－２

# ACのindex(左端)
import re
import numpy as np
index =0
t =[0]*N

for i in range(N-1):
    t[i+1] = t[i] +np.count_nonzero(S[i:i+2] =="AC")

#
for i in range(Q):
    ans = t[ r[i]] - t[ l[i]] 
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
A,B = (int(i) for i in input().split())
AB =np.array([i for i in range(A,B+1)])
digit_max=40

#
ans =""
for i in range(digit_max):
    c1 =np.count_nonzero(AB &1)
    c1 %= 2
    ans +=str(c1)
    AB >>=1
ans =ans[::-1]
ans =int(ans,2)
print(ans)

Fixed submission:
def xor_sum(n):
    #0からの連続数のXOR和は４つ目が０（初項）
    st =n -n%4
    n_list =[i for i in range(st,n+1)]
    ans =0
    for i in n_list:
        ans ^=i
    return ans
# 初期入力

import sys
input = sys.stdin.readline
A,B = (int(i) for i in input().split())
ans =xor_sum(B) ^xor_sum(A-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
Ken_n,City_n = (int(i) for i in input().split())
city ={i:[] for i in range(1,City_n+1)}
for i in range(1,City_n+1):
    p,y = (int(i) for i in input().split())
    city[p].append((y,i))

city_ID ={i:0 for i in range(1,City_n +1)}
for i in range(1,Ken_n +1):
    city[i].sort()
    for j in range(len(city[i])):
        city_ID[city[i][j][1]] = "{0:06d}".format(i) +"{0:06d}".format(j+1)

for i in range(1,City_n +1):
    print(city_ID[i])

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
Ken_n,City_n = (int(i) for i in input().split())
city ={i:[] for i in range(1,Ken_n+1)}
for i in range(1,City_n+1):
    p,y = (int(i) for i in input().split())
    city[p].append((y,i))

city_ID ={i:0 for i in range(1,City_n +1)}
for i in range(1,Ken_n +1):
    city[i].sort()
    
    for j in range(len(city[i])):
        city_ID[city[i][j][1]] = "{0:06d}".format(i) +"{0:06d}".format(j+1)

for i in range(1,City_n +1):
    print(city_ID[i])
Buggy python 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)

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 python submission (verdict: Runtime Error):
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())
"""
co1_l =list(co1.values())
ce2_l =list(ce2.values())
co1_l.sort(reverse=True)
ce2_l.sort(reverse=True)
"""
ans =0

if vo1 ==ve2:
    ans =len(vo1)
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans1 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)

Fixed submission:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())

ans =0

if vo1 ==ve2:
    if len(ce2_k) <=2:
        ans =sum(ce2_v)
    else:
        ans =sum(ce2_v) +sum(co1_v[2:])   
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans2 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)