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

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  if S[i : i + 2] == 'AC':
    t[i + 1] = t[i] + 1
  else:
    t[i + 1] = t[i]
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  if s[i]=='A' and s[i+1]=='C':
    t[i + 1] = t[i] + 1
  else:
    t[i + 1] = t[i]
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*(n+1)
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i+1]=ans[i]+1
  else:
    ans[i+1]=ans[i]
#ti =「S の 1 文字目から i 文字目までに出現する a の数」として数列 t = {t0, t1, . . . , tN } を考えると、問 i の答えは tri−1 − tli−1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(ans[r-1]-ans[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  tmp=0
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  tmp=sum(ans[l-1:r-1])
  print(tmp)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(sum(ans[l-1:r-1]))

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(sum(ans[L[i]-1:R[i]-1]))

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
Row=q
L=[]
R=[]
for i in range(Row):
    l,r=input().split()
    L.append(int(l))
    R.append(int(r))
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  print(sum(ans[L[i]-1:R[i]-1]))

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
Row=q
L=[]
R=[]
for i in range(Row):
    l,r=input().split()
    L.append(int(l))
    R.append(int(r))
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(len(L)):
  tmp=0
  print(sum(ans[L[i]-1:R[i]-1]))
Problem p03089 (python)

Fixed submission:
import copy
N=int(input())
b=[int(i) for i in input().split()]
 
c = copy.copy(b) #コピーを行う
a = [0]*N
a_n = N-1
 
for n in range(N)[::-1]:#N桁
  for i in range(len(c))[::-1]:#大きい数字からcheck
    if c[i]==i+1:#iが9を超えても成立する
      a[a_n] = c.pop(i)
      #print(c,len(c))
      a_n = a_n-1
      break#このbreakに気づかなかったので、2を取り除いたあとに1も取り除いてしまった
 
if n-1 != a_n:
  print(-1)
  exit()
else:
  for i in range(N):
    print(a[i])

Buggy submission (verdict: Runtime Error):
N=int(input())
b=[int(i) for i in input().split()]
a = [0]*N
def dfs(x,n,a): #n桁のx
  if x == []: #Goalで終了
    return True
    
  for xlen in range(min(len(x),9))[::-1]:
    if x[xlen] == xlen+1:
      a[n] = xlen+1
      xx = copy.copy(x)
      xx.pop(xlen)
      return dfs(xx, n-1, a)

  if a[n] == 0:
      return False
if dfs(b,N-1,a):
  for i in range(N):
    print(a[i])
else:
  print(-1)
Problem p03112 (python)

Fixed submission:
import bisect #bisectの典型的問題
a,b,q = map(int, input().split())

s  = [int(input()) for i in range(a)]
t  = [int(input()) for i in range(b)]

INF=10**18
s=[-INF]+s+[INF] #グリッド系の問題では、配列外を探索しないように
t=[-INF]+t+[INF]
x  = [int(input()) for i in range(q)]
for i in range(q):
  xi = x[i] #xを一気に読み込まなくてもfor loopの中の方が良い
  si = bisect.bisect_right(s, xi)
  ti = bisect.bisect_right(t, xi)
  ans=INF
  
  for S in [s[si-1], s[si]]:
    for T in [t[ti-1], t[ti]]:
      SX = abs(S-xi)
      TX = abs(T-xi)
      ST = abs(S-T)
      ans = min(ans, SX+ST, TX+ST)
  print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
a,b,q = list(map(int, input().split()))

s  = [int(input()) for i in range(a)]
t  = [int(input()) for i in range(b)]
x  = [int(input()) for i in range(q)]

S = np.asarray(s)
T = np.asarray(t)
X = np.asarray(x)

st = np.zeros([a,b])
for i in range(a):
  for j in range(b):
    st[i][j] = abs(s[i]-t[j])

ans = np.zeros(q)
for k in range(q):
  #sを探す
  SX= np.abs(S-X[k])
  min_SX = min(SX)
  i = np.argmin(SX)
  #tを探す
  TX = np.abs(T-X[k])
  j = np.argmin(TX)
  min_TX = min(TX)
  #sが近い->そのsに近いtを探す
  ans[k] = min(min_SX + min(st[i]), min_TX + min(st.T[j]))
  print(int(ans[k]))
Problem p03160 (python)

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]

def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(cost[n-1]+abs(hlist[n]-hlist[n-1]), cost[n-2]+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i]=dp(i)
print(cost[-1])

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)
 
@lru_cache(maxsize = None)

N = int(input())
hlist = list(map(int, input().split()))
 
#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))
 
print(dp(N-1))

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

#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))

print(dp(N-1))
Problem p03231 (python)

