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

Fixed submission:
import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return deque(lis[:now+1] + [item] + lis[now+1:])
  

C = sum(cut)
res = min(K - C, N)
length = length[:res+1]
length = deque(length)
for k in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    length.append(a)
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(list(length), list(a))
  length.pop()

print(math.ceil(length.popleft()[0]))

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S + 1)

length = []
after = []
for k in range(N):
  length.append(A[k] / (cut[k]+1))
  after.append([A[k] / cut[k], k])
after.sort(key = lambda x: x[0])

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] < item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return lis[:now+1] + [item] + lis[now+1:]
  

C = sum(cut)
res = C - K
after = after[:res+1]
for _ in range(res):
  while cut[after[0][1]] == 0:
    after = after[1:]
  cut[after[0][1]] -= 1
  length[after[0][1]] = 0 + after[0][0]
  after[0][0] *= (cut[after[0][1]]+2)/(cut[after[0][1]]+1)
  if after[0][0] > after[1][0]:
    after = nibun_insert(after[1:], after[0])

length.sort()  
print(math.ceil(length[-1]))
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

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

a = 0
b = 0
ans = 0
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    if AA[k] <= K:
        for j in range(M, -1, -1):
            if  AA[k] + BB[j+1]> K >= AA[k] + BB[j]:
                ans = max(k+j, ans)
                break
            else:
                continue
        if K >= AA[k] + BB[M]:
            ans = max(k+M, ans)
    else:
        break
print(ans)

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

a = 0
b = 0
ans = 0
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    if AA[k] <= K:
        for j in range(M+1):
            if  AA[k] + BB[j+1]> K >= AA[k] + BB[j]:
                ans = max(k+j, ans)
                break
            else:
                continue
    else:
        break
print(ans)

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

L = [float("inf") for _ in range(N+M+1)]
L[0] = 0

a = 0
b = 0
ans = 0
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    for j in range(ans-k, M+1):
        if  K >= AA[k] + BB[j]:
            ans = max(k+j, ans)
            continue
        else:
            break
print(ans)
Problem p02685 (python)

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

inv = [0,1]
for i in range(2, N):
  inv.append((-inv[mod%i]*(mod//i))%mod)

if N == 1:
  print(M)
  exit()

m = [1]
s = 1
for _ in range(N-1):
  s = s*(M-1)%mod
  m.append(s)

ncombi = [1]
c = 1
for k in range(K):
  c = c*(N-1-k)*inv[k+1]
  c %= mod
  ncombi.append(c)

ans = 0
for k in range(K+1):
  ans = ans + m[-k -1]*ncombi[k]
  ans %= mod

ans = ans*M%mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N, M, K = map(int, input().split())
mod = 998244353

m = [1, M]
k = M
for _ in range(1, N+1):
  k = k*(M-1)%mod
  m.append(k)
ans = []


def solve(now, pairs, colors):
  if now == N:
    ans.append(m[colors])
    return 0
  elif pairs == K:
    colors += N - now
    ans.append(m[colors])
    return 0
  else:
    solve(now+1, pairs+1, colors)
    solve(now+1, pairs, colors+1)


solve(1, 0, 1)


#print(ans)
a = 0
for _ in range(len(ans)):
  a += ans[_]
  a %= mod
print(a)
Problem p02689 (python)

Fixed submission:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0 for k in range(M)]
B = [0 for k in range(M)]

for k in range(M):
    A[k], B[k] = map(int, input().split())
    A[k] -= 1
    B[k] -= 1
good = [1 for k in range(N)]

for k in range(M):
    if H[A[k]] <= H[B[k]]:
        good[A[k]] = 0
    if H[A[k]] >= H[B[k]]:
        good[B[k]] = 0   
        '''
for k in range(N):
    if good[k] ==1:
        if k in A:
            for j in range(M):
                if k == A[j] and H[k]<=H[B[j]]:
                    good[k] = 0
                if k == A[j] and H[k]>=H[B[j]]:
                    good[B[j]] = 0
        if k in B:
            for j in range(M):
                if k == B[j] and H[k]<=H[A[j]]:
                    good[k] = 0
                if k == B[j] and H[k]>=H[A[j]]:
                    good[A[j]] = 0
'''
print(sum(good))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0 for k in range(M)]
B = [0 for k in range(M)]

for k in range(M):
    A[k], B[k] = map(int, input().split())
    A[k] -= 1
    B[k] -=1
good = [1 for k in range(N)]
C = A.append(B)
for k in A:
    if good[k] ==1:

        for j in range(M):
            if k == A[j] and H[k]<=H[B[j]]:
                good[k] = 0
            if k == A[j] and H[k]>=H[B[j]]:
                good[B[j]] = 0
            if k == B[j] and H[k]<=H[A[j]]:
                good[k] = 0
            if k == B[j] and H[k]>=H[A[j]]:
                good[A[j]] = 0
for k in B:
    if good[k] ==1:

        for j in range(M):
            if k == A[j] and H[k]<=H[B[j]]:
                good[k] = 0
            if k == A[j] and H[k]>=H[B[j]]:
                good[B[j]] = 0
            if k == B[j] and H[k]<=H[A[j]]:
                good[k] = 0
            if k == B[j] and H[k]>=H[A[j]]:
                good[A[j]] = 0        
        

print(sum(good))
Problem p02695 (python)

Fixed submission:
N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
  a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]

