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

Fixed submission:
def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

N, W = li()
L = [li() for i in range(N)]
V = 10 ** 5
# W <= 10**9 なので、
# dp[i][w]: i番目の選択で重さwだった時の価値の最大値、は計算量厳しい
# dp[i][v]: i番目の選択で価値vだった時の重さの最小値、で考えて重さの最小値がW以下のものから最大価値を算出する

dp = [[INF] * (V+1) for _ in range(N)]

# 初期条件
# 選ばない
dp[0][0] = 0
# 選ぶ
w0, v0 = L[0]
dp[0][v0] = w0

for i in range(1, N):
    for v in range(V+1):
        cw, cv = L[i]
        # 選ばない
        dp[i][v] = min(dp[i][v], dp[i-1][v])
        # 選ぶ
        if v + cv > V:
            continue
        dp[i][v+cv] = min(dp[i][v+cv], dp[i-1][v] + cw)

# 重さの最小値がW以下で達成できるvの最大値
v_max = 0
for v in range(V+1):
    if dp[N-1][v] <= W:
        v_max = v
print(v_max)

Buggy submission (verdict: Runtime Error):
def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

N, W = li()
L = [li() for i in range(N)]
V = 1000
# W <= 10**9 なので、
# dp[i][w]: i番目の選択で重さwだった時の価値の最大値、は計算量厳しい
# dp[i][v]: i番目の選択で価値vだった時の重さの最小値、で考えて重さの最小値がW以下のものから最大価値を算出する

dp = [[INF] * V for _ in range(N)]

# 初期条件
# 選ばない
dp[0][0] = 0
# 選ぶ
w0, v0 = L[0]
dp[0][v0] = w0

for i in range(1, N):
    for v in range(V):
        cw, cv = L[i]
        # 選ばない
        dp[i][v] = min(dp[i][v], dp[i-1][v])
        # 選ぶ
        if v + cv >= V:
            continue
        dp[i][v+cv] = min(dp[i][v+cv], dp[i-1][v] + cw)

# 重さの最小値がW以下で達成できるvの最大値
v_max = 0
for v in range(V):
    if dp[N-1][v] <= W:
        v_max = v
print(v_max)
Problem p03166 (python)

Fixed submission:
def li():
    return [int(x) for x in input().split()]

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5 + 100)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)

Buggy submission (verdict: Runtime Error):
def li():
    return [int(x) for x in input().split()]

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)
Problem p02612 (python)

Fixed submission:
n = int(input())
print((1000 - (n % 1000)) % 1000)

Buggy submission (verdict: Runtime Error):
n = int(input)
print((1000 - (n % 1000)) % 1000)
Problem p02618 (python)

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = []
N = 26
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [d%N for d in range(D)]
for d in range(D):
  print(myans[d]+1)

Buggy submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = []
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [i for i in range(26)]
#print(myans)

def estimate(mylist):
    mycost = 0
    dayflag = [0 for n in range(26)]
    for d in range(1,D+1):
        mycontest = mylist[d-1]
        mycost += S[d-1][mycontest]
        dayflag[mycontest] = d
        #print(mycontest, d, dayflag)
        for i in range(26):
             mycost -= C[mycontest] * (d - dayflag[i])
    return mycost

import random
import copy
times = 10**4
bestcost = 0
random.seed(1)
for i in range(times):
    a = random.randrange(26)
    b = random.randrange(26)
    mylist = copy.deepcopy(myans)
    #print(a,b, mylist)
    mylist[a] = myans[b]
    mylist[b] = myans[a]
    #print(mylist)
    #estimate
    mycost = estimate(mylist)
    if  bestcost < mycost:
        bestcost = mycost
        myans = mylist
        #print(i, bestcost)
for d in range(D):
    print(myans[d]+1)

Buggy submission (verdict: Runtime Error):


D = int(input())
C = list(map(int, input().split()))
S = []
for d in range(D):
    S += [list(map(int, input().split()))]
#print(C)
#print(S)
myans = [i for i in range(26)]
#print(myans)

def estimate(mylist):
    mycost = 0
    dayflag = [0 for n in range(26)]
    for d in range(1,D+1):
        mycontest = mylist[d-1]
        mycost += S[d-1][mycontest]
        dayflag[mycontest] = d
        #print(mycontest, d, dayflag)
        for i in range(26):
             mycost -= C[mycontest] * (d - dayflag[i])
    return mycost

