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

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

S_array = [["#" for _ in range(W+2)]] + [["#"] + list(input()) + ["#"] for i in range(H)] + [["#" for _ in range(W+2)]]

def connection_check(target_list):
    connection = 0
    connection_list = list()
    
    for i in range(len(target_list)):
        if target_list[i]=="#":
            connection_list += [connection for _ in range(connection)]
            connection_list += [0]
            connection = 0
        elif target_list[i]==".":
            connection += 1
    
    return connection_list

W_connection_array = [[0 for _ in range(W+2)]] + [connection_check(S_array[i]) for i in range(1,H+1)] + [[0 for _ in range(W+2)]]
H_connection_array = [[0 for _ in range(H+2)]] + [connection_check([row[i] for row in S_array]) for i in range(1,W+1)] + [[0 for _ in range(H+2)]]

#print(W_connection_array)
#print(H_connection_array)

ans = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        temp_ans = W_connection_array[i][j] + H_connection_array[j][i]
        if ans < temp_ans:
            ans = temp_ans

print(ans - 1) #自分自身の分の重複加算を引く

Buggy submission (verdict: Runtime Error):
#129d
H,W = map(int, input().split()) #H,W<=2000≒2*10^3
#∴最大で4*10^6…シンプルな処理でないと死ぬ。

input_2d = [[None] * W for _ in range(H)]

processed_input_2d_w = [[None] * W for _ in range(H)]
processed_input_2d_h = [[None] * H for _ in range(W)]

ans = 0

def cont_quantificate(seq_list):
    stored_char = seq_list[0]
    stored_index = 0
    stored_count = 1
    
    ans = []
    
    if len(seq_list)!=1:
        for i in range(1,len(seq_list)):
            
            if seq_list[i] == stored_char:
                stored_count += 1
                
            else:
                if stored_char != "#":
                    ans.extend([stored_count for _ in range(stored_count)])
                    stored_count = 1
                    stored_char = seq_list[i]
                else:
                    ans.extend([0 for _ in range(stored_count)])
                    stored_count = 1
                    stored_char = seq_list[i]
                    
        if stored_char != "#":
            ans.extend([stored_count for _ in range(stored_count)])
        else:
            ans.extend([0 for _ in range(stored_count)]) 
            
        return ans
    else:
        if stored_char != "#":
            ans = [1]
        else:
            ans = [0]
        return ans

#読み込みつつ、横方向の処理
for i in range(H):
    #読み込み
    input_row = str(input())
    input_2d[i] = [input_row[i] for i in range(len(input_row))]
    #横方向で連続している数を求める
    processed_input_2d_w[i] = cont_quantificate(input_row)

print("input")
print(input_2d)
print("横方向")
print(processed_input_2d_w)
    
#縦方向に処理する
for i in range(W):
    #縦方向で連続している数を求める
    processed_input_2d_h[i] = cont_quantificate([row[i] for row in input_2d])
    
print("縦方向")
print(processed_input_2d_h)

#回答を求める
for i in range(H):
    for j in range(W):
        ans[i][j] = processed_input_2d_w[i][j] + processed_input_2d_h[j][i]
        
print(ans)
Problem p03071 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
# スペース区切りの整数の入力
A, B = map(int, input().split())

ans=max((A)+(A-1),A+B,B+(B-1))

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 文字列の入力
S = str(input())

ans=0

if len(S)==1:
  ans=0
elif len(S)==2:
  if S[0]==S[1]:
    ans=1
  else:
    ans=0
else: #3枚以上はちゃんと読み込む
  strint=[]
  original_string=[]
  
  for i in range(len(S)):
    string.append(S[i])
    original_string.append(S[i])
    
  for i in range(len(S)-2):
    gramed = str(string[i])+str(string[i+1])+str(string[i+2])
    
    if gramed=="000":
      string[i+1]="1"
    if gramed=="001":
      string[i]="1"
    if gramed=="011":
      string[i+2]="0"
    if gramed=="110":
      string[i]="0"
    if gramed=="100":
      string[i+2]="1"
    if gramed=="111":
      string[i+1]="1"
  
  #print(string)
  #print(original_string)
  
  for i in range(len(S)):
    if original_string[i]!=string[i]:
      ans=ans+1
  
print(ans)
Problem p03086 (python)

Fixed submission:
S = list(input())
ACGT = set(["A","C","G","T"])
ans = 0
acgt_length = 0

for i in range(len(S)):
  if S[i] in ACGT:
    acgt_length += 1
  else:
    ans = max(ans,acgt_length)
    acgt_length = 0
    
