Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque
 
S = input()
Q = int(input())
S = deque(S)
 
flg_reverse = False
 
for q in range(Q):
  _ = input()
  if _[0] == '1':
    flg_reverse = flg_reverse ^ True
  else:
    _T, _F, _C = _.split()
    ## リバース回数が奇数偶数のいずれかをチェック
    if _F == '1':
      if cnt_reverse % 2 == 0:
        S.appendleft(_C)
      else:
        S.append(_C)
    else:
      if cnt_reverse % 2 == 0:
        S.append(_C)
      else:
        S.appendleft(_C)
 
S = list(S)
# reverseの部分を対応
if flg_reverse:
  S.reverse()
 
print(''.join(S))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
S = deque(S)

cnt_reverse = 0

for q in range(Q):
  _ = input()
  if _[0] == '1':
    cnt_reverse += 1
  else:
    _T, _F, _C = _.split()
    ## リバース回数が奇数偶数のいずれかをチェック
    if _F == '1':
      if cnt_reverse % 2 == 0:
        S.appendleft(_C)
      else:
        S.append(_C)
    else:
      if cnt_reverse % 2 == 0:
        S.append(_C)
      else:
        S.appendleft(_C)

S = list(S)
# reverseの部分を対応
if cnt_reverse % 2 == 1:
  S.reverse()

print(''.join(S))
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())

_list = [-1]*(N+1)

for m in range(M):
  s,c = map(int, input().split())
  
  # 条件を満たさない
  if _list[s] != -1 and _list[s] != c:
    print(-1)
    exit()
  
  else:
    _list[s] = c
  
ans = ''
for idx, _ in ennumerate(_list[1:]):
  if _ == -1:
    # 1桁目は1、そうでなかったら０にする
    if idx != 0:
      ans += '0'
    else:
      ans += '1'
  else:
    ans += str(_)

# 1桁目が0なのはNG
if N > 1 and ans[0] == '0':
  print(-1)
  exit()
else:
  print(int(ans))

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

_list = [-1]*(N+1)

for m in range(M):
  s,c = map(int, input().split())
  # 条件を満たさない
  if _list[s] != -1 and _list[s] != c:
    print(-1)
    exit()
  else:
    _list[s] = c
  
ans = ''
for idx, _ in enumerate(_list[1:]):
  if _ == -1:
    # 1桁目は1、そうでなかったら０にする
    if idx != 0:
      ans += '0'
    else:
      ans += '1'
  else:
    ans += str(_)

# 1桁目が0なのはNG
if N > 1 and ans[0] == '0':
  print(-1)
elif M == 0:
  if N == 1:
    print(0)
  elif N == 2:
    print(10)
  elif N == 3:
    print(100)
else:
  print(int(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))

if len(set(L)) > 3:
  L = list(set(L))

ans = 0
for a in range(0, N-2):
  for b in range(a+1, N-1):
    for c in range(b+1, N):
      if L[a] < (L[b]+L[c]):
        if L[b] < (L[a]+L[c]):
          if L[c] < (L[a]+L[b]):
            ans += 1

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
ans = 0

for a in range(0, N-2):
  for b in range(a+1, N-1):
    t = L[a] + L[b]
    idx = bisect_left(L,t)
    ans += max(0, idx-b-1)

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(set(list(map(int, input().split()))))

ans = 0
for a in range(0, N-2):
  for b in range(a+1, N-1):
    for c in range(b+1, N):
      if L[a] < (L[b]+L[c]):
        if L[b] < (L[a]+L[c]):
          if L[c] < (L[a]+L[b]):
            ans += 1

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
ans = 0

for a in range(0, N-2):
  for b in range(a+1, N-1):
    t = L[a] + L[b]
    idx = bisect_left(L,t)
    ans += max(0, idx-b-1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))

ans = 0
for a in range(0, N-2):
  for b in range(a+1, N-1):
    for c in range(b+1, N):
      if L[a] < (L[b]+L[c]):
        if L[b] < (L[a]+L[c]):
          if L[c] < (L[a]+L[b]):
            ans += 1

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
ans = 0