import random
import copy
times = 10**4
bestcost = 0
random.seed(1)
for i in range(times):
    a = random.randrange(26)
    b = random.randrange(26)
    mylist = copy.deepcopy(myans)
    #print(a,b, mylist)
    mylist[a] = myans[b]
    mylist[b] = myans[a]
    #print(mylist)
    #estimate
    mycost = estimate(mylist)
    if  bestcost < mycost:
        bestcost = mycost
        myans = mylist
        #print(i, bestcost)
for d in range(D):
    print(myans[d])
Problem p02684 (python)

Fixed submission:
N, K = map(int, input().split())
mylist =   [0] + list(map(int,input().split()))
#print(mylist)
flag_list = [float('INF') for n in range(N+1)]
#print(flag_list)
myseries = []

myflag = 0
mypos = 1
mycnt = 0 
while myflag == 0:
    if flag_list[mypos] == float('INF'):
        flag_list[mypos] = mycnt
        #print(mypos)
        myseries.append(mypos)
        mypos = mylist[mypos]
        mycnt += 1
    else:
        myflag = 1
        mystart = flag_list[mypos]
        mylen = mycnt-mystart
#print(flag_list)
#print(myseries)
#print(mystart, mylen)

if K < mystart:
    print(myseries[K])
else:
    print(myseries[(K-mystart)%mylen + mystart])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N, K = map(int, input().split())


mylist =  [0] + list(map(int,input().split()))
#print(mylist)

myflag = [0 for n in range(N+1)]
#print(myflag)

myorigine = []
mypos = 1
for n in range(1,N+1):
    if myflag[n] == 0:
        myflag[n] == 1
        myorigine.append(mypos)
        mypos = mylist[mypos]
    elif myflag[n] == 1:
        break
#print(myorigine)
    
mypos = 0
while myorigine[mypos] != myorigine[-1]:
    mypos += 1
#print(mypos)
origin1 = myorigine[:mypos]
origin2 = myorigine[mypos:]
#print(origin1, origin2[:-1])


mymod = K%N
mymod = len(origin1) -1
print(origin2[mymod-1])
Problem p02687 (python)

Fixed submission:
S = input()
 
if S == 'ABC':
    print('ARC')
else:
    print('ABC')

Buggy submission (verdict: Runtime Error):
S = input()
 
if S = 'ABC':
    print('ARC')
else:
    print('ABC')
Problem p02714 (python)

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

ans = S.count('R')*S.count('G')*S.count('B')

for i in range(N-2):
    for j in range(i+1,N-1):
        k = j-i + j
        if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1

print(ans)

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

ans = S.count('R')*S.count('G')*S.count('B')
for i in range(n-2):
  for j in range(i+1,n-1):
    k = j+1
    if k < n and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      ans -= 1
print(ans)
Problem p02791 (python)

Fixed submission:
N = int(input())


mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

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

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

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

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 0
mymin = 99999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

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

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 0
mymin = 9999999
for i in range(N):
    if mylist[i] < mymin:
        mymin = mylist[i]
        myans += 1
        
print(myans)

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

if N == 1:
    print(1)
    sys.exit()

mylist = list(map(int, input().split()))


myans = 1
minn = mylist[0]
for i in range(N):
    if mylist[i] < minn:
        minn = mylist[i]
        myans += 1
    else:
        minn = mylist[i]
        
print(myans)
Problem p02866 (python)

Fixed submission:
mod = 998244353
 
N = int(input())
D = [int(x) for x in input().split()]
 
dep = max(D)
dict = [0]*(dep+1)

#print(dict)
 
for d in D:
    dict[d]+=1
#print(dict)
if(dict[0]!=1 or D[0]!=0):
    ans = 0
else:
    ans = 1
    for de in range(1,dep+1):
        ans *= (dict[de-1]**dict[de])%mod
        #print(ans)
        ans %= mod
print(ans)

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

D= list(map(int, input().split()))

mydic = {}
myans = 0

for i in D:
    if i in mydic:
        mydic[i] += 1
    else:
        mydic[i] = 1

#dicsorted = sorted(mydic.items())

myans = 1

if 0 not in mydic:
    print(0)
else:
    for i in range(len(mydic)):
        if i ==0:
            i = 1
        myans = myans * (i**mydic[i])
    print(myans%998244353)
Problem p02909 (python)

Fixed submission:
mys = input()
 
if mys == 'Sunny':
  print('Cloudy')

elif mys == 'Cloudy':
  print('Rainy')

elif mys == 'Rainy':
  print('Sunny')

Buggy submission (verdict: Runtime Error):


mys = input()

if mys = 'Sunny':
  print('Cloudy')

elif mys = 'Cloudy':
  print('Rainy')

elif mys = 'Rainy':
  print('Sunny')
Problem p02953 (python)