ans = max(ans,acgt_length)

print(ans)

Buggy submission (verdict: Runtime Error):
#122c
N,Q = map(int, input().split())
S = str(input())

for _ in range(Q):
    l,r = map(int, input().split())
    print(S[l-1:r].count('AC'))
Problem p03106 (python)

Fixed submission:
import fractions

# スペース区切りの整数の入力
A,B,K = map(int, input().split())

divisor = fractions.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)

Buggy submission (verdict: Runtime Error):
# スペース区切りの整数の入力
A,B,K = map(int, input().split())

import math

divisor = math.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)

Buggy submission (verdict: Runtime Error):
# スペース区切りの整数の入力
A,B,K = map(int, input().split())

import math

divisor = math.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)
Problem p03125 (python)

Fixed submission:
# スペース区切りの整数の入力
A,B = map(int, input().split())

if B%A==0:
  print(A+B)
else:
  print(B-A)

Buggy submission (verdict: Runtime Error):
# スペース区切りの整数の入力
N,M = map(int, input().split())
A_list=[]
food_list=[]

for i in range(N):
  A_list.append([int(e) for e in input().split()])

for i in range(M):
  food_list.append(0)
  
for i in range(N):
  K=A_list[i][0]
  for j in range(1,K+1):
    #print(A_list[i][j],end="")
    food_list[A_list[i][j]-1]+=1

ans=0
    
for i in range(M):
  if food_list[i]==N:
    ans+=1
    
print(ans)
Problem p03220 (python)

Fixed submission:
N = int(input())
T, A = map(int, input().split())
H_list = [int(e) for e in input().split()]
     
diff=1000000
ans = 0
     
for i in range(len(H_list)):
  if abs(T-H_list[i]*0.006-A)<diff:
    diff = abs(T-H_list[i]*0.006-A)
    ans = i
    
