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

Fixed submission:
def binom(n,r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def power(n,r):
    res = 1
    for i in range(r):
        res *= n
        res %= p
    return res

n,m,k = list(map(int, input().split()))

p = 998244353

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

num = 0

pw = (m-1)**(n-k-1) % p

for i in range(k+1):
    num += m * pw * binom(n-1, k - i)
    num %= p
    pw *= m-1
    pw %= p

print(num)

Buggy submission (verdict: Runtime Error):
def binom(n,r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def power(n,r):
    res = 1
    for i in range(r):
        res *= n
        res %= p
    return res

n,m,k = list(map(int, input().split()))

p = 998244353

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

num = 0

pw = (m-1)**(n-k-2) % p

for i in range(k+1):
    pw *= m-1
    pw %= p
    num += m * pw * binom(n-1, k - i)
    num %= p

print(num)
Problem p02781 (python)

Fixed submission:
def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s

N = input()
K = int(input())

def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit <= 1:
            return 0
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit <= 2:
            return 0
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res

print(calc(N, K))

Buggy submission (verdict: Runtime Error):
def zeroTrim(s):
    while s[0] == '0':
        if len(s) == 1:
            break
        s = s[1:]
    return s

N = input()
K = int(input())

def calc(N, K):
    digit = len(N)
    res = 0

    if K == 1:
        if digit > 1:
            res += (digit - 1) * 9
        res += int(N[0])
    elif K == 2:
        if digit > 2:
            res += 9 * 9 * (digit - 1) * (digit - 2) // 2
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 1)
        res += calc(zeroTrim(N[1:]), 1)
    else:
        if digit > 3:
            res += 9 * 9 * 9 * (digit - 1) * (digit - 2) * (digit - 3) // 6
        
        for i in range(int(N[0])-1):
            res += calc('9'*(digit-1), 2)
        res += calc(zeroTrim(N[1:]), 2)
    return res

print(calc(N, K))
Problem p02580 (python)

Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  d={}
  for _ in range(M):
    a,b=LI()
    a-=1
    b-=1
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(h):
    if x==h_max:
      h_koho.append(i)
  for i,x in enumerate(w):
    if x==w_max:
      w_koho.append(i)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1

# main()
print(main())

Buggy submission (verdict: Runtime Error):
r, l, m = map(int, input().split())
rr, ll = [0] * r, [0] * l
tt = [[0] * l for i in range(r)]
for i in range(m):
    hi, wi = map(int, input().split())
    rr[hi-1] += 1
    ll[wi-1] += 1
    tt[hi-1][wi-1] = 1
i = rr.index(max(rr))
flag = max(ll)
ans = max(rr)
for j in range(l):
    if ll[j] == flag and tt[i][j] != 1:
        ans += flag
        print(ans)
        exit()

print(ans + flag - 1)
Problem p02836 (python)

Fixed submission:
s = input()
n = len(s)
counter = 0
for i in range(n//2):
  if s[i] != s[n-i-1]:
    counter += 1
print(counter)

Buggy submission (verdict: Runtime Error):
v
Problem p03013 (python)

Fixed submission:
import sys
n, m = map(int, input().split())
danger = [int(input()) for i in range(m)]

MOD = 1000000007
MAX = 200000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

def poss(n):
  n -= 1
  k = n//2
  ans = 0
  for i in range(k+1):
    ans += modcomb(n-i, i) % MOD
  return ans % MOD
if m == 0:
  print(poss(n+1))
  sys.exit()
ans = poss(danger[0])
for i in range(1, m):
  if danger[i] - danger[i-1] == 1:
    print(0)
    sys.exit()
  ans *= poss(danger[i] - danger[i-1] - 1)
  ans = ans % MOD
ans *= poss(n - danger[m-1])

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
danger = [int(input()) for i in range(m)]

MOD = 1000000007
MAX = 1000000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

def poss(n):
  n -= 1
  k = n//2
  ans = 0
  for i in range(k+1):
    ans += modcomb(n-i, i) % MOD
  return ans % MOD

ans = poss(danger[0])
for i in range(1, m):
  if danger[i] - danger[i-1] == 1:
    print(0)
    sys.exit()
  ans *= poss(danger[i] - danger[i-1] - 1)
  ans = ans % MOD
ans *= poss(n - danger[m-1])

print(ans % MOD)
Problem p03295 (python)

Fixed submission:
n, m = map(int, input().split())
need = [list(map(int, input().split())) for i in range(m)]
need = sorted(need, key=lambda x: x[1])

ans = 1
stock = need[0][1]
for i in range(m):
  if stock <= need[i][0]:
    ans += 1
    stock = need[i][1]
    
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = []
for i in range(n):
  x, l = map(int, input().split())
  left = x - l
  right = x + l
  lst.append([left, right])

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

ans = 1
limit = lst[0][1]
for i in range(n):
  if lst[i][0] >= limit:
    ans += 1
    limit = lst[i][1]

print(ans)
Problem p03013 (python)

Fixed submission:
MOD = 10**9 + 7
N, M = map(int,input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * (N+1)
dp[0] = 1

for i in range(1, N+1):
    if i not in a and i > 1:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
    elif i not in a and i == 1:
        dp[i] = dp[i-1]
print(dp[-1])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, M = map(int,input().split())
a = set(int(input()) for _ in range(M))

dp = [0] * N
if 1 in a:
    dp[0] = 0
    if 2 in a:
        dp[0] = 0
    else:
        dp[1] = 1
else:
    dp[0] = 1
    if 2 in a:
        dp[1] = 0
    else:
        dp[1] = 2

for i in range(2, N):
    if i+1 not in a:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[-1])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, M = map(int,input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * N
if 1 in a:
    dp[0] = 0
    if 2 in a:
        dp[0] = 0
else:
    dp[0] = 1
    if 2 in a:
        dp[1] = 0
    else:
        dp[1] = 2

for i in range(2, N):
    if i+1 not in a:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[-1])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, M = map(int,input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * N
if 1 not in a:
    dp[0] = 1
    if 2 not in a:
        dp[1] = 2
else:
    if 2 not in a:
        dp[1] = 1

for i in range(2, N):
    if i+1 not in a:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[-1])

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
N, M = map(int,input().split())
a = [int(input()) for _ in range(M)]
dp = [0] * N
if 1 not in a:
    dp[0] = 1
    if 2 not in a:
        dp[1] = 2
else:
    if 2 not in a:
        dp[1] = 1

for i in range(2, N):
    if i+1 not in a:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
dp = [0] * N
if 1 not in a:
    dp[0] = 1
    if 2 not in a:
        dp[1] = 2
else:
    if 2 not in a:
        dp[1] = 1

for i in range(2, N):
    if i+1 not in a:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[-1] % 1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
dp = [0] * N
if 1 not in a:
    dp[0] = 1
    if 2 not in a:
        dp[1] = 2
else:
    if 2 not in a:
        dp[1] = 1

for i in range(2, N):
    if i+1 not in a:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[-1] % 1000000007)
Problem p03038 (python)

Fixed submission:
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1), reverse=True)