for a in range(0, N-2):
  for b in range(a+1, N-1):
    t = L[a] + L[b]
    idx = bisect_left(L,t)
    ans += max(0, idx-b-1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
"""
考え方

N-1までの値を合計した値が答え
"""

N = int(input())

ans = 0
for i in range(1,N):
  ans += i

print(ans)

Fixed submission:
N=int(input())

ans = N*(N-1)
ans //= 2

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
N,M = map(int,input().split(' '))
broken_list = [int(input()) for i in range(M)]

ans = [0,1]

for n in range(1,N+1):
  if n in broken_list:
    ans.append(0)
  else:
    ans.append((ans[-2]+ans[-1]) % MOD)

print(ans[-1] % MOD)               

Fixed submission:
MOD = 10**9 + 7
N,M = map(int,input().split(' '))
broken_list = set([int(input()) for i in range(M)])

ans = [0,1]

for n in range(1,N+1):
  if n in broken_list:
    ans.append(0)
  else:
    ans.append((ans[-2]+ans[-1]) % MOD)

print(ans[-1] % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
N,M = map(int,input().split(' '))
broken_list = [int(input()) for i in range(M)]

ans = [0,1]

for n in range(1,N+1):
  if n in broken_list:
    ans.append(0)
  else:
    ans.append(ans[-2]+ans[-1])

print(ans[-1] % MOD)               

Fixed submission:
MOD = 10**9 + 7
N,M = map(int,input().split(' '))
broken_list = set([int(input()) for i in range(M)])

ans = [0,1]

for n in range(1,N+1):
  if n in broken_list:
    ans.append(0)
  else:
    ans.append((ans[-2]+ans[-1]) % MOD)

print(ans[-1] % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())

first,last = map(int,input().split(" "))
set_cnt = set()
for i in range(first,last+1):
  set_cnt.add(i)


for m in range(M-1):
  _first, _last = map(int,input().split(" "))
  _set_cnt = set()
  for _ in range(_first,_last+1):
    _set_cnt.add(_)
  
  set_cnt = set_cnt & _set_cnt

print(len(set_cnt))

Fixed submission:
N,M = map(int, input().split())
min_set_cnt,max_set_cnt = map(int,input().split(" "))

for m in range(M-1):
  _first, _last = map(int,input().split(" "))
  min_set_cnt = max(min_set_cnt,_first)
  max_set_cnt = min(max_set_cnt,_last)


ans = max(max_set_cnt - min_set_cnt + 1, 0)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split(' ')))

from fractions import gcd
from functools import reduce
import functools

def gcd(a,b):
    if a==0:
        return b 
    else:
        return gcd(b%a,a)
  
max_gcd = 0

for i in range(N):
  if i < N:
    values = A[i+1:] + A[:i] 
  else:
    values = A[:-1]
  
  g = lambda a,b:a if b==0 else g(b,a%b)
  gcd = functools.reduce(lambda x,y:g(x,y),values)
  max_gcd = max(max_gcd,gcd)

  
print(max_gcd)

Fixed submission:
def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
 
N=int(input())
A=[int(i) for i in input().split()]
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(1,N):
    X[i]=gcd(X[i-1],A[i-1])
for i in range(N-1)[::-1]:
    Y[i]=gcd(Y[i+1],A[i+1])
Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

list_inp = [a,b,c,d,e]
min_last = 100
for index, inp in enumerate(list_inp):
  tmp = int(str(inp)[-1])
  if tmp == 0:
    continue
  
  if tmp <= min_last:
    min_last = tmp
    min_last_index = index

# 全部の料理がちょうど１０分単位だった場合
if min_last == 100:
  min_last = 0

# 切り上げ
def ceil(src,range):
  if str(src)[-1] == '0':
    return src
  else:
    return ((int)(src / range) + 1 ) * range

ans = 0
for index,value in enumerate(list_inp):
  if index == min_last_index:
    continue
  else:
    ans += ceil(value, 10)


print(ans + list_inp[min_last_index])

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

list_inp = [a,b,c,d,e]
min_last = 100
for index, inp in enumerate(list_inp):
  tmp = int(str(inp)[-1])
  if tmp == 0:
    continue
  
  if tmp <= min_last:
    min_last = tmp
    min_last_index = index

# 全部の料理がちょうど１０分単位だった場合
if min_last == 100:
  min_last_index = 0

# 切り上げ
def ceil(src,range):
  if str(src)[-1] == '0':
    return src
  else:
    return ((int)(src / range) + 1 ) * range

ans = 0
for index,value in enumerate(list_inp):
  if index == min_last_index:
    continue
  else:
    ans += ceil(value, 10)


print(ans + list_inp[min_last_index])

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