def point(A):
  p = 0
  for ai, bi, ci, di in zip(a, b, c, d):
    if A[bi-1] - A[ai-1] == ci:
      p += di
  return p

def next(A):
  k = 1
  while k < N+1:
    if A[-k] < M:
      A[-k] += 1
      return A
      break
    else:
      for j in range(1, k+1):
        A[-j] = A[-k-1] + 1
      k += 1

ans = point([M for _ in range(N)])
while A[0] < M:
  ans = max(ans, point(A))
  A = next(A)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
a = [0 for _ in range(Q)]
b = [0 for _ in range(Q)]
c = [0 for _ in range(Q)]
d = [0 for _ in range(Q)]
for k in range(Q):
  a[k], b[k], c[k], d[k] = map(int, input().split())
A = [1 for _ in range(N)]

def point(A):
  p = 0
  for ai, bi, ci, di in zip(a, b, c, d):
    if A[bi-1] - A[ai-1] == ci:
      p += di
  return p

def next(A):
  k = 1
  while k < N+1:
    if A[-k] < M:
      A[-k] += 1
      return A
      break
    else:
      for j in range(1, k+1):
        A[-j] = A[-k-1] + 1
      k += 1
      
ans = max(ans, point([M for _ in range(N)]))
while A[0] < M:
  ans = max(ans, point(A))
  A = next(A)
print(ans)
Problem p02753 (python)

Fixed submission:
s = input()
if s.count('A') == 0 or s.count('B') == 0:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()
sgn = 1
Q = int(input())
ans = []
for _ in range(Q):
  i = input()
  if i[0] == '1':
    sgn*=-1
  else:
    if i[2] == '1':
      ans.append([i[4], -sgn])
    else:
      ans.append([i[4], sgn])

if sgn == -1:
  s = s[::-1]
  for k in range(len(ans)):
    if ans[k][1] == -1:
      s = s + ans[k][0]
    else:
      s = ans[k][0] + s
else:
  for k in range(len(ans)):
    if ans[k][1] == 1:
      s = s + ans[k][0]
    else:
      s = ans[k][0] + s

print(s)
Problem p02793 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
a = max(A)
prime_num = [2]
sgn = [0 for _ in range(max(int(a**0.5)+1, 4))]
sgn[2] = 1
for k in range(3, len(sgn), 2):
  if sgn[k] == 0:
    prime_num.append(k)
    for j in range(k, a+1, 2*k):
      sgn[k] = 1
baisu = []
count = [0 for _ in range(a+1)]
for k in range(N):
  b = 0 + A[k]
  for p in prime_num:
    if p**2 <= b:
      if b%p == 0:
        if count[p] == 0:
          baisu.append(p)
        c = 0
        while b % p == 0:
          b //= p 
          c += 1 
        if c > count[p]:
          count[p] = c
    else:
      break
  if b != 1:
    if count[b] == 0:
      count[b] = 1
      baisu.append(b)

product = 1
for item in baisu:
  product *= pow(item, count[item], mod)
  product %= mod

b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

ans = 0
for k in range(N):
  ans += product*modinv(A[k])
  ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
a = max(A)
prime_num = [2]
count = [0 for _ in range(a+1)]
count[2] = 1
for k in range(3, a+1, 2):
  if count[k] == 0:
    count[k] = 1
    prime_num.append(k)
    for j in range(k, a+1, k):
      count[k] = 1
baisu = []
count = [0 for _ in range(a+1)]
for k in range(N):
  b = 0 + A[k]
  for p in prime_num:
    if p**2 <= b:
      if count[p] == 0 and b%p == 0:
        baisu.append(p)
      c = 0
      while b % p == 0:
        b //= p 
        c += 1 
      if c > count[p]:
        count[p] = c
    else:
      break
  if b != 1:
    if count[b] == 0:
      count[b] = 1
      baisu.append(b)