idx = 0
flag = 0
for i in range(M):
    q = Q[i]
    B = q[0]
    C = q[1]
    for b in range(B):
        if idx >= N:
            flag = -1
            break
        if A[idx] < C:
            A[idx] = C
            idx += 1
        else:
            flag = -1
    if flag == -1 or i == M-1:
        break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1), reverse=True)

idx = 0
flag = 0
for i in range(M):
    q = Q[i]
    B = q[0]
    C = q[1]
    for b in range(B):
        if A[idx] < C:
            A[idx] = C
            idx += 1
        else:
            flag = -1
    if flag == -1 or i == M-1:
        break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1))
Q.reverse()
flag = 0
idx = 0

for q in Q:
    if flag == -1:
        break
    b = q[0]
    c = q[1]
    a = A[idx:idx+b]
    if c < max(a):
        count = 0
        for i in a:
            if i < c:
                count+=1
        A = A[:idx] + [c]*count + A[idx+count:]
        flag = -1
    else:
        a = [c]*b
        A = A[:idx] + a + A[idx+b:]
        idx += b

print(sum(A))
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500*500)
N, M = map(int,input().split())
Q = [list(map(int,input().split())) for _ in range(M)]
C = [[] for _ in range(N+1)]
count = 0
for q in Q:
    X = q[0]
    Y = q[1]
    C[X].append(Y)
    C[Y].append(X)