print(ans+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
T, A = map(int, input().split())
H_list = [int(e) for e in input().split()]

diff=1000000
ans = 0

for i in H_list:
	 
    if abs(A-(T−i*0.006)) < diff
    	diff = abs(A-(T−i*0.006))
        ans=i
        
print(ans)
Problem p03239 (python)

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

ans = 10000

for i in range(N):
  c,t = map(int, input().split())
  
  if t<=T and c<ans:
    ans=c

if ans!=10000:
  print(ans)
else:
  print("TLE")

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

min_t = T + 1
ans = "TLE"

for i in range(N):
  c,t = map(int, input().split())
  if t<min_t:
    min_t = t
    ans = c
  elif t==min_t:
    if ans>c:
      ans=c
print(ans)
Problem p03240 (python)

Fixed submission:
N = int(input())

xyh_list = list()

for i in range(N):
    x,y,h = map(int, input().split())
    xyh_list.append((x,y,h))
    
for i in range(N):
    h = xyh_list[i][2]
    if h != 0:
        no_zero_h = i
        break


break_flag = 0

for i in range(0,101):
    for j in range(0,101):
        
        x = xyh_list[no_zero_h][0]
        y = xyh_list[no_zero_h][1]
        h = xyh_list[no_zero_h][2]
        H = h + abs(x-i) + abs(y-j)
        
        if 1 <= H:
            for k in range(0,N):
                x = xyh_list[k][0]
                y = xyh_list[k][1]
                h = xyh_list[k][2]
                
                if (h != 0 and h + abs(x-i) + abs(y-j) != H) or (h == 0 and H - abs(x-i) - abs(y-j) > 0):
                    break
            else:
                print(i,j,H)
                break_flag = 1
                
        if break_flag == 1:
            break
            
    if break_flag == 1:
        break

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

xyh_list = list()

for i in range(N):
    x,y,h = map(int, input().split())
    xyh_list.append((x,y,h))
    
for i in range(N):
    h = xyh_list[i][2]
    if h != 0:
        no_zero_h = i
        break
else:


break_flag = 0

for i in range(0,101):
    for j in range(0,101):
        
        x = xyh_list[no_zero_h][0]
        y = xyh_list[no_zero_h][1]
        h = xyh_list[no_zero_h][2]
        H = h + abs(x-i) + abs(y-j)
        
        if 1 <= H:
            for k in range(0,N):
                x = xyh_list[k][0]
                y = xyh_list[k][1]
                h = xyh_list[k][2]
                
                if h + abs(x-i) + abs(y-j) != H:
                    break
            else:
                print(i,j,H)
                break_flag = 1
                
        if break_flag == 1:
            break
            
    if break_flag == 1:
        break
Problem p03260 (python)

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

if A*B%2==0:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
    A, B = map(int, input().split())
     
    if A*B%2==0:
      print("No")
    else:
      print("Yes")

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

if A*B%2=0:
  print("No")
else:
  print("Yes")
Problem p03379 (python)

Fixed submission:
#094c
import copy
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

sort_X_list = copy.copy(X_list)
sort_X_list.sort(reverse=False)
Bi_smaller = sort_X_list[int(len(X_list)/2-1)]
Bi_bigger = sort_X_list[int(len(X_list)/2)]

for i in range(N):
    if X_list[i]>=Bi_bigger:
        print(Bi_smaller)
    else:
        print(Bi_bigger)

Buggy submission (verdict: Runtime Error):
#094c
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

#l が奇数のとき，l 個の数 a1,a2,...,al の中央値とは，a1,a2,...,al の中で (l+1)/2番目に大きい値のことを言います．
#N個の数 X1,X2,...,XN が与えられます．ここで，N は偶数です． 
#i=1,2,...,N に対して，X1,X2,...,XN から Xi のみを除いたもの，すなわち X1,X2,...,Xi−1,Xi+1,...,XN の中央値を Biとします．
#i=1,2,...,Nに対して，Bi を求めてください．

X_list.sort(reverse=False)
print(X_list)
Bi_smaller = X_list[int(len(X_list)/2)]
Bi_bigger = X_list[int(len(X_list)/2 +1)]

for i in range(int(N/2)):
    print(Bi_bigger)
    
for i in range(int(N/2),N):
    print(Bi_smaller)
Problem p03380 (python)

Fixed submission:
#094d
import math

N = int(input()) #N<10**5
a_list = list(int(e) for e in input().split())
a_tuple = tuple(a_list)

comb_n = max(a_tuple)

a_list.remove(comb_n)
diff = min([abs(comb_n/2 - a) for a in a_list])
a_tuple = tuple(a_list)
if int(comb_n/2 + diff) in a_tuple:
    comb_r = comb_n/2 + diff
elif int(comb_n/2 - diff) in a_tuple:
    comb_r = comb_n/2 - diff  
    
print(int(comb_n),int(comb_r))

Buggy submission (verdict: Runtime Error):
#094d
from scipy.special import comb
from bisect import bisect_left, bisect_right

n = int(input())
a_list = [int(e) for e in input().split()]

#n 個のものから順番を無視して r 個を選ぶ場合の数を comb(n,r) と書くことにします。 
#n 個の非負の整数 a1,a2,...,an から 2 つの数 ai > aj を comb(ai,aj) が最大になるように選んで下さい。 
#最大になる組が複数ある場合、どれを選んでも構いません。

#全組み合わせはn*(n-1)≒10**10 地球爆発

#comb = n*(n-1)*…*(n-r) / r
#from scipy.special import combすれば = comb(n, r, exact=True) で計算可能
#nに最大の値、rにその半分の値(nが奇数なら±0.5)を使った時に大きい値をとることを下記で確認した。
#from scipy.special import comb

#for i in range(101):
#    max_comb = 0
#    max_comb_j = 1 
#    for j in range(1,i):
#        ij_comb = comb(i, j, exact=True) 
#        if ij_comb > max_comb:
#            max_comb = ij_comb
#            max_comb_j = j
#            
#    print(i,max_comb_j,max_comb)


#が、丁度良く半分の値があるとは限らない。
#∴n側は全探索して、rはbisectで半分の値を探る

a_list.sort(reverse=False)

#仮値を入れる
max_comb = comb(a_list[1], a_list[0], exact=True) 
max_comb_ai = a_list[1]
max_comb_aj = a_list[0]

#n側を全探索
for ai in a_list: #10**5
    aj_left = bisect_left(a_list, ai/2) #O(log N)…17回で探れる　∴17*10**5なので間に合いそう
    
    #半分に近い値を算出
    if a_list[aj_left] == ai/2:
        aj_list = [a_list[aj_left]]
    elif a_list[aj_left] < ai/2:
        if aj_left != n-1:
            aj_list = [a_list[aj_left],a_list[aj_left + 1]]
        else:
            aj_list = [a_list[aj_left]]
    elif a_list[aj_left] > ai/2:
        if aj_left != 0:
            aj_list = [a_list[aj_left],a_list[aj_left - 1]]
        else:
            aj_list = [a_list[aj_left]]
    
    #combを計算
    for aj in aj_list:
        temp_comb = comb(ai, aj, exact=True)
        if temp_comb > max_comb:
            max_comb = temp_comb
            max_comb_ai = ai
            max_comb_aj = aj
        
print(max_comb_ai,max_comb_aj)
Problem p03573 (python)

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

if A==B:
    print(C)
elif A==C:
    print(B)
elif B==C:
    print(A)

Buggy submission (verdict: Runtime Error):
#75b
H,W = map(int, input().split())

S_list = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(1,H+1):
    S = list(input())
    S_list[i][1:W+1] = S
    
ans = [["#" for i in range(W+2)] for j in range(H+2)]
    
for i in range(1,H+1):
    for j in range(1,W+1):
        if S_list[i][j] != "#":            
            ans[i][j] = S_list[i-1][j-1:j+2].count("#") + S_list[i][j-1:j+2].count("#") + S_list[i+1][j-1:j+2].count("#")
            
for i in range(1,H+1):
    print(''.join(map(str, ans[i][1:-1])))
Problem p03633 (python)

Fixed submission:
#70c
from functools import reduce
import math
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())