list_inp = [a,b,c,d,e]
min_last = 9
for index, inp in enumerate(list_inp):
  tmp = int(str(inp)[-1])
  if tmp == 0:
    continue
  
  if tmp <= min_last:
    min_last = index


    
# 切り上げ
def ceil(src, range):
    return ((int)(src / range) + 1 ) * range

ans = 0
for index,value in enumerate(list_inp):
  if index == min_last:
    continue
  else:
    ans += ceil(value, 10)


print(ans + list_inp[min_last])

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

list_inp = [a,b,c,d,e]
min_last = 100
for index, inp in enumerate(list_inp):
  tmp = int(str(inp)[-1])
  if tmp == 0:
    continue
  
  if tmp <= min_last:
    min_last = tmp
    min_last_index = index

# 全部の料理がちょうど１０分単位だった場合
if min_last == 100:
  min_last_index = 0

# 切り上げ
def ceil(src,range):
  if str(src)[-1] == '0':
    return src
  else:
    return ((int)(src / range) + 1 ) * range

ans = 0
for index,value in enumerate(list_inp):
  if index == min_last_index:
    continue
  else:
    ans += ceil(value, 10)


print(ans + list_inp[min_last_index])
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

'''
考え方
各リストをソートして、前からk個分のみの要素にする
'''

'''
import math

cnt_num = math.ceil(pow(k, 1/3))

A = sorted(A,reverse=True)[:cnt_num]
B = sorted(B,reverse=True)[:cnt_num]
C = sorted(C,reverse=True)[:cnt_num]
'''
A = sorted(A,reverse=True)[:k]
B = sorted(B,reverse=True)[:k]
C = sorted(C,reverse=True)[:k]


ans_list = []
for a in A:
  for b in B:
    for c in C:
      ans_list.append(a+b+c)

ans_list.sort(reverse=True)
for ans in ans_list[:k]:
  print(ans)

Fixed submission:
x,y,z,k = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A = sorted(A,reverse=True)[:k]
B = sorted(B,reverse=True)[:k]
C = sorted(C,reverse=True)[:k]

list_ans = []
for index_a,a in enumerate(A):
  for index_b,b in enumerate(B):
    for index_c,c in enumerate(C):
      if (index_a + 1) * (index_b + 1) * (index_c + 1) > k:
        break
      list_ans.append(a+b+c)


list_ans.sort(reverse=True)
for i in list_ans[:k]:
  print(i)
Buggy python submission (verdict: Runtime Error):
import sys
 
stdin = sys.stdin

N,Q = map(int,input().split())
S = input()

check_point = []
inf = 10 ** 18

# AC文字列のAの位置をリストに収めた
for i in range(inf):
  out = S.find('AC')
  if out < 0:
    break
  else:
    S = S[out+2:]
    check_point.extend([(out + len(check_point) * 2)])
  

# 指定した文字列範囲を含む要素数を表示
for i in range(Q):
  start, end  = map(int, stdin.readline().split())
  print(len([i for i in check_point if (start - 1 <= i) and (i + 1 < end)]))


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

dct_a_tmp = {}
dct_b = {}
for n in range(N):
  a,b = map(int, input().split())
  dct_a_tmp[n] = a
  dct_b[n] = b

# 安い順にkeyをソート
list_a = sorted(dct_a_tmp.items(), key=lambda x: x[1])


# 安い順に買っていく
'''
1.不足本数を計算
2.不足本数と購入できる本数を比較する
a.全部購入していいようなら通常購入
b.ダメなら、購入していい本数だけ購入
'''
cnt_buied = 0
cost = 0
inf = 10 ** 18


for i in range(inf):
  want_buy = M - cnt_buied 
  
  if dct_b[list_a[i][0]] <= want_buy:
    cost += list_a[i][1] * dct_b[list_a[i][0]]
    cnt_buied += dct_b[list_a[i][0]] 
  else:
    cost += list_a[i][1] * want_buy
    cnt_buied += want_buy
    
  if cnt_buied >= M:
    break

print(cost)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

dct_a_tmp = {}
dct_b = {}
for n in range(N):
  a,b = map(int, input().split())
  dct_a_tmp[n] = a
  dct_b[n] = b

# 安い順にkeyをソート
list_a = sorted(dct_a_tmp.items(), key=lambda x: x[1])