flag = [-1]*(N+1)
flag[1] = 0
def dfs(s):
    global count
    for c in C[s]:
        flag[s] = 0
        if flag[c] == -1:
            flag[c] = 0
            count += 1
            dfs(c)

for i in range(1,N+1):
    dfs(i)
print(N-count)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
Q = [list(map(int,input().split())) for _ in range(M)]
C = [[] for _ in range(N+1)]
count = 0
for q in Q:
    X = q[0]
    Y = q[1]
    C[X].append(Y)
    C[Y].append(X)

flag = [-1]*(N+1)
flag[1] = 0
def dfs(s):
    global count
    for c in C[s]:
        flag[s] = 0
        if flag[c] == -1:
            flag[c] = 0
            count += 1
            dfs(c)

for i in range(1,N+1):
    dfs(i)
print(N-count)
Problem p03127 (python)

Fixed submission:
import fractions
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
print(reduce(lambda a, b: fractions.gcd(a,b), A))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
HP = input().split()

while True:
    a = math.gcd(int(HP[-1]),int(HP[0]))
    del HP[-1]
    del HP[0]
    HP.append(str(a))
    if len(HP) == 1:
        print(HP[0])
        break

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

N = int(input())
HP = input().split()

while True:
    a = math.gcd(int(HP[-1]),int(HP[0]))
    del HP[-1]
    del HP[0]
    HP.append(str(a))
    if len(HP) == 2:
        print(math.gcd(int(HP[-1]),int(HP[0])))
        break
Problem p03242 (python)

Fixed submission:
n = int(input())
print(1110 - n)

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in n:
    if i == 1:
        i = 9
    elif i == 9:
        i = 1
print(n)
Problem p03250 (python)

Fixed submission:
a = list(input().split())
b = int(max(a))
a.remove(max(a))
result = 0
for i in range(2):
    result += int(a[i])
print(b * 10 + int(result))

Buggy submission (verdict: Runtime Error):
a = list[int(input().split()) for i in range(3)]
a.remove(max(a))
result = 0
for i in range(2):
    result += a[i]
print(int(max(a) * 10 + result))
Problem p03252 (python)

Fixed submission:
S = input()
T = input()
dict1 = {}
dict2 = {}

for s,t in zip(S,T):
    if s in dict1:
        if dict1[s] == t:
            pass
        else:
            print('No')
            exit()
    else:
        dict1[s] = t
    if t in dict2:
        if dict2[t] == s:
            pass
        else:
            print('No')
            exit()
    else:
        dict2[t] = s
print('Yes')

Buggy submission (verdict: Runtime Error):
S = list(input())
T = list(input())
dic = {}
for i in range(len(S)):
    if i == 0:
        dic[S[i]] = T[i]
        dic[T[i]] = S[i]
        S[i] = T[i]
    else:
        if T[i] in S[:i]:
            if dic[S[i]] != T[i]:
                print('No')
                exit()
        else:
            dic[S[i]] = T[i]
            dic[T[i]] = S[i]
            S[i] = T[i]
print('Yes')
Problem p03265 (python)

Fixed submission:
import math

x1,y1,x2,y2 = map(int,input().split())
x12 = x2 - x1
y12 = y2 - y1

r = (x12**2+y12**2)**(1/2)
θ = math.asin(abs(y12)/r)
if 0 >= x12 and 0 <= y12:
    θ = math.pi - θ
elif 0 >= x12 and 0 > y12:
    θ += math.pi
elif 0 < x12 and y12 < 0:
    θ = 2*math.pi - θ
x3 = round((2**(1/2)*r)*math.cos(θ + (math.pi/4)) + x1)
y3 = round((2**(1/2)*r)*math.sin(θ + (math.pi/4)) + y1)
x4 = round(r*math.cos(θ + (math.pi/2)) + x1)
y4 = round(r*math.sin(θ + (math.pi/2)) + y1)
print(x3,y3,x4,y4)