T_set = set()

for _ in range(N):
    t = int(input())
    T_set.add(t)
    
T_list = list(T_set)
print(lcm_list(T_list))

Buggy submission (verdict: Runtime Error):
#70c
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())

T_set = set()

for _ in range(N):
    t = int(input())
    T_set.add(t)
    
T_list = list(T_set)
print(lcm_list(T_list))
Problem p03680 (python)

Fixed submission:
N = int(input())

button_dict = dict()

for i in range(1,N+1):
    button_dict[i] = int(input())

pushed_button_set = set()
i = 1
while 1:
    if i in pushed_button_set:
        print(-1)
        break
    elif i == 2:
        print(len(pushed_button_set))
        break
    else:
        pushed_button_set.add(i)
        i = button_dict[i]

Buggy submission (verdict: Runtime Error):
#065b
N = int(input())
a_list=[0]

for i in range(N):
    ai = int(input())
    a_list.append(ai)

def push_button(pushed_button,pushed_button_set):
	if pushed_button == 2:
		print(len(pushed_button_set))
	else:
		if pushed_button in pushed_button_set:
			print(-1)
			return -1
		else:
			pushed_button_set.add(pushed_button)
			push_button(a_list[pushed_button],pushed_button_set)
			
push_button(1,set())

Buggy submission (verdict: Runtime Error):
#065b
N = int(input())
a_list=[0]

for i in range(N):
    ai = int(input())
    a_list.append(ai)
    
def push_button(pushed_button,ans):
    ans += 1
    #print(ans,":",pushed_button,a_list[pushed_button])
    
    if a_list[pushed_button] == 2:
        return ans
    elif a_list[pushed_button] == pushed_button or pushed_button == a_list[a_list[pushed_button]]:
        return -1
    else:
        ans = push_button(a_list[pushed_button],ans)
        return ans
        
#print(a_list)
print(push_button(1,0))
Problem p03720 (python)

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

town_road = [0 for _ in range(N+2)]

for i in range(M):
    a,b = map(int, input().split())
           
    town_road[a] += 1
    town_road[b] += 1
        
for i in range(1,N+1):
    print(town_road[i])

Buggy submission (verdict: Runtime Error):

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

town_road_dict = {}

for i in range(M):
    a,b = map(int, input().split())
    
    if a not in town_road_dict:
        town_road_dict[a] = [b]
    else:
        town_road_dict[a].append(b)
    if b not in town_road_dict:
        town_road_dict[b] = [a]
    else:
        town_road_dict[b].append(a)
        
for i in range(N):
    print(len(town_road_dict[i+1]))
Problem p03778 (python)

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

if (a <= b <= a+W) or (a <= b+W <= a+W):
    print(0)
else:
    if a+W < b:
        print(abs(b-(a+W)))
    elif b+W < a:
        print(abs(a-(b+W)))

Buggy submission (verdict: Runtime Error):
W,a,b = map(int, input().split())

if (a <= b <= a+W) or (a <= b+W <= a+W) or :
    print(0)
else:
    if a+W < b:
        print(abs(b-(a+W)))
    elif b+W < a:
        print(abs(a-(b+W)))
Problem p03852 (python)

Fixed submission:

Boin=["a","i","u","e","o"]

S = str(input())

if S in Boin:

    print("vowel")

else: 

    print("consonant")

Buggy submission (verdict: Runtime Error):
Boin=["a","i","u","e","o"]
S = str(input())

if S in Boin:
    print(“vowel”)
else:
    print(“consonant”)
Problem p03999 (python)

Fixed submission:
#045c
S = list(input())

#allは2**9=512なので全探索でOK
if len(S)==1:
  print(int(S[0]))
