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

Fixed submission:
N = int(input())
if N<=104:
    print(0)
elif N<=134:
    print(1)
elif N<=164:
    print(2)
elif N<=188:
    print(3)
elif N<=194:
    print(4)
else:
    print(5)

Buggy submission (verdict: Runtime Error):
if N<=104:
    print(0)
elif N<=134:
    print(1)
elif N<=164:
    print(2)
elif N<=188:
    print(3)
else:
    print(4)
Problem p03282 (python)

Fixed submission:
S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
flag=0
flag2=0
i=0
j=0
ans = 0
if K<=len(l):
    while j<K and flag2 == 0:
        if l[j] == 1 or l[j]==0:
            ans = l[j]
            j = j + 1
        else:
            flag2 =1
            ans = l[j]
else:
    while flag ==0:
        if l[i] == 1 or l[i]==0:
            i = i + 1
        else:
            flag=1
            ans = l[i]
print(ans)

Buggy submission (verdict: Runtime Error):
S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
length = len(l)
flag=0
i=0
ans = 0
while flag ==0:
    if l[i] == 1 or l[i]==0:
        i = i + 1
    else:
        flag=1
        ans = l[i]
if len(l)>=K:
    ans = l[K-1]
print(ans)

Buggy submission (verdict: Runtime Error):
S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
length = len(l)
flag=0
i=0
ans = 0
while flag ==0:
    if l[i] == 1 or l[i]==0:
        i = i + 1
    else:
        flag=1
        ans = l[i]
if len(l)>=K:
    ans = S[K-1]
print(ans)

Buggy submission (verdict: Runtime Error):
S = int(input())
l = [int(x) for x in list(str(S))]
K = int(input())
length = len(l)
flag=0
i=0
ans = 0
while flag ==0:
    if l[i] == 1:
        i = i + 1
    else:
        flag=1
        ans = l[i]
if len(S)>=K:
    ans = S[K-1]
print(ans)
Problem p03309 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i - 1
A = sorted(A)
medN = N//2

x = 0
for i in range(N):
    x = x + abs(A[i] - A[medN])
print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i - 1
A = sorted(A)
medN = N//2

x = 0
for i in range(N):
    x = x + abs(A[i] - A[halfN])
print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = A[i] - i
sorted(A)
halfN = int(N/2)
x = 0
list = []
for j in range(-1,2):
    for i in range(N):
        x = x + abs(A[i] - A[halfN+j])
    list.append(x)
    x = 0
print(min(list))
Problem p02787 (python)

Fixed submission:
import numpy as np

H, N = map(int, input().split())

A = []
B = []
for i in range(N):
	a, b = list(map(int, input().split()))
	A.append(a)
	B.append(b)

A = np.array(A)
B = np.array(B)

dp = np.full((H+1), np.inf)
dp[0] = 0

def solve():
	for i in range(1, H + 1):
		dp[i] = np.amin(dp[np.maximum(i - A, 0)] + B)
	return int(dp[H])

print(solve())

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

H, N = map(int, input().split())

A = []
B = []
for i in range(N):
	a, b = list(map(int, input().split()))
	A.append(a)
	B.append(b)

A = np.array(A)
B = np.array(B)

dp = np.full((H+1), np.inf)
dp[0] = 0

def solve():
	for i in range(1, H + 1):
		dp[i] = np.amin(dp[np.maximum(i - A, 0)] + B)
	return int(dp[H])

print(solve())
Problem p03290 (python)

Fixed submission:
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})


d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], (g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})

d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)
Problem p03545 (python)

Fixed submission:
def dfs(i: int, t: int, op: str):
  if i == 3:
    if t == 7:
      return op
    else:
      return ""

  return dfs(i + 1, t + s[i + 1], op + "+") + dfs(i + 1, t - s[i + 1], op + "-")

s = list(map(int, list(input())))
op = ""