Buggy submission (verdict: Runtime Error):
x1,y1,x2,y2 = map(int,input().split())
x12 = x2 - x1
y12 = y2 - y1

for x in range(-100, 101):
    for y in range(-100, 101):
        if x*x12 + y*y12 == 0 and x12**2 + y12**2 == x**2 + y**2:
            x += x1
            y += y1
            if x12 >= 0 and y12 <= 0:
                if 0 <= x and 0 <= y:
                    x4 = x
                    y4 = y
            elif x12 >= 0 and y12 >= 0:
                if 0 >= x and 0 <= y:
                    x4 = x
                    y4 = y
            elif x12 <= 0 and y12 >= 0:
                if 0 >= x and 0 >= y:
                    x4 = x
                    y4 = y
            elif x12 <= 0 and y <= 0:
                if x >= 0 and y <= 0:
                    x4 = x
                    y4 = y

for x in range(-300,301):
    for y in range(-300,301):
        if (x2-x)**2 + (y2-y)**2 == (x4-x)**2 + (y4-y)**2 == x12**2 + y12**2 and x != x1 and y != y1:
            x3 = x
            y3 = y
print(x3,y3,x4,y4)
Problem p03307 (python)

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(N)
else:
    print(2 * N)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = list(accumulate(A))
ans = []

for i in range(N-3):
    for j in range(i+1, N-2):
        for k in range(j+1, N-1):
            list = []
            p = A[i]
            q = A[j]-A[i]
            r = A[k]-A[j]
            s = A[-1]-A[k]
            list = [p, q, r, s]
            ans.append(max(list) - min(list))

print(min(ans))

Buggy submission (verdict: Runtime Error):
 N = int(input())
if N % 2 == 0:
    print(N)
else:
    print(2 * N)
Problem p03315 (python)

Fixed submission:
S = input()
result = 0
for i in S:
    if i == "+":
        result += 1
    else:
        result -= 1
print(result)

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

if K < 9:
    for i in range(1,K+1):
        print(i)
else:
    for i in range(1,9):
        print(i)
    for i in range(K-8):
        print((i+1) * 10 -1)
Problem p03631 (python)

Fixed submission:
N = input()
list = []
for i in N:
    list.append(i)
list.reverse()
new = ''.join(list)
if new == N:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())
if B <= C:
    print(0)
elif C < B <= D:
    print(B - C)
elif C < D <= B:
    print(D - C)
elif D <= A:
    print(0)
Problem p03634 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
Q,K = map(int,input().split())
distance = [None] * (N+1)
def dfs(v1,d):
    distance[v1] = d
    for v2,dd in edge[v1]:
        if distance[v2] is not None:
            continue
        dfs(v2,d+dd)

dfs(K,0)

ans = [0] * Q
for i in range(Q):
    x,y = map(int,input().split())
    ans[i] = distance[x]+distance[y]
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
Q,K = map(int,input().split())
distance = [None] * (N+1)
def dfs(v1,d):
    distance[v1] = d
    for v2,dd in edge[v1]:
        if distance[v2] is not None:
            continue
        dfs(v2,d+dd)

dfs(K,0)

ans = [0] * Q
for i in range(Q):
    x,y = map(int,input().split())
    ans[i] = distance[x]+distance[y]
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
Q,K = map(int,input().split())
distance = [-1] * (N+1)
def dfs(v1,d):
    distance[v1] = d
    for v2,dd in edge[v1]:
        if distance[v2] is not -1:
            continue
        dfs(v2,d+dd)

dfs(K,0)

ans = [0] * Q
for i in range(Q):
    x,y = map(int,input().split())
    ans[i] = distance[x]+distance[y]
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
Q,K = map(int,input().split())
distance = [-1] * (N+1)
def dfs(v1,d):
    distance[v1] = d
    for v2,dd in edge[v1]:
        if distance[v2] is not -1:
            continue
        dfs(v2,d+dd)