Fixed submission:
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))
H[0] -= 1
for i in range(0, N - 1):
    diff = H[i + 1] - H[i]
    if diff >= 1:
        H[i + 1] -= 1
    elif diff < 0:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
for i in range(0, n - 1):
    diff = H[i + 1] - H[i]
    if diff >= 1:
        H[i + 1] -= 1
    elif diff < 0:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())

mylist = list(input().split())

for i in range(N-1):
     
    if int(mylist[i+1]) >= int(mylist[i])-1 :
        continue

    else:
        print('No')
        sye.exit()


print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())

mylist = list(input().split())


for i in range(N-1):
     
    if int(mylist[i+1]) == int(mylist[i]) or int(mylist[i+1]) > int(mylist[i]):
        continue
    elif int(mylist[i+1]) == (int(mylist[i]) -1):
        continue
    else:
        print('No')
        sye.exit()
    
    


print('Yes')
Problem p02996 (python)

Fixed submission:
import sys

N = int(input())
mylist=[]

for i in range(N):
  s = input().split()
  mylist += [[int(s[0]),int(s[1])]]

mylsit = sorted(mylist, key=lambda x:x[1])

mysum = 0
for i in mylsit:
  mysum += i[0]
  if mysum <= i[1]:
    continue
  else:
    print('No')
    sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720
Problem p03005 (python)

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

if N < K or K==1:
  print(0)
else:
  print(N-K)

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

x = []
sub_x=[]
sub_y=[]

for i in range(N):
  x.append(list(map(int, input().split())))
  
x.sort()
for i in range(len(x)-1,0, -1):
  mysub_x = [(x[i][0] - x[i-1][0])]
  mysub_y = [(x[i][1] - x[i-1][1])]
  if mysub_x != [0]:
    sub_x += mysub_x
  if mysub_y != [0]:
    sub_y += mysub_y
p = statistics.mode(sub_x)
q = statistics.mode(sub_y)

ans = 0
for i in range(N-1):
    if abs(x[i][0] - x[i+1][0]) != abs(p) or abs(x[i][1] - x[i+1][1]) != abs(q):
      ans += 1
if ans == 0:
  print(1)
else:
  print(ans)
Problem p03006 (python)

Fixed submission:
N = int(input())
xy_list = []
ans = []
 
for i in range(N):
    x,y = map(int,input().split())
    xy_list.append([x,y])

if N==1:
    print(1)
    exit(0)
xy_list.sort(key=lambda x:x[1]) #yの値でソート
xy_list.sort(key=lambda x:x[0]) #xの値でソート
#print(xy_list)
#差をすべて調べる
for i in range(N):
  for j in range(N):
    if( i==j ):     #xとyの重複はなし
      continue
    t = (xy_list[i][0]-xy_list[j][0],xy_list[i][1]-xy_list[j][1])
    ans.append(t)
    #print(ans)  
#差の種類ごとの個数を調べる
res = [ans.count(e) for e in set(ans)]
#Nから一番多かった差の個数を引いたものが答え
print(N-max(res))

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

x = []
sub_x=[]
sub_y=[]


for i in range(N):
  x.append(list(map(int, input().split())))
  
x.sort()
#y.sort()
for i in range(len(x)-1,0, -1):
  mysub_x = [(x[i][0] - x[i-1][0])]
  mysub_y = [(x[i][1] - x[i-1][1])]
  if mysub_x != [0]:
    sub_x += mysub_x
  if mysub_y != [0]:
    sub_y += mysub_y


p = statistics.mode(sub_x)
#print(sub_x, p)
q = statistics.mode(sub_y)

ans = 0
for i in range(N-1):
    if abs(x[i][0] - x[i+1][0]) != abs(p) or abs(x[i][1] - x[i+1][1]) != abs(q):
      #print('dif')
      #print(ans, i)
      ans += 1

if ans == 0:
  print(1)
else:
  print(ans)
Problem p03014 (python)

Fixed submission:
import numpy as np
 
H, W = map(int, input().split())
#mapの入力
mymap = [] 
for i in range(H):
    mymap.append(list(input()))

#探索可能性をブーリアン表記
mymap = (np.array(mymap) == ".")
  
L = np.zeros((H, W), dtype=int) #左側から探索した場合の配列
R = np.zeros((H, W), dtype=int) #右側から探索した場合の配列
U = np.zeros((H, W), dtype=int) #上側から探索した場合の配列
D = np.zeros((H, W), dtype=int) #下側から探索した場合の配列

#列ごとに左から
for j in range(W):
  if j == 0: #左端
    L[:, j] = mymap[:, j] #true = 1, false = 0
  else:
    L[:, j] = (L[:, j - 1] + 1) * mymap[:, j] #trueの場合は1つ左の列の値を加算しながら