Fixed submission:
from fractions import gcd
from bisect import bisect_left
 
N, M = map(int, input().split())
S = input()
T = input()
 
if N > M:
    N, M = M, N
    S, T = T, S

G = N*M // gcd(N, M)
 
a = G//N
b = G//M
 
X = [a*i for i in range(N)]
Y = [b*j for j in range(M)]
 
for i, x in enumerate(X):
    j = bisect_left(Y, x)
    if j < M and Y[j] == x:
        if S[i] != T[j]:
            print(-1)
            break
else:
    print(G)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from bisect import bisect_left

N, M = map(int, input().split())
S = input()
T = input()
 
if N > M:
    N, M = M, N
    S, T = T, S

L = N*M // gcd(N, M)
 
a = G//N
b = G//M
 
X = [a*i for i in range(N)]
Y = [b*j for j in range(M)]
 
for i, x in enumerate(X):
    j = bisect_left(Y, x)
    if j < M and Y[j] == x:
        if S[i] != T[j]:
            print(-1)
            break
else:
    print(L)

Buggy submission (verdict: Runtime Error):
import re

N, M = map(int, input().split())
S = str(input())
T = str(input())
#print(S)

# 最大公約数
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

# 最小公倍数
def lcm(a, b):
  return a*b/gcd(a, b)

L = int(lcm(N, M))

#文字列の作成
#SをもとにX
X1 = r''
n = 0
for i in range(1,int(L)):
  if i == n * (L//N) + 1:
    X1 += S[n]
    n += 1
  else:
    X1 += r'*'
#print(X1)  
#X1とTを比べる
m = 0
ans = 0
for i in range(0,int(L)):
  if i == m * (L//M) :
    #print(i,m,X1[i],T[m])
    if X1[i] == T[m] or X1[i] == "*":
      ans = 1
      m += 1
    else:
      ans = -1
      break

if ans != -1:
  print(int(L))
else:
  print(-1)
Problem p03238 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
if N==1:
  print("Hello World")
else:
  a = int(input())
  b = int(input())
  print(a+b)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)
Problem p03240 (python)

Fixed submission:
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
#arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)
Problem p03280 (python)

Fixed submission:
a, b = map(int, input().split())
print ((a-1)*(b-1))

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

Buggy submission (verdict: Runtime Error):
(A-1)*(B-1)
Problem p03281 (python)

Fixed submission:
a = int(input())
 
b=0#約数の個数
 
for num in range(1,a+1):#i:1~inputまで,奇数だけ
  if num % 2 == 1:
  #ある数Niについて約数を数える
    yakusuu = 0
    for i in range(1,num):
      if num % i == 0:
        yakusuu += 1
    if yakusuu == 7:
      b += 1
print(b)

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

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
	yakusuu_array = []

	for i in range(1,num):
	    if num % i == 0:
            yakusuu_array.append(i)
            
  	if len(yakusuu_array) == 8:
  		b += 1
print(b)

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

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
    yakusuu_array = []

    for i in range(1,num):
        if num % i == 0:
    	    yakusuu_array.append(i)
            
    if len(yakusuu_array) == 8:
  	    b += 1
print(b)

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

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
	yakusuu_array = []

	for i in range(1,num):
	    if num % i == 0:
    	    yakusuu_array.append(i)
            
  	if len(yakusuu_array) == 8:
  		b += 1
print(b)

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

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
	yakusuu_array = []

	for i in range(1,num):
	    if num % i == 0:
    	    yakusuu_array.append(i)
            
  	if len(yakusuu_array) == 8:
  		b += 1
print(b)
Problem p03282 (python)

Fixed submission:
s = int(input())
k = int(input())
S = str(s) #文字列にする

ans=0

for i in range(k):
  N = int(S[i])
  
  if N == 1:
    ans = 1
  else:
    ans = N
    break  
print(ans)

Buggy submission (verdict: Runtime Error):
s = int(input())
k = int(input())
 
ans=0
 
n  = 5000000000000000
 
S = str(s) #文字列にする
saisho = 0
L = len(S)
 
for i in range(L):
  N = int(S[i])
  if k <= saisho+1:#最初からの文字数
    ans = N
    break
    
  else:
    if N == 1:
      Nn == 1
    else:
      Nn = N**n
    saisho += N**n
    
print(ans)

Buggy submission (verdict: Runtime Error):
s = int(input())
k = int(input())
 
ans=0
 
n  = 5000000000000000
 
S = str(s) #文字列にする
L = len(S)
saisho = 0
 
for i in range(L):
  N = int(S[i])
  if N == 1:
    Nn == 1
  else:
    Nn = N**n
    
  if saisho <= k <= saisho + Nn:#最初からの文字数
    ans = N
    break
    
  else:
    saisho += Nn
    
print(ans)

Buggy submission (verdict: Runtime Error):
s = int(input())
k = int(input())
 
ans=0
 
n  = 5000000000000000
 
S = str(s) #文字列にする
L = len(S)
saisho = 0
 
for i in range(L):
  N = int(S[i])
  if N == 1:
    Nn == 1
  else:
    Nn = N**n
    
  if saisho <= k <= saisho + Nn:#最初からの文字数
    ans = N
    break
    
  else:
    if N ==1
      Nn ==
    saisho += Nn
    
print(ans)
Problem p03472 (python)

Fixed submission:
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 
 
#bのうち大きなものから引いていく
#b[i]のうち、max(a)が大きければ、以降max(a)で攻撃し続ける
 
max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] #降順
 