op = dfs(0, s[0], op)
ans = str(s[0]) + op[0] + str(s[1]) + op[1] + str(s[2]) + op[2] + str(s[3]) + "=7"
print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(array: list, index: int, calc: str, result: int):
    if index == len(array):
        if result == 7:
            print("{}=7".format(calc))
            exit(0)

    if index == 0:
        test(array, index + 1, array[index], int(array[index]))
    elif index < len(array):
        test(array, index + 1, calc + "-" + array[index], result - int(array[index]))
        test(array, index + 1, calc + "+" + array[index], result + int(array[index]))

array = list(input())
test(array, 0, "", 0)

Buggy submission (verdict: Runtime Error):
def dfs(i: int, t: int, op: str):
  if i == 3:
    if t == 7:
      return op
    else:
      return ""

  return dfs(i + 1, t + s[i + 1], op + "+") + dfs(i + 1, t - s[i + 1], op + "-")

s = list(map(int, list(input())))
ans = 0
op = ""

op = dfs(0, s[0], op)
print(f"{s[0]}{op[0]}{s[1]}{op[1]}{s[2]}{op[2]}{s[3]}=7")
Problem p03565 (python)

Fixed submission:
sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

n = len(S)
m = len(T)

s = []

for i in reversed(range(n - m + 1)):
  t_kamo = S[i: i + m]
  for j in range(m + 1):
    if j == m:
      print((S[:i] + T +  S[i + m:]).replace("?", "a"))
      exit()
    if t_kamo[j] == "?":
      continue
    elif t_kamo[j] != t[j]:
      break

print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
S = list(input())
T = list(input())
flag = False

if "".join(map(str, T)) in "".join(map(str, S)):
  for i in range(len(S)):
      if S[i] == "?":
        S[i] = "a"
    print("".join(map(str,S)))

else:
  for i in reversed(range(len(S) - len(T) + 1)):
    if S[i] == (T[0] or "?"):
      for j in range(len(T)):
        if S[i + j] != T[j] and S[i + j] != "?":
          print(S[i + j])
          break
      else:
        flag = True
        S[i:i + len(T)] = T

  if flag == False:
    print("UNRESTORABLE")
  else:
    for i in range(len(S)):
      if S[i] == "?":
        S[i] = "a"
    print("".join(map(str,S)))
Problem p03145 (python)

Fixed submission:
a,b,c=map(int,input().split())
print(int((a*b)/2))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(d/2)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
d=a*B
print(d*0.5)

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

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

print(a*b/2)

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

print(a*b/2)
Problem p02724 (python)

Fixed submission:
from sys import maxsize as infinity


def exchange(amount: int) -> int:
    dp = [0] * (amount + 1)

    for to_exchange in range(amount + 1):
        dp[to_exchange] = 0

        for (coin, gain) in [(500, 1000), (5, 5), (100, 0), (50, 0), (10, 0), (1, 0)]:
            if coin <= to_exchange:
                dp[to_exchange] = max(
                    dp[to_exchange],
                    gain + dp[to_exchange - coin]
                )

    return dp[amount]


amount = int(input())
n_500, new_amount = divmod(amount, 500)
n_5, new_amount_2 = divmod(new_amount, 5)

print(n_500 * 1000 + n_5 * 5)

Buggy submission (verdict: Runtime Error):
from sys import maxsize as infinity


def exchange(amount: int) -> int:
    dp = [0] * (amount + 1)

    for to_exchange in range(amount + 1):
        dp[to_exchange] = 0

        for (coin, gain) in [(500, 1000), (5, 5), (100, 0), (50, 0), (10, 0), (1, 0)]:
            if coin <= to_exchange:
                dp[to_exchange] = max(
                    dp[to_exchange],
                    gain + dp[to_exchange - coin]
                )

    return dp[amount]


amount = int(input())
print(exchange(amount))

Buggy submission (verdict: Runtime Error):
from sys import maxsize as infinity
import resource
import sys

resource.setrlimit(resource.RLIMIT_STACK, (2**29, -1))
sys.setrecursionlimit(10**6)