#列ごとに右から
for j in range(W - 1, -1, -1): #(引数：開始数，終了数，加算数）
  if j >= W - 1: #右端
    R[:, j] = mymap[:, j]
  else:
    R[:, j] = (R[:, j + 1] + 1) * mymap[:, j] 

#行ごとに上から
for i in range(H):
  if i <= 0: #上端
    U[i, :] = mymap[i, :]
  else:
    U[i, :] = (U[i - 1, :] + 1) * mymap[i, :]

#行ごとに下から
for i in range(H - 1, -1, -1):
  if i >= H - 1: #下端
    D[i, :] = mymap[i, :]
  else:
    D[i, :] = (D[i + 1, :] + 1) * mymap[i, :]

#総和から重複分(=3)の差をとって，最大値を出力
print(np.max(L + R + U + D - 3))

Buggy submission (verdict: Runtime Error):
#入力部
H, W = [int(i) for i in input().split()]

mymap = [] 　#mapの配列
myansmap = list(list(-1 for a in range(W)) for b in range(H))　#列方向を探索配列
myansmap2 = list(list(-1 for a in range(W)) for b in range(H))　#行方向を探索配列

#入力しながら，列方向を探索する
for i in range(H):
  myinput =  input()
  for j in range(W):
    if myinput[j] == '#':
      myansmap[i][j] = 0
    elif myinput[j] == '.':
      if myansmap [i][j] == -1 :
        mycnt = 0
        for m in range(j,W):
          if myinput[m] == '#':
            break
          mycnt += 1
      for k in range(j, m+1):
        myansmap[i][k] = mycnt
  mymap.append(myinput)

mymax = -99　#出力用変数

#行方向を探索する
for i in range(H):
  for j in range(W):
    #探索していない箇所について
    if myansmap2 [i][j] == -1:
      mycnt = 0
      for m in range(i,H):
        if myansmap[m][j] == 0:
          break
        mycnt += 1
      for k in range(i, m+1):
        if i > 0 and i < H or  j > 0 and i < W:
          myansmap2[k][j] = mycnt
        else: 
          myansmap2[k][j] = mycnt
    if myansmap[i][j] == 0:
      myansmap2[i][j] = 0

      
    if mymax < myansmap[i][j] + myansmap2[i][j]:
      mymax=myansmap[i][j] + myansmap2[i][j]

print(mymax-1)
Problem p02727 (python)

Fixed submission:
import heapq

X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = list(map(int, input().split()))

Red = p[:X]
Green = q[:Y]

h = sorted(Red + Green)
heapq.heapify(h)
for i in r:
    heapq.heappushpop(h, i)
print(sum(h))

Buggy submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

Red = p[:X]
Green = q[:Y]

Apple = sorted(Red + Green)
for i in range(C):
    print(Apple[i], r[i])
    if Apple[i] < r[i]:
        Apple[i] = r[i]
print(sum(Apple))
Problem p02982 (python)

Fixed submission:
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dis = 0
        for d in range(D):
            dis += (X[i][d] - X[j][d])**2
        if math.sqrt(dis) == int(math.sqrt(dis)):
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
mport math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = 0
        for d in range(D):
            dis += (X[i][d] - X[j][d])**2
        if math.sqrt(dis) == int(math.sqrt(dis)):
            cnt += 1

print(cnt)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
mod = 2019

if R - L >= 2018:
    print(0)
elif R - L == 1:
    print(((L % mod) * (R % mod)) % mod)
else:
    m = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            m = min(m, ((i % mod) * (j % mod)) % mod)
    print(m)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
mod = 2019

lmod = L % mod
rmod = R % mod

if lmod <= rmod:
    list_ij = sorted(list(range(lmod, rmod + 1)))
    print(list_ij[0] * list_ij[1])
else:
    list_ij = sorted(list(range(lmod, rmod + 1)))
    print(list_ij[0] * list_ij[1])
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())
L = [0 for _ in range(M)]
R = [0 for _ in range(M)]
for i in range(M):
    L[i], R[i] = map(int, input().split())

l = max(L)
r = min(R)
print(r - l + 1 if l <= r else 0)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    x, y = [int(i) for i in input().split()]
    L.append(x)
    R.append(y)
id = []
for i in range(M):
    id += [L[i:] + R[:i + 1]]
com = set(id[0]) & set(id[1])
for j in range(1, M):
    com = com & set(id[j])
print(len(com))
Problem p03282 (python)

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

ans = 1
for i in range(K):
    if S[i] != "1":
        ans = int(S[i])
        break
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