ans = 0
 
b_sort = b_sort[np.where(b_sort > max_a)]
 
#b_sortの中で大きいのから順に引いていく
for i in range(len(b_sort)):
  H -= b_sort[i]
  ans += 1
  if H <= 0:
    print(ans)
    exit()
 
#bをすべて引いてもH>0ならaで攻撃
if H % max_a == 0:
  ans += H // max_a
else:
  ans += H // max_a + 1
 
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 
 
#bのうち大きなものから引いていく
#b[i]のうち、max(a)が大きければ、以降max(a)で攻撃し続ける
 
max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] #降順
 
ans = 0
 
b_sort = b_sort[np.where(b_sort > max_a)]
 
#b_sortの中で大きいのから順に引いていく
for i in range(len(b_sort)):
  H -= b_sort[i]
  ans += 1
  if H <= 0:
    print(ans)
    exit()
 
#bをすべて引いてもH>0ならaで攻撃
if H % max_a == 0:
  ans += H // max_a
else:
  ans += H // max_a + 1
 
print(i)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 

#bのうち大きなものから引いていく
#b[i]のうち、max(a)が大きければ、以降max(a)で攻撃し続ける

max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] #降順

ans = 0

b_sort = b_sort[np.where(b_sort > max_a)]

#b_sortの中で大きいのから順に引いていく
for i in range(len(b_sort)):
  H -= b_sort[i]
  i += 1
  if H <= 0:
    print(i)
    exit()

#bをすべて引いてもH>0ならaで攻撃
if H % max_a == 0:
  i += H // max_a
else:
  i += H // max_a + 1

print(i)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 
#ソート
a_sort = sorted(ab[:,0], reverse=True)
b_sort = sorted(ab[:,1], reverse=True)
ab_sort = sorted(ab.reshape(2*N), reverse=True)
 
ans = 0
i = 0 #ab_sortの中で大きいのから順に引いていく
while H > 0:
  ab_max = ab_sort[i]
  H -= ab_max
  ans += 1
  
  #値がaかbにあるか
  a = np.sum(a_sort == ab_max)
  b = np.sum(b_sort == ab_max)
  if b!=0 and a==0: #値がaになくてbにあれば次に大きい値を引く
    i += 1
  else: #aにあればaを引き続ける
    if H % ab_max == 0:
      ans += H // ab_max
      break
    else:
      ans += H // ab_max + 1
      break
    
print(ans)

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

N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])

#ソート
a_sort = sorted(ab[:,0], reverse=True)
b_sort = sorted(ab[:,1], reverse=True)
ab_sort = sorted(ab.reshape(2*N), reverse=True)

ans = 0
i = 0 #ab_sortの中で大きいのから順に引いていく
while H > 0:
  H -= ab_sort[i]
  ans += 1
  if np.sum(b_sort == ab_sort[i]): #値がbにあれば次に大きい値を引く
    i += 1
    
print(ans)
Problem p03609 (python)

Fixed submission:
a, b = map(int, input().split())
print (a-b) if a-b>0 else print (0)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print min(0,a-b)
Problem p03711 (python)

Fixed submission:
x,y = map(int, input().split())
ans='No'
if x in [2]:
  if y in [2]:
    ans='Yes'
if x in [4,6,9,11]:
  if y in [4,6,9,11]:
    ans='Yes'
if x in [1,3,5,7,8,10,12]:
  if y in [1,3,5,7,8,10,12]:
    ans='Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())
ans='No'
if x,y in [2]:
  if y in [2]:
    ans='Yes'
if x in [4,6,9,11]:
  if y in [4,6,9,11]:
    ans='Yes'
if x in [1,3,5,7,8,10,12]:
  if y in [1,3,5,7,8,10,12]:
    ans='Yes'
print(ans)
Problem p02934 (python)