# 安い順に買っていく
'''
1.不足本数を計算
2.不足本数と購入できる本数を比較する
a.全部購入していいようなら通常購入
b.ダメなら、購入していい本数だけ購入
'''
cnt_buied = 0
cost = 0
inf = 10 ** 18


for i in range(inf):
  want_buy = M - cnt_buied 
  
  if dct_b[list_a[i][0]] <= want_buy:
    cost += list_a[i][1] * dct_b[list_a[i][0]]
    cnt_buied += dct_b[list_a[i][0]] 
  else:
    cost += list_a[i][1] * want_buy
    
  if cnt_buied >= M:
    break

print(cost)

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

dct_a_tmp = {}
dct_b = {}
for n in range(N):
  a,b = map(int, input().split())
  dct_a_tmp[n] = a
  dct_b[n] = b

# 安い順にkeyをソート
list_a = sorted(dct_a_tmp.items(), key=lambda x: x[1])


# 安い順に買っていく
'''
1.不足本数を計算
2.不足本数と購入できる本数を比較する
a.全部購入していいようなら通常購入
b.ダメなら、購入していい本数だけ購入
'''
cnt_buied = 0
cost = 0
inf = 10 ** 18


for i in range(inf):
  want_buy = M - cnt_buied 
  
  if dct_b[list_a[i][0]] <= want_buy:
    cost += list_a[i][1] * dct_b[list_a[i][0]]
    cnt_buied += dct_b[list_a[i][0]] 
  else:
    cost += list_a[i][1] * want_buy
    cnt_buied += want_buy
    
  if cnt_buied >= M:
    break

print(cost)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

B_2 = str(bin(B)[2:])
B_2_len = len(B_2)
b_a = B-A


'''考え方
B,Aの差分が（２の倍数-1）なら、0も1も偶数個入り続ける。
Bの桁数分ループする
'''

oct = ''
for b in range(1,B_2_len+1,1):
  if b_a % (b ** 2 - 1) == 0:
    oct = '0' + oct
  else:
    oct = '1' + oct



# 2進数を１０進数に変換
out = int(oct, 2)
print(out)


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

def f(x):
  amari = x % 4
  if amari == 0:
    return x
  elif amari == 1:
    return x ^ (x-1)
  elif amari == 2:
    return x ^ (x-1) ^ (x-2)
  elif amari == 3:
    return 0
    
    
A = f(a-1)
B = f(b)


print(A^B)
Buggy python submission (verdict: Runtime Error):
inp = list(map(int, input().split()))

A = inp[0]
B = inp[1]
K = inp[2]

# 約数を求める
yakusuu_a = []
yakusuu_b = []

for i in range(1,A):
    if A % i == 0:
        yakusuu_a.append(i)

for i in range(1,B):
    if B % i == 0:
        yakusuu_b.append(i)

c = []
for i in yakusuu_a:
  if i in yakusuu_b:
    c.append(i)

c.sort()
if len(c) == 0:
  print(1)
else:
  print(c[K-1])

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

A = inp[0]
B = inp[1]
K = inp[2]

# 約数を求める
yakusuu_a = []
yakusuu_b = []

for i in range(1,A+1):
    if A % i == 0:
        yakusuu_a.append(i)

for i in range(1,B+1):
    if B % i == 0:
        yakusuu_b.append(i)

c = []
for i in yakusuu_a:
  if i in yakusuu_b:
    c.append(i)

c.sort(reverse=True)
if len(c) == 0:
  print(1)
else:
  print(c[K-1])

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

A = inp[0]
B = inp[1]
K = inp[2]

# 約数を求める
yakusuu_a = []
yakusuu_b = []

for i in range(1,A):
    if A % i == 0:
        yakusuu_a.append(i)

for i in range(1,B):
    if B % i == 0:
        yakusuu_b.append(i)

c = []
for i in yakusuu_a:
  for j in yakusuu_b:
    if i == j:
      c.append(i)

c.sort()
print(c[K-1])

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

A = inp[0]
B = inp[1]
K = inp[2]

# 約数を求める
yakusuu_a = []
yakusuu_b = []

for i in range(1,A+1):
    if A % i == 0:
        yakusuu_a.append(i)

for i in range(1,B+1):
    if B % i == 0:
        yakusuu_b.append(i)

c = []
for i in yakusuu_a:
  if i in yakusuu_b:
    c.append(i)

c.sort(reverse=True)
if len(c) == 0:
  print(1)