if S[0] == "1":
    print(S[1])
else:
    print(S[0])
Problem p03310 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
S = [0]
for a in A:
    S += [S[-1] + a]

ans = float("inf")
l = 0
r = 2
for i in range(1, N - 1):
    while S[l] < S[i] - S[l + 1]:
        l += 1
    while S[r] - S[i] < S[N] - S[r + 1]:
        r += 1

    a = S[l]
    b = S[i] - S[l]
    c = S[r] - S[i]
    d = S[N] - S[r]

    ans = min(ans, max(a, b, c, d) - min(a, b, c, d))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

N = int(input())
A = np.array(input().split(), np.int64)
A_cum = [0] + np.cumsum(A)

ans = 10**10
l = 0
r = 2
for i in range(1, N - 1):
    while A[l] < A[i] - A[l + 1]:
        l += 1
    while A[r] - A[i] < A[-1] - A[r + 1]:
        r += 1
    P = A[l]
    Q = A[i] - A[l]
    R = A[r] - A[i]
    S = A[-1] - A[r]
    tmp = max(P, Q, R, S) - min(P, Q, R, S)
    ans = min(ans, tmp)
print(ans)
Problem p03495 (python)

Fixed submission:
import collections

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

c = collections.Counter(A)
n = len(c)
c_sorted = sorted(c.values())
cnt = 0
for i in range(max(0, n - K)):
    cnt += c_sorted[i]
print(cnt)

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

c = [0] * N
for i in range(N):
    c[i] = A.count(i + 1)
c = sorted(c)

n = len(c)
if n - K > 0:
    cnt = sum(c[:n - K])
print(cnt)
Problem p03563 (python)

Fixed submission:
R = int(input())
G = int(input())

print(2 * G - R)

Buggy submission (verdict: Runtime Error):
R, G = map(int, input().split())

print(2 * G - R)
Problem p03612 (python)

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
p.insert(0, -1)

j = [0] * (N + 1)
for i in range(1, N + 1):
    if p[i] == i and j[i - 1] == 0:
        j[i] = 1
print(sum(j))

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
p.insert(0, -1)

j = [0] * N
for i in range(1, N + 1):
    if p[i] == i and j[i - 1] == 0:
        j[i] = 1
print(sum(j))
Problem p03633 (python)

Fixed submission:
import math
from functools import reduce

N = int(input())
T = [int(input()) for i in range(N)]

# def gcd(numbers):  # "numbers" is list
#     return reduce(math.gcd, numbers)

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


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


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


def lcm(numbers):  # "numbers" is list
    return reduce(lcm_base, numbers,
                  1)  # [third argument] return 1 if "numbers" is empty


print(lcm(T))

Buggy submission (verdict: Runtime Error):
import math
from fractions import gcd
from functools import reduce

N = int(input())
T = [int(input()) for i in range(N)]


def gcd(numbers):  # "numbers" is list
    return reduce(gcd, numbers, 1)


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


def lcm(numbers):  # "numbers" is list
    return reduce(lcm_base, numbers,
                  1)  # [third argument] return 1 if "numbers" is empty


print(lcm(T))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
T = [int(input()) for i in range(N)]


def gcd(numbers):  # "numbers" is list
    return reduce(math.gcd, numbers,1)


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


def lcm(numbers):  # "numbers" is list
    return reduce(lcm_base, numbers,
                  1)  # [third argument] return 1 if "numbers" is empty


print(lcm(T))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
T = [int(input()) for i in range(N)]


def gcd(numbers):  # "numbers" is list
    return reduce(math.gcd, numbers)


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


def lcm(numbers):  # "numbers" is list
    return reduce(lcm_base, numbers,
                  1)  # [third argument] return 1 if "numbers" is empty


print(lcm(T))
Problem p03645 (python)

Fixed submission:
N, M = map(int, input().split())
L = []
for _ in range(M):
    L.append(list(map(int, input().split())))

first = []
second = []
for a, b in L:
    if a == 1:
        first.append(b)
    if b == N:
        second.append(a)
flg = len(set(first) & set(second))
print('POSSIBLE' if flg else 'IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
L = []
for _ in range(M):
    L.append(list(map(int, input().split())))

first = []
second = []
for a, b in L:
    if a == 1:
        first.append(b)
    if b == N:
        second.append(a)
print('POSSIBLE' if set(first) & set(second) else 'IMPOSSIBLE')
Problem p03860 (python)

Fixed submission:
[print(i[0], end="") for i in input().split()]
print()

Buggy submission (verdict: Runtime Error):
a, b, c = str(input().split())
print(a[0], b[0], c[0])