else:
  ans = 0

  for i in range(0,2**(len(S)-1)):
      bit = str(bin(i))[2:].zfill(len(S)-1)
      #print(bit,":",end="") 
      number = int(S[0])

      for j in range(len(bit)):

          if bit[j] == "0":
              number = number*10 + int(S[j+1])
          else:
              #print("+",number,end="")
              ans += number
              number = int(S[j+1])

      #print("+",number)
      ans += number

  print(ans)

Buggy submission (verdict: Runtime Error):
#045c
S = list(input())

#allは2**9=512なので全探索でOK

ans = 0

for i in range(0,2**(len(S)-1)):
    bit = str(bin(i))[2:].zfill(len(S)-1)
    #print(bit,":",end="") 
    number = int(S[0])
    
    for j in range(len(bit)):

        if bit[j] == "0":
            number = number*10 + int(S[j+1])
        else:
            #print("+",number,end="")
            ans += number
            number = int(S[j+1])
            
    #print("+",number)
    ans += number
    
print(ans)
Problem p04019 (python)

Fixed submission:
S = str(input())

if (S.count("N") !=0 and S.count("S") !=0) or (S.count("N") ==0 and S.count("S") ==0):
    if (S.count("W") !=0 and S.count("E") !=0) or (S.count("W") ==0 and S.count("E") ==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

if ((S.count("N") !=0 and S.count("S") !=0) or (S.count("N") ==0 and S.count("S") ==0)) and
   ((S.count("W") !=0 and S.count("E") !=0) or (S.count("W") ==0 and S.count("E") ==0)):
  print("Yes")
else:
  print("No")
Problem p04034 (python)

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(1)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]
red_ball_containable_box = set()
red_ball_containable_box.add(y)

for i in range(M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        red_ball_containable_box.add(y)
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))

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

balls_in_box = [0] + [1 for _ in range(1,N+1)]

#赤玉の初回移動までは捨てる
for i in range(M):
    x,y = map(int, input().split())
    if x == 1:
        red_ball_containable_box = set()
        red_ball_containable_box.add(y)
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        start = i + 1
        break
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

for j in range(start,M):
    x,y = map(int, input().split())
    if x in red_ball_containable_box:
        red_ball_containable_box.add(y)
        balls_in_box[x] -= 1
        balls_in_box[y] += 1
        if balls_in_box[x] == 0: #赤玉が入っている可能性が100％の箱を全部空にすれば確実に移る
            red_ball_containable_box.remove(x)
    else:
        balls_in_box[x] -= 1
        balls_in_box[y] += 1

print(len(red_ball_containable_box))
Problem p02909 (python)

Fixed submission:
s = str(input())
a = ['Sunny', 'Cloudy', 'Rainy','Sunny', 'Cloudy', 'Rainy']
print(a[a.index(s)+1])

Buggy submission (verdict: Runtime Error):
s = input()
a = ['Sunny', 'Cloudy', 'Rainy','Sunny', 'Cloudy', 'Rainy']
print(a[a.index(s)+1]
Problem p02719 (python)

Fixed submission:
N, K = map(int, input().split())
if N == 0:
    print(N)
elif int(K / N) > 1:
    print(N)
else:
    amari = N % K
    mainasu_noatai = abs(amari - K)
    if (amari > mainasu_noatai):
    	print(mainasu_noatai);
    else:
        print(amari)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if (K / N) > 1:
    print(N)
else:
    amari = N % K
    mainasu_noatai = abs(amari - K)
    if (amari > mainasu_noatai):
    	print(mainasu_noatai);
    else:
        print(amari)
Problem p02731 (python)

Fixed submission:
L = int(input())

hen_nagasa = L / 3
print(hen_nagasa ** 3)

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

dic = {}
for num in lis:
    if num in dic:
        dic[num] = dic[num] + 1
    else:
        dic[num] = 1

answer_memo_dic = {}
for key, val in dic.items():
    ans_1 = int(val * (val -1) / 2)
    ans_2 = int((val - 1) * (val - 2) / 2)
    answer_memo_dic[key] = {"ans_1": ans_1, "ans_2": ans_2}

answer_list = []
answer_dic = {}
def answer():
    for n in lis:
        if n in answer_dic:
            answer_list.append(answer_dic[n])
        else:
            answer = 0
            for key, val in answer_memo_dic.items():
                if n == key:
                    answer += val["ans_2"]
                else:
                    answer += val["ans_1"]
            answer_list.append(answer)
            answer_dic[n] = answer

answer()
for a in answer_list:
    print(a)