else:
  print(c[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
len_1st = len(inp)

inf = 10 ** 5
for i in range(inf):
  inp = inp.replace('10','')  
  inp = inp.replace('01','')  
  
  if i%100 == 0: 
    cnt_01 = inp.count('01')
    cnt_10 = inp.count('10')
    if (cnt_01 == 0) & (cnt_10 == 0):
      break
  
len_after = len(inp)
print(len_1st - len_after)

Fixed submission:
inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
len_1st = len(inp)

inf = 10 ** 5
for i in range(inf):
  inp = inp.replace('10','')  
  inp = inp.replace('01','')  
  
  cnt_01 = inp.count('01')
  cnt_10 = inp.count('10')
  if (cnt_01 == 0) & (cnt_10 == 0):
    break
  
len_after = len(inp)
print(len_1st - len_after)

Fixed submission:
inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
cnt = 0

inf = 10 ** 5
for i in range(inf):
  cnt_10 = inp.count('10')
  if cnt_10 > 0:
    cnt += cnt_10 * 2
    inp = inp.replace('10','')

  cnt_01 = inp.count('01')
  if cnt_01 > 0:
    cnt += cnt_01 * 2
    inp = inp.replace('01','')  
  
  if (cnt_01 == 0) & (cnt_10 == 0):
    break

print(cnt)

Fixed submission:
inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
cnt = 0

inf = 10 ** 18
for i in range(inf):
  cnt_10 = inp.count('10')
  if cnt_10 > 0:
    cnt += cnt_10 * 2
    inp = inp.replace('10','')

  cnt_01 = inp.count('01')
  if cnt_01 > 0:
    cnt += cnt_01 * 2
    inp = inp.replace('01','')  
  
  if (cnt_01 == 0) & (cnt_10 == 0):
    break

print(cnt)

Fixed submission:
inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0


for n in range(1,N):
  for k in range(1,K+1):
    if n-k < 0:
      break
    dp[n] = min(dp[n], dp[n-k]+abs(H[n]-H[n-k])) 
  
print(dp[-1])

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

import numpy as np

cost = np.zeros(N,dtype=int)
H = np.array(H)

for n in range(1,N):
  start = max(0, n-K)
  cost[n] = min(cost[start:n] + 
          abs(H[n]-H[start:n])
         )

 
print(cost[-1])
Buggy python submission (verdict: Runtime Error):
N,W = map(int, input().split())

import numpy as np
dp = np.zeros(W+1, dtype=int)

for n in range(N):
  w,v = map(int, input().split())
  dp[w:] = np.maximum(dp[:-w]+v, dp[w:])

print(dp[-1])

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

import numpy as np
dp = np.zeros(W+1, dtype=int)

for n in range(N):
  w,v = map(int, input().split())
  dp[w:] = np.maximum(dp[:-w]+v, dp[w:])

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())

list_inp = [list(map(int,input().split())) for _ in range(N)]
list_inp.sort(key=lambda x: x[2], reverse=True)
max_list_inp = list_inp[-1]


for x in range(101):
  for y in range(101):
    flg = True
    max_h = max_list_inp[2] + abs(max_list_inp[0] - x) + abs(max_list_inp[1] - y)
    
    # 全サンプルで、結果が一致することを確認する。
    for i in list_inp:
      h = max(max_h - abs(i[0] - x) - abs(i[1] - y), 0)
      if h != i[2]:
        flg = False
        break
    
    if flg:
      ans_x, ans_y,ans_h = x,y,max_h
      break
    
  if flg:
    break
    
    
print(ans_x, ans_y,ans_h)

Fixed submission:
N = int( input())
X = [ list( map( int, input().split())) for _ in range(N)]
for j in range(N):
    if X[j][2] != 0:
        k = j
        break
A = X[j]


for cx in range(101):
  for cy in range(101):
    H = A[2] + abs(A[0] - cx) + abs(A[1] - cy)
    flag = True
    for i in range(N):
      if max(H - abs(X[i][0]-cx) - abs(X[i][1] - cy), 0) != X[i][2]:
        flag = False
        break
    if flag:
      print(cx,cy,H)
      break
  if flag:
    break

Buggy python submission (verdict: Runtime Error):
N = int(input())

list_inp = [list(map(int,input().split())) for _ in range(N)]
list_inp.sort(key=lambda x: x[2], reverse=True)
max_list_inp = list_inp[-1]


for x in range(101):
  for y in range(101):
    flg = True
    max_h = max_list_inp[2] + abs(max_list_inp[0] - x) + abs(max_list_inp[1] - y)
    
    # 全サンプルで、結果が一致することを確認する。
    for i in list_inp:
      h = max(max_h - abs(i[0] - x) - abs(i[1] - y), 0)
      if h != i[2]:
        flg = False
        break
    
    if flg:
      ans_x, ans_y,ans_h = x,y,max_h
    
    
print(ans_x, ans_y,ans_h)

Fixed submission:
N = int( input())
X = [ list( map( int, input().split())) for _ in range(N)]
for j in range(N):
    if X[j][2] != 0:
        k = j
        break
A = X[j]


for cx in range(101):
  for cy in range(101):
    H = A[2] + abs(A[0] - cx) + abs(A[1] - cy)
    flag = True
    for i in range(N):
      if max(H - abs(X[i][0]-cx) - abs(X[i][1] - cy), 0) != X[i][2]:
        flag = False
        break
    if flag:
      print(cx,cy,H)
      break
  if flag:
    break
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
An = list(map(int, input().split()))

ans = 0
for x in range(N):
  for y in range(x+1,N+1):
    _ = sum(An[x:y])
    if _%M == 0:
      ans += 1

print(ans)

Fixed submission:
import numpy as np
from collections import Counter

N,M = map(int, input().split())
An = [0] + list(map(int, input().split()))
An = np.array(An)

_ = Counter(np.cumsum(An%M) % M)
ans = 0
for i in _.values():
  ans += i*(i-1)//2

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [A[i] - (i+1) for i in range(N)]

B.sort()

print(sum(abs(x - B[2//N]) for x in B))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [A[i] - (i+1) for i in range(N)]

B.sort()

print(sum([abs(x - B[N//2]) for x in B]))
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))

inf = 10 ** 18

for i in range(1,inf):
  N -= (K - 1)a
  if N <= 1:
    print(i)
    break
  

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

inf = 10 ** 18

for i in range(1,inf):
  N -= (K - 1)
  if N <= 1:
    print(i)
    break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()


"""考え方
「右側のE」+「左側のW」の合計が一番小さくなるインデックスを探索する。
"""

ans = 10**6
## 西の端から東に向かって確認していく
for n in range(0,N):
  cnt = S[:n].count('W') + S[n:].count('E')
  ans = min(ans,cnt)

print(ans)

Fixed submission:
N = int(input())
S = input()


"""考え方
「右側のE」+「左側のW」の合計が一番小さくなるインデックスを探索する。
"""
left_w = 0
right_e = S.count('E')
ans = 10**6
## 西の端から東に向かって確認していく
for n in range(0,N):
  if S[n] == "W":
    cnt = left_w + right_e
    left_w += 1
  else:
    cnt = left_w + right_e - 1
    right_e -= 1
    
  ans = min(ans,cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

import collections

c = collections.Counter(A)
values, counts = zip(*c.most_common()[::-1])
counts = list(counts)
cnt = 0
inf = 10 ** 18


for _ in range(inf):
  if len(counts) <= K:
    print(cnt)
    break

  cnt +=  counts[0]  
  counts = counts[1:]
    


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

import collections
from itertools import accumulate

c = collections.Counter(A)
_, counts = zip(*c.most_common()[::-1])
counts = list(accumulate(counts))
cnt = 0
inf = 10 ** 18

target = len(counts) - K 
 
if target <= 0:
  print(0)
else:
  print(counts[target-1])
Buggy python submission (verdict: Runtime Error):
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])


for x in range(2):
  if x == 0:
    _ = A+B
    op1 = '+'
  else:
    _ = A-B
    op1 = '-'
  for y in range(2):
    if y == 0:
      _ += C
      op2 = '+'
    else:
      _ -= C
      op2 = '-'      
    for z in range(2):
      if z == 0:
        _ += D
        op3 = '+'
      else:
        _ -= D
        op3 = '-'      
      if _ == 7:
        ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)

Fixed submission:
ABCD = input()

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])


def get_op(num):
  if num == -1:
    _ = '-'
  else:
    _ = '+'

  return _
  

for x in [-1,1]:
  for y in [-1,1]:
    for z in [-1,1]:
      _ = A+x*B+y*C+z*D
      if _ == 7:
        op1 = get_op(x)
        op2 = get_op(y)
        op3 = get_op(z)        
        ans = str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7'

print(ans)