product = 1
for item in baisu:
  product *= pow(item, count[item], mod)
  product %= mod

b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

ans = 0
for k in range(N):
  ans += product*modinv(A[k])
  ans %= mod

print(ans)
Problem p02859 (python)

Fixed submission:
r = int(input())
print(r**2)

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int,input().split())
ans = []
flag = True
cnt = 0
while True:
  if A < 0 or B < 0 or C < 0:
    flag = False
    break
  cnt += 1
  if cnt > N:
    break
  s = input()
  if s == 'AB':
    if A == B == 1:
      cnt += 1
      if cnt > N:
        ans.append('A')
        break
      else:
        s = input()
        if s == 'AB':
          ans.append('A')
          ans.append('B')
          continue
        elif s == 'AC':
          ans.append('A')
          ans.append('C')
          B -= 1
          C += 1
          continue
        else:
          ans.append('B')
          ans.append('C')
          A -= 1
          C += 1
          continue
    elif A >= B:
      A -= 1
      B += 1
      ans.append('B')
      continue
    else:
      B -= 1
      A += 1
      ans.append('A')
      continue
  elif s == 'BC':
    if B == C == 1:
      cnt += 1
      if cnt > N:
        ans.append('B')
        break
      else:
        s = input()
        if s == 'BC':
          ans.append('B')
          ans.append('C')
          continue
        elif s == 'AB':
          ans.append('B')
          ans.append('A')
          B -= 1
          A += 1
          continue
        else:
          ans.append('C')
          ans.append('A')
          C -= 1
          A += 1
          continue
    elif B >= C:
      B -= 1
      C += 1
      ans.append('C')
      continue
    else:
      C -= 1
      B += 1
      ans.append('B')
      continue 
  else:
    if C == A == 1:
      cnt += 1
      if cnt > N:
        ans.append('C')
        break
      else:
        s = input()
        if s == 'AC':
          ans.append('C')
          ans.append('A')
          continue
        elif s == 'BC':
          ans.append('C')
          ans.append('B')
          A -= 1
          B += 1
          continue
        else:
          ans.append('A')
          ans.append('B')
          C -= 1
          B += 1
          continue
    elif A >= C:
      A -= 1
      C += 1
      ans.append('C')
      continue
    else:
      C -= 1
      A += 1
      ans.append('A')
      continue
if flag:
  print('Yes')
  for item in ans:
    print(item)
else:
  print('No')
Problem p03806 (python)

Fixed submission:
N,Ma,Mb=map(int,input().split())
a=[0 for k in range(N)]
b=[0 for k in range(N)]
c=[0 for k in range(N)]
import copy
for k in range(N):
    a[k],b[k],c[k]=map(int,input().split())
Sa=sum(a)
Sb=sum(b)
dp =[[[5000 for k in range(Sb+1)]for k in range(Sa+1)]for k in range(N+1)]
dp[0][0][0]=0
for k in range(N):
    listj=[]
    listl=[]
    for j in range(Sa-a[k]+1):
        for l in range(Sb-b[k]+1):
            if dp[k][j][l]!=5000:
                listj.append(j)
                listl.append(l)
    for m in range(len(listl)):
        dp[k+1][listj[m]+a[k]][listl[m]+b[k]]=min(dp[k][listj[m]][listl[m]]+c[k], dp[k][listj[m]+a[k]][listl[m]+b[k]])
        dp[k+1][listj[m]][listl[m]]=min(dp[k][listj[m]][listl[m]], dp[k+1][listj[m]][listl[m]])