dp = {}
minus_infinity = - (infinity // 2)


def exchange(amount: int) -> int:
    if amount < 0:
        return minus_infinity
    if amount == 0:
        return 0
    if amount in dp:
        return dp[amount]

    dp[amount] = max([
        1000 + exchange(amount - 500),
        5 + exchange(amount - 5),
        exchange(amount - 100),
        exchange(amount - 50),
        exchange(amount - 10),
        exchange(amount - 1)
    ])

    return dp[amount]


amount = int(input())
print(exchange(amount))
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))

red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
apple.sort()

j = 0
for i in range(X + Y):
    if apple[i] < trans[j]:
        apple[i] = trans[j]
        j = j + 1
        if j == C:
            break
    else:
        continue
print(sum(apple))

Buggy submission (verdict: Runtime Error):
# 標準入力
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))

red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
apple.sort(reverse=True)

j = 0
for i in range(X + Y):
    if apple[X + Y - i - 1] < trans[j]:
        apple[X + Y - i - 1] = trans[j]
        j = j + 1
        if j is C:
            break
    else:
        continue
print(sum(apple))

Buggy submission (verdict: Runtime Error):
# 標準入力
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))
red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
apple.sort(reverse=True)
j = 0
for i in range(X + Y):
    if apple[i] < trans[j]:
        apple[i] = trans[j]
        j = j + 1
    else:
        continue
print(sum(apple))