dfs(K,0)
print(distance)
ans = [0] * Q
for i in range(Q):
    x,y = map(int,input().split())
    ans[i] = distance[x]+distance[y]
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a].append((b,c))
    edge[b].append((a,c))
Q,K = map(int,input().split())
distance = [-1] * (N+1)
def dfs(v1,d):
    distance[v1] = d
    for v2,dd in edge[v1]:
        if distance[v2] != -1:
            continue
        else:
            dfs(v2,d+dd)

dfs(K,0)
ans = [0] * Q
for i in range(Q):
    x,y = map(int,input().split())
    ans[i] = distance[x]+distance[y]
for a in ans:
    print(a)
Problem p03834 (python)

Fixed submission:
s = list(input().split(",",2))
a = " ".join(s)
print(a)

Buggy submission (verdict: Runtime Error):
K,S = map(int,input().split())
count=0

for x in range(K+1):
    for y in range(K+1):
        if 0 <= S-x-y <= K:
                count += 1

print(count)
Problem p02571 (python)

Fixed submission:
S = input()
T = input()
ans = float("INF")
for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt += 1
    ans = min(ans,cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
ans = float("INF")
for i in range(len(S)-len(T)):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt += 1
    ans = min(ans,cnt)
print(cnt)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
ans = float("INF")
for i in range(len(S)):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt += 1
    ans = min(ans,cnt)
print(cnt)
Problem p02598 (python)

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

def is_ok(X):
    #最大値をX以下にできるか
    cnt = 0
    for a in A:
        cnt += ceil(a/X)-1
    return cnt <= K

def bisearch(high,low):
    while high - low > 1:
        mid = (high+low)//2
        if is_ok(mid):
            high = mid
        else:
            low = mid
    return high

print(bisearch(10**9+1,0))

Buggy submission (verdict: Runtime Error):
#各丸太を何回切るか、どこで切るか
#丸太iをKi回切る場合、その丸太の最小はL//Kiとなる
#あとは、どの丸太を何回切るかを求めればよい。
"""
長い丸太ほど多く切るべき
丸太が2本、1本が10**9でもう一本が1。10**9回切れるのであれば1本目に全振りするのがベスト。

結論、元の長さの比に基づいて割り当てればよい。
一番短い丸太の長さを1として各丸太の
"""
from math import ceil
import heapq
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
pivot = A[0]
hiritu = [a/pivot for a in A]
hirituSum = sum(hiritu)
kaisu = []
for i in range(N):
    h = hiritu[i]
    k = int(K*h/hirituSum)
    kaisu.append(k)
    K -= k
if K >= 1000000:
    for i in range(N):
    h = hiritu[i]
    k = int(ceil(K*h/hirituSum))
    kaisu.append(k)
    K -= k

leng = []
for i in range(N):
    a = A[i]
    k = kaisu[i]
    leng.append(((-a/(k+1)),k,a))
heapq.heapify(leng)
for _ in range(K):
    l,k,a = heapq.heappop(leng)
    l = -a/(k+2)
    heapq.heappush(leng,(l,k+1,a))
l,k,a = heapq.heappop(leng)
l *= -1
print(ceil(l))
Problem p02725 (python)

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

for i in range(N-1):
  now = i
  pre = now-1
  post = now +1
  #nowとpreの距離を求める
  if now == 0:
    preDic = (K-A[N-1])+A[now]
  else:
    preDic = A[now]-A[pre]
  postDic = A[post]-A[now]  
  if preDic >= postDic:#時計回りに、i-1の位置まで進む
    ans.append(K-preDic)
  else:
    ans.append(K-postDic)
  
print(min(ans))

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

foK,N = map(int,input().split())
A = list(map(int,input().split()))
ans = []

for i in range(N-1):
  now = i
  pre = now-1
  post = now +1
  #nowとpreの距離を求める
  if now == 0:
    preDic = (K-A[N-1])+A[now]
  else:
    preDic = A[now]-A[pre]
  postDic = A[post]-A[now]  
  if preDic >= postDic:#時計回りに、i-1の位置まで進む
    ans.append(K-preDic)
  else:
    ans.append(K-postDic)

    
print(min(ans))