ans=[5000]
for k in range(1, min(Sa//Ma,Sb//Mb)+1):
    ans.append(dp[-1][Ma*k][Mb*k])
if min(ans)==5000:
    print(-1)
else:
    print(min(ans))

Buggy submission (verdict: Runtime Error):
N,Ma,Mb=map(int,input().split())
a=[0 for k in range(N)]
b=[0 for k in range(N)]
c=[0 for k in range(N)]

for k in range(N):
    a[k],b[k],c[k]=map(int,input().split())
Sa=sum(a)
Sb=sum(b)
dp =[[5000 for k in range(Sb+1)]for k in range(Sa+1)]
dp[0][0]=0
for k in range(N):
    for j in range(Sa-a[k]+1):
        for l in range(Sb-b[k]+1):
            dp[j+a[k]][l+b[k]]=min(dp[j][l]+c[k], dp[j+a[k]][l+b[k]])

ans=[5000]
for k in range(1, max(sum(a)//Mb,sum(b)//Ma)+1):
    ans.append(dp[Mb*k][Ma*k])
if min(ans)==5000:
    print(-1)
else:
    print(min(ans))
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()

if a < 3200:
  print("red")
else:
  print(s)

Buggy submission (verdict: Runtime Error):
#include<iostream>
#include<string>
using namespace std;

int main(){
    int i;
    string s;
    cin >> i;
    cin >> s;
    if(i < 32000){
        cout << "red" << endl;
    }
    else{
        cout << s << endl;
    }
}
Problem p02550 (python)

Fixed submission:
# 繰り返しの始まり + 繰り返し + 途中で終わった繰り返し分
N,X,M = map(int,input().split())
p = [0] * (M+2)
sum = [0] * (M+2)
p[X] = 1
sum[1] = X

repeat_start = 0
repeat_end = 0

for i in range(2,N+1):
  X = (X**2) % M
  if p[X] != 0:
    repeat_start = p[X]
    repeat_end = i
    break
  else:
    sum[i] = sum[i-1] + X
    p[X] += i

if repeat_start == 0:
  print(sum[N])
else:
  repeat_cnt,mod=divmod(N-repeat_start+1,repeat_end-repeat_start)
  print(repeat_cnt*(sum[repeat_end-1]-sum[repeat_start-1]) + sum[repeat_start+mod-1])

Buggy submission (verdict: Runtime Error):
# 繰り返しの始まり + 繰り返し + 途中で終わった繰り返し分
N,X,M = map(int,input().split())
p = [0] * (M+2)
sum = [0] * (M+2)
p[X] = 1
sum[1] = X

repeat_start = 0
repeat_end = 0

for i in range(2,N+1):
  X = (X**2) % M
  if p[X] != 0:
    repeat_start = p[X]
    repeat_end = i
    break
  else:
    sum[i] = sum[i-1] + X
    p[X] += i

if repeat_start == 0:
  print(sum[N])
else:
  repeat_cnt,mod=divmod(N-repeat_start-1,repeat_end-repeat_end)
  print(d*(sum[repeat_end-1]-sum[repeat_start-1]) + sum[repeat_start+mod-1])

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

cnt = [False] + [1] + [0] * (M-1)
numbers = [X]
ans = 0

if M == 0:
  print(0)
  exit()
for n in range(N):
  X = pow((X % M),2)%M
  cnt[X] += 1
  if (cnt[X] >= 2) or X == 0:
    break
  else:
    numbers.append(X) 

if X == 0:
  print(sum(numbers))
  exit()

repeat_before = numbers[0:numbers.index(X)]
repeat = numbers[numbers.index(X):X]

repeat_cnt,mod  = divmod(N-numbers.index(X),len(repeat))


print(sum(repeat_before) + sum(repeat) * repeat_cnt + sum(repeat[:mod]))

Buggy submission (verdict: Runtime Error):
# 繰り返しの始まり + 繰り返し + 途中で終わった繰り返し分
N,X,M = map(int,input().split())

cnt = [False] + [1] + [0] * (M-1)
numbers = [X]
ans = 0
for n in range(N):
  X = pow((X % M),2)%M
  cnt[X] += 1
  if (cnt[X] >= 2) or X == 0:
    break
  else:
    numbers.append(X) 

if X == 0:
  print(sum(numbers))
  exit()

repeat_before = numbers[0:numbers.index(X)]
repeat = numbers[numbers.index(X):X]

repeat_cnt,mod  = divmod(N-numbers.index(X),len(repeat))


print(sum(repeat_before) + sum(repeat) * repeat_cnt + sum(repeat[:mod]))
Problem p02580 (python)

Fixed submission:
H, W, M = map(int, input().split())
boms = [tuple(map(int, input().split())) for _ in range(M)]
# boms = [list(map(int, input().split())) for _ in range(M)]

hBom = [0]*H
wBom = [0]*W

# 各行、各列の爆破対象をカウント
for h, w in boms:
    hBom[h-1] += 1
    wBom[w-1] += 1

# 爆破対象の最大数と最大になる行と列の番号を調べる
maxHBom = max(hBom)
maxWBom = max(wBom)
maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom]
maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom]

# 爆破対象が最大になる行と列の組み合わせについて、
# 爆弾を配置する場所が爆破対象であるかないかで場合分け
boms = set(boms)
for h in maxHBomIndex:
    for w in maxWBomIndex:
        if (h+1, w+1) not in boms:
            print(maxHBom + maxWBom)
            exit()
else:
    print(maxHBom + maxWBom - 1)

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

hBom = [0]*H
wBom = [0]*W

# 各行、各列の爆破対象をカウント
for h, w in bom:
    hBom[h-1] += 1
    wBom[w-1] += 1

# 爆破対象の最大数と最大になる行と列の番号を調べる
maxHBom = max(hBom)
maxWBom = max(wBom)
maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom]
maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom]