Buggy submission (verdict: Runtime Error):
# 標準入力
X, Y, A, B, C = map(int, input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
trans = list(map(int,input().split()))
red.sort(reverse=True)
green.sort(reverse=True)
trans.sort(reverse=True)
apple = red[:X] + green[:Y]
j = 0
for i in range(X + Y):
    if apple[i] < trans[j]:
        apple[i] = trans[j]
        j = j + 1
    else:
        continue
print(sum(apple))
Problem p02730 (python)

Fixed submission:
def palindrome(S):
    N=len(S)
    for i in range(N):
        if S[i]!=S[N-i-1]:
            return False
    return True
def g(S):
    N=len(S)
    if palindrome(S)==True and palindrome(S[(((N+3)//2)-1):])==True and palindrome(S[:((N-1)//2)])==True:
        return "Yes"
    else:
        return "No"
S=input()
print(g(S))

Buggy submission (verdict: Runtime Error):
def g(S):
    N=len(S)
    if palindrome(S)==True and palindrome(S[((N+3)//2)-1])==True and palindrome(S[(N-1)//2])==True:
        return "Yes"
    else:
        return "No"
S=input()
print(g(S))
Problem p02806 (python)

Fixed submission:
def f(X,s,t):
    N=len(s)
    i=0
    c=0
    b=0
    while i<N and s[i]!=X:
        c+=int(t[i])
        i+=1
    #print(c)
    #print(i)
    for k in range(N):
        b+=int(t[k])
    #print(b)
    return b-(c+int(t[i]))
N=int(input())
s=[0]*N
t=[0]*N
for a in range(0,N):
    (s[a],t[a])=map(str,input().split())
X=str(input())
print(f(X,s,t))

Buggy submission (verdict: Runtime Error):
def f(X,s,t):
    N=len(s)
    i=0
    c=0
    while s[i]!=X:
        c+=int(t[i])
        i+=1
    return sum(t)-(c+int(t[i]))
N=int(input())
s=[0]*N
t=[0]*N
for a in range(0,N):
    (s[a],t[a])=map(str,input().split())
X=input()
print(f(X,s,t))
Problem p02817 (python)

Fixed submission:
def f(S,T):
    return T+S
S,T= map(str,input().split())
print(f(S,T))

Buggy submission (verdict: Runtime Error):
def f(S,t):
    return T+S
S=input()
T=input()
print(f(S,T))
Problem p02854 (python)

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

sep = N//2
for i in range(N):
  if sum(A[:sep]) >= sum(A[sep:]):
    sep -= N//((i+2)**2)
  else:
    sep += N//((i+2)**2)
  if N//((i+2)**2) == 1:
    break
#print(sep)


a = abs(sum(A[:sep])-sum(A[sep:]))
b = abs(sum(A[:sep+1])-sum(A[sep+1:]))
c = abs(sum(A[:sep-1])-sum(A[sep-1:]))
d = abs(sum(A[:sep+2])-sum(A[sep+2:]))
e = abs(sum(A[:sep-2])-sum(A[sep-2:]))
print(min(a,b,c,d,e))

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

if A[:1] < A[1:]:
  print(abs(A[1:]-A[:1]))
  sys.exit()
if A[:1] > A[1:]:
  print(abs(A[:1]-A[1:]))
  sys.exit()

sep = N//2
for i in range(N):
  if sum(A[:sep]) >= sum(A[sep:]):
    sep -= N//((i+2)**2)
  else:
    sep += N//((i+2)**2)
  if N//((i+2)**2) == 1:
    break
#print(sep)


a = abs(sum(A[:sep])-sum(A[sep:]))
b = abs(sum(A[:sep+1])-sum(A[sep+1:]))
c = abs(sum(A[:sep-1])-sum(A[sep-1:]))
print(min(a,b,c,d,e))
Problem p02923 (python)

Fixed submission:
N = int(input())
H = list(map(int,input().split()))
ans = [0]
count = 0
for i in range(N-1):
  if i == N-2:
    if H[i] >= H[i+1]:
      count += 1
    ans.append(count)
    break
  if H[i] < H[i+1]:
    ans.append(count)
    count = 0
  else:
    count += 1
print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int,input().split()))
ans = []
count = 0
for i in range(N-1):
  if i == N-2:
    if H[i] >= H[i+1]:
      ans.append(count+1)
    else:
      ans.append(count)
    break
  if H[i] < H[i+1]:
    ans.append(count)
    count = 0
  else:
    count += 1
print(max(ans))
Problem p02924 (python)

Fixed submission:
N = int(input())
print((N-1)*N//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(range(1,N))
print(sum(P))
Problem p02947 (python)

Fixed submission:
import math
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
s = [sorted(input())]
ans = 0
for i in range(N-1):
  s_i = sorted(input())
  s.append(s_i)
s = sorted(s)
count=1
for j in range(N-1):
  if s[j] == s[j+1]:
    count+=1
  else:
    if count != 1:
      ans += combinations(count,2)
    count=1
if count != 1:
  ans += combinations(count,2)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
s = [sorted(input())]
ans = 0
for i in range(N-1):
  s_i = sorted(input())
  s.append(s_i)
s = sorted(s)
count=1
for j in range(N-1):
  if s[j] == s[j+1]:
    count+=1
  else:
    ans += combinations(count,2)
    count=1
if count != 1:
  ans += combinations(count,2)
print(ans)
Problem p02963 (python)

Fixed submission:
S = int(input())
x1 = 0
y1 = 0
x2 = 10**9
y2 = 1
x3 = (x2-S%x2)%x2
y3 = -(-S//x2)
print(x1,y1,x2,y2,x3,y3)

Buggy submission (verdict: Runtime Error):
S = int(input())
N = 10**9
x = (N - S%N) % N
y = S//x2 + 1
print(0,0,10**9,1,x,y)
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A_max = max(A)
A_max_count = A.count(A_max)
if A_max_count != N:
  a_ = A[:]
  a_ = sorted(a_,reverse = True)
  A_next_max = a_[A_max_count]
else:
  A_next_max = A_max_count

for i in range(N):
  tmp = A[i]
  if tmp != A_max:
    print(A_max)
  else:
    if A_max_count == 1:
      print(A_next_max)
    else:
      print(A_max)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
A_max = max(A)
A_max_count = A.count(A_max)
a_ = A[:]
a_ = sorted(a_,reverse = True)
A_next_max = a_[A_max_count]

for i in range(N):
  tmp = A[i]
  if tmp != A_max:
    print(A_max)
  else:
    if A_max_count == 1:
      print(A_next_max)
    else:
      print(A_max)
Problem p03037 (python)

Fixed submission:
N,M = map(int,input().split())
L,R = map(int,input().split())
for i in range(M-1):
  L_ans,R_ans = map(int,input().split())
  if L < L_ans:
    L = L_ans
  if R > R_ans:
    R = R_ans
print(len(list(range(L,R+1))))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
L,R = map(int,input().split())
tmp = list(range(L,R+1))
for i in range(M-1):
  L,R = map(int,input().split())
  ans = []
  for j in tmp:
    if L<=j<=R:
      ans.append(j)
  tmp = ans
print(len(ans))
Problem p03061 (python)

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

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

ans = 0
L = [0]*(N+1)
for i in range(N):
  L[i+1] = gcd(L[i],A[i])

R = [0]*(N+1)
for i in range(N-1,-1,-1):
  R[i] = gcd(R[i+1],A[i])
  
for i in range(N):
  M = gcd(L[i],R[i+1])
  if ans < M:
    ans = M
    
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
ans = 0
A = sorted(A)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
ans = 0
ans_ = 0
if N == 2:
  print(max(A))
elif N == 3:
  tmp = [A[0],A[1],A[N-1]]
  for i in range(len(tmp)):
    tmp_ = tmp[:]
    tmp_.pop(i)
    ans_ = gcd_list(tmp_)
    if ans < ans_:
      ans = ans_
  print(ans)
else:
  tmp = [A[0],A[1],A[N-2],A[N-1]]
  if len(list(set(A))) == 2:
    print(max(A))
  else:
    count = 0
    ans = gcd_list(tmp)
    for j in range(N):
      if A[j]%ans != 0:
        count+=1
    if count = 1:
      print(ans)
    else:
      for i in range(len(tmp)):
        tmp_ = tmp[:]
        tmp_.pop(i)
        ans_ = gcd_list(tmp_)
        if ans < ans_:
          ans = ans_
      print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 0
A_set = list(set(A))
if len(A_set)==2 and (A.count(A_set[0])==1 or A.count(A_set[1])==1):
  print(max(A))
elif len(A_set)==1:
  print(max(A))
else:
  for i in sorted(range(1,max(A)+1),reverse=True):
    tmp = [A[j]%int(i) for j in range(N)]
    tmp_set = list(set(tmp))
    if len(tmp_set)==2:
      if tmp.count(tmp_set[0])==1 or tmp.count(tmp_set[1])==1:
        ans = i
        break
  print(ans)
Problem p03067 (python)

Fixed submission:
A,B,C = map(int,input().split())

if (C >= A and C <= B) or  (C <= A and C >= B):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
count = 0
count_b = []
count_w = []
b_num = 0
w_num = 0
w_all = S.count('.')
for i in range(N):
  if S[i] == '#':
    b_num += 1
  if S[i] == '.':
    w_num += 1
  count_w.append(w_all-w_num)
  count_b.append(b_num)
ans = 100000
for i in range(N):
  if ans > count_b[i]+count_w[i]:
    ans = count_b[i]+count_w[i]

print(ans)
Problem p03089 (python)

Fixed submission:
N = int(input())
b = list(map(int,input().split()))
ans = []

for j in range(N):
  n = list(range(1,len(b)+1))
  n_tmp = [x - y for (x, y) in zip(n,b)]
  if min(n_tmp) >= 0:
    tmp = sorted(list(set(b)),reverse = True)
    for i in tmp:
      if i == b[i-1]:
        ans.insert(0,b[i-1])
        b.pop(i-1)
        break
  else:
    print('-1')
    break
else:
  for k in range(N):
    print(ans[k])

Buggy submission (verdict: Runtime Error):
N = int(input())
b = list(map(int,input().split()))
ans = []
if b[0]!=1:
  print('-1')
else:
  for j in range(N):
    tmp = sorted(list(set(b)),reverse = True)
    for i in tmp:
      if i == b[i-1]:
        ans.insert(0,b[i-1])
        b.pop(i-1)
        break
  for k in range(N):
    print(ans[k])
Problem p03146 (python)

Fixed submission:
s = int(input())
f = []
n = s
while(1):
  f.append(n)
  if n % 2 == 0:
    n = int(n/2)
  else:
    n = 3*n+1
  
  if n in f:
    break
    
print(len(f)+1)

Buggy submission (verdict: Runtime Error):
s = int(input())
f = [s]
i = 1
n = s
while(i<=1000001):
  if n % 2 == 0:
    f.append(int(n/2))
  else:
    f.append(3*n+1)
  n = f[i]
  i = i + 1
f_ = list(dict.fromkeys(f))
f.pop(f.index(f_[0]))
print(f.index(f_[0]))

Buggy submission (verdict: Runtime Error):
s = int(input())
f = []
i = 0
n = s
while(i<1000000):
  if n % 2 == 0:
    f.append(n/2)
  else:
    f.append(3*n+1)
  n = f[i]
  i = i + 1
f_ = list(dict.fromkeys(f))
f.pop(f.index(f_[0]))
print(f.index(f_[0])+1)
Problem p03150 (python)

Fixed submission:
S = list(input())
ans = ['k','e','y','e','n','c','e']
for i in range(len(S)):
    for j in range(i,len(S)):
        new_str = S[:i] + S[j:]
        if new_str == ans:
            print("YES")
            break
    else:
        continue
    break
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
S = list(input())
ans = ['k','e','y','e','n','c','e']

for i in range(len(ans)):
  if S[i] == ans[i]:
    S[i] = ans[i] = ''
  else:
    break
S = list(''.join(S))
ans = list(''.join(ans))

if ans != []:
  for i in range(len(ans)):
    for j in range(len(S)):
      if S[j] != ans[i]:
        S[j] = ''
      else:
        break
    else:
      continue
    break
  S = list(''.join(S))

  for i in range(len(ans)):
    if S[i] == ans[i]:
      S[i] = ans[i] = ''
    else:
      break
  S = list(''.join(S))
  ans = list(''.join(ans))

  if ans == [] and S == []:
    print('YES')
  else:
    print('NO')
else:
 print('YES')
Problem p03160 (python)

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

dp_num = []
dp_num.append(0)
dp_num.append(abs(h[1]-h[0]))
for i in range(2,N):
  tmp = min(dp_num[i-2]+abs(h[i]-h[i-2]),dp_num[i-1]+abs(h[i]-h[i-1]))
  dp_num.append(tmp)
print(dp_num[N-1])

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

memo = [-1]*N
# iをわたすとiにおける最小のコストを返す
# N-1を渡した時が答え
def calc_cost(i):
  if memo[i] != -1:
    return memo[i]
  # 初期値は条件分岐
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[0]-h[1])
  
  a = calc_cost(i-1)+abs(h[i]-h[i-1])
  b = calc_cost(i-2)+abs(h[i]-h[i-2])
  memo[i] = min(a,b)
  return(memo[i])

print(calc_cost(N-1))
Problem p03161 (python)

Fixed submission:
def main():
  N,K= map(int,input().split())
  h = list(map(int,input().split()))
  dp = [0]*N
  for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(i-K,0),i))
  print(dp[N-1])

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  N,K= map(int,input().split())
  h = list(map(int,input().split()))
  dp = [-1]*N
  dp[0] = 0
  for i in range(1,N):
    tmp = i - K
    if tmp < 0: tmp = 0
    cost_min = 10**9
    for j in range(index,i):
      ans = dp[j] + abs(h[i] - h[j])
      if cost_min > ans: cost_min = ans
    dp[i] = cost_min
  print(dp[N-1])

if __name__ == '__main__':
  main()