Fixed submission:
n = int(input())
nums = map(lambda x: 1 / int(x), input().split(' '))
print(1 / sum(nums))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(input().split(' '), lambda x: 1 / int(x)))
print(1 / sum(nums))

Buggy submission (verdict: Runtime Error):
n = int(input())
num = 0
for _ in range(n):
    num += 1 / int(input())
print(1 / num)
Problem p02972 (python)

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

bs = nums.copy()
res = []

for i in range(n // 2, 0, -1):
    val = 0
    for j in range(1, n // i + 1):
        if i * j <= n:
            val += bs[i * j - 1]
    bs[i - 1] = val % 2
for i in range(n):
    if bs[i] > 0:
        res.append(i + 1)
m = sum(bs)
print(m)
if m > 0:
    print(' '.join(map(str, res)))

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

bs = nums.copy()
res = []

for i in range(n // 2, 0, -1):
    bs[i] = 0
    for j in range(1, n // i):
        bs[i] += bs[i * j]
    bs[i] %= 2
for i in range(n):
    if bs[i] > 0:
        res.append(i + 1)
m = sum(bs)
print(m)
if m > 0:
    print(' '.join(map(str, res)))

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

res = nums.copy()

for i in range(n // 2, 0, -1):
    res[i] = 0
    for j in range(1, n // i + 1):
        res[i] += res[i * j]
    res[i] %= 2
for elem in res:
    print(elem)
Problem p03061 (python)

Fixed submission:
def gcd(a, b):
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a


n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = gcd(l_gcds[-1], nums[i])
        r = gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-1], r_gcds[0]]
    for i in range(1, n - 1):
        gcds.append(gcd(l_gcds[i - 1], r_gcds[i]))
    print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
        if i == 1:
          break

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-1], r_gcds[0]]
    for i in range(1, n - 1):
        gcds.append(math.gcd(l_gcds[i - 1], r_gcds[i]))
    print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-2], r_gcds[1]]
    for i in range(1, n - 1):
        gcds.append(math.gcd(l_gcds[i - 1], r_gcds[i + 1]))
    print(max(gcds))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
nums = list(map(int, input().split()))

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-2], r_gcds[1]]
    for i in range(1, n - 1):
        gcds.append(math.gcd(l_gcds[i - 1], r_gcds[i + 1]))
    print(max(gcds))
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = list(input().strip())

streaks = []
c = s[0]
i = 1
count = 1
while True:
    if i == n:
        streaks.append(count)
        break
    if s[i] == c:
        i += 1
        count += 1
    else:
        streaks.append(count)
        c = s[i]
        i += 1
        count = 1

accs = [0]
for num in streaks:
    accs.append(accs[-1] + num)
if accs[-1] != n:
    accs.append(n)

flag = s[0] == '0'
res = []
for i in range(len(accs)):
    if flag:
        index = i + 2 * k
    else:
        index = i + 2 * k + 1
    index = min(index, len(accs) - 1)
    res.append(accs[index] - accs[i])
    flag = not flag

print(max(res))

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


def count_zero(s, i):
    count = 0
    for j in range(i, len(s)):
        if s[j] == 0:
            count += 1
        else:
            break
    return count


def dfs(s, i, k, count):
    if i == len(s):
        return count
    elif s[i] == 1:
        count += 1
        return dfs(s, i + 1, k, count)
    else:
        if k > 0:
            c = count_zero(s, i)
            count += c
            return dfs(s, i + c, k - 1, count)
        else:
            return count


nums = []
for i in range(n):
    count = 0
    nums.append(dfs(s, i, k, count))
print(max(nums))
Problem p03078 (python)

Fixed submission:
import heapq


def select(ls0, ls1, k):
    ls = []
    for a in ls0:
        for b in ls1:
            heapq.heappush(ls, -(a + b))
    return [-heapq.heappop(ls) for _ in range(min(k, len(ls0) * len(ls1)))]


x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
ps = select(ls[0], ls[1], k)
res = select(ps, ls[2], k)
print(*res, sep='\n')

Buggy submission (verdict: Runtime Error):
import collections
import heapq

x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)]
res = []
used = collections.defaultdict(lambda: False)
while len(res) < k:
    s, i, j, l = heapq.heappop(q)
    res.append(-s)
    index_list = [
        (i + 1, j, l),
        (i, j + 1, l),
        (i, j, l + 1),
    ]
    for i, (indices, limit) in enumerate(zip(index_list, [x, y, z])):
        if indices[i] < limit and not used[indices]:
            ss = sum([ls[j][l] for j, l in zip(range(3), indices)])
            heapq.heappush(q, (-ss, *indices))
            used[indices] = True
print(*res, sep='\n')