# 爆破対象が最大になる行と列の組み合わせについて、
# 爆弾を配置する場所が爆破対象であるかないかで場合分け
for h in maxHBomIndex:
    for w in maxWBomIndex:
        if [h+1, w+1] not in set(bom):
            print(hBom[h] + wBom[w])
            exit()
else:
    print(hBom[h] + wBom[w] - 1)
Problem p02598 (python)

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


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//n-1
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

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


def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//(n-1)
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


l = 0
r = max(A)
# 二分探索
while r - l > 1:
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

Buggy submission (verdict: Runtime Error):
def f(n):
    cnt = 0
    for a in A:
            # a/nが偶数の場合
        if a % n == 0:
            cnt += a//(n-1)
        # a/nが奇数の場合
        else:
            cnt += a//n
    return True if K >= cnt else False


N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = max(A)
# 二分探索
while r - l > 1:
    cnt = 0
    m = (r+l)//2
    if f(m):
        r = m
    else:
        l = m
print(r)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = 0
r = max(A)
# 二分探索
while r - l > 1:
    cnt = 0
    flag = False
    m = (r+l)//2
    for a in A:
        # a/mが偶数の場合
        if a % m == 0:
            cnt += a//(m-1)
        # a/mが奇数の場合
        else:
            cnt += a//m
    flag = True if K >= cnt else False
    # Trueなら右側を狭める
    # Falseなら左側を狭める
    if flag == True:
        r = m
    else:
        l = m
print(r)
Problem p02859 (python)

Fixed submission:
print(int(input())**2)

Buggy submission (verdict: Runtime Error):
print(int(input()**2)
Problem p02773 (python)

Fixed submission:
N = int(input())
S = []
for _ in range(N):
    S.append(input())
    
import collections
c = collections.Counter(S)
most = c.most_common()
answerlist = [most[0][0]]
i = 0
if len(most) > 1:
    while most[i][1] == most[i+1][1]:
        answerlist.append(most[i+1][0])
        i += 1
        if i == len(most)-1:
            break
sortanswer = sorted(answerlist)
for i in range(len(sortanswer)):
    print(sortanswer[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
S = []
for _ in range(N):
    S.append(input())
    
import collections
c = collections.Counter(S)
most = c.most_common()
answerlist = [most[0][0]]
i = 0
while most[i][1] == most[i+1][1]:
    answerlist.append(most[i+1][0])
    i += 1
    if i == len(most)-1:
        break
sortanswer = sorted(answerlist)
for i in range(len(sortanswer)):
    print(sortanswer[i])
Problem p02912 (python)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = list(map(lambda x: x*(-1),A))
import heapq
heapq.heapify(A)

for i in range(M):
    maxA = (((heapq.heappop(A))*(-1))//2)*(-1)
    heapq.heappush(A,maxA)
   
    
print(sum(A)*-1)

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

for i in range(M):
    if A[0]<A[1]:
        A = sorted(A,reverse=True)
    A[0] = A[0]//2
print(sum(A))

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

for i in range(M):
    if A[0]<A[1]:
        A = sorted(A,reverse=True)
    A[0] = A[0]//2
print(sum(A))
Problem p02933 (python)

Fixed submission:
a = int(input())
s = str(input())
if a>=3200:
    print(s)
else:
    print('red')

Buggy submission (verdict: Runtime Error):
a = int(input())
s = str(input())
if a>=3200:
    print(s)
else:
    print(red)
Problem p02598 (python)

Fixed submission:
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while math.ceil(minVal) != math.ceil(maxVal):
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

print(math.ceil(maxVal))

Buggy submission (verdict: Runtime Error):
import math

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

def isPossible(X):
    global N, K, A

    cuts = 0
    for i in range(N):
        cuts += math.ceil(A[i]/X) - 1
    
    return cuts <= K

minVal = 0
maxVal = max(A)

while maxVal - minVal >= 1:
    if isPossible((maxVal + minVal) / 2):
        maxVal = (maxVal + minVal) / 2
    else:
        minVal = (maxVal + minVal) / 2

if not isPossible(minVal) and int(minVal) == minVal:
    print(minVal+1)
else:
    print(math.ceil(minVal))