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

Fixed submission:
import numpy as np
N, W = map(int, input().split())

items = [tuple(map(int, input().split())) for _ in range(N)]

dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0

for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)

print(np.max(np.where(dp <= W)))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

items = [tuple(map(int, input().split())) for _ in range(N)]

dp = np.zeros(W+1)

for i, (w, v) in enumerate(items):
    tmp = np.zeros(W+1)
    tmp[w:] = dp[:W-w+1] + v
    dp[w:] = np.fmax(tmp[w:], dp[w:])

print(int(dp[-1]))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

items = [tuple(map(int, input().split())) for _ in range(N)]

dp = np.zeros(W+1)

for i, (w, v) in enumerate(items):
    tmp = np.zeros(W+1)
    tmp[w:] = dp[:-w] + v
    dp[w:] = np.fmax(tmp[w:], dp[w:])

print(int(dp[-1]))
Problem p03497 (python)

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

d = defaultdict(int)
for i in A:
    d[i] += 1

d_ = sorted(d.items(), key=lambda x:x[1], reverse=True)
n =len(d_)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d_[i][1]
print(ans)

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

d = Counter(A)
d.most_common()
n =len(d)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d[i][1]
print(ans)

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

d = Counter(A)
d.most_common()
n =len(d_)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d[i][1]
print(ans)
Problem p03545 (python)

Fixed submission:
import sys
s = input()
n = len(s)

ans = 7

for bit in range(2**(n-1)):
    tmp = s[0]
    for i in range(n-1):
        if (1<<i)&bit:
            tmp += '+'
        else:
            tmp += '-'
        tmp += s[i+1]
    total = eval(tmp)
    if total == ans:
        print(tmp + '=7')
        sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
s = input()
n = len(s)

ans = 7

for bit in range(2**(n-1)):
    tmp = s[0]
    for i in range(n-1):
        if (1<<i)&bit:
            tmp += '+'
        else:
            total += '-'
        tmp += s[i+1]
    total = eval(tmp)
    if total == ans:
        print(tmp + '=7')
        sys.exit()
Problem p03559 (python)

Fixed submission:
import bisect
N = int(input())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a*(N-c)
print(ans)

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

tmp_b = 0
tmp_c = 0
max_b = B[-1]
max_c = C[-1]
ans = 0
for i in range(N):
    flg = False
    tmp = A[i]
    if tmp >= max_b:
        break
    while True:
        if B[tmp_b] > tmp:
            tmp = B[tmp_b]
            break
        else:
            tmp_b += 1
    while True:
        if C[tmp_c] > tmp:
            break
        else:
            tmp_c += 1
    k = tmp_c
    for j in range(tmp_b, N):
        if B[j] >= max_c or flg:
            break
        else:
            while True:
                if B[j] < C[k]:
                    ans += N-k
                    break
                else:
                    k += 1
                    if k == N:
                        flg = True
                        break

print(ans)
Problem p04045 (python)

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

for i in range(N, 10**5):
    if not set(str(i)) & D:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
import itertools

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

D = list(map(int, input().split()))
dic = [0,1,2,3,4,5,6,7,8,9]

for i in D:
    dic.remove(i)

dict = map(str, dic)
n = len(str(N)) #何桁か

ans = []
for i in range(2):
    for v in itertools.permutations(dict, n+i):
        if int(''.join(v)) >= N:
            ans.append(int(''.join(v)))
print(min(ans))
Problem p02706 (python)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
p=0
for i in a:
      p+=i
if(n>=p):
          print("{}".format(n-p))
else:
          print("-1")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=0
a+=map(int,input().split())
if(n>a):
  print("{}",n-a)
else:
  print("-1",
Problem p02734 (python)

Fixed submission:
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n,s=reads()
a=list(reads())
mod= 998244353
f=[[] for i in range(n+1)]
for k in range(1,n+1):
  if k==1:
    res=[0]*(s+1)
    res[0]=1
    if a[0]<s+1:
      res[a[0]]=1
    f[1]=res
    continue
  res=f[k-1][:]
  k-=1
  for i in range(s,-1,-1):
    if i-a[k]>=0:
      res[i]+=res[i-a[k]]
      res[i]%=mod
  if a[k]<s+1:
      res[a[k]]+=1
  res[0]+=1
  f[k+1]=res
ans=0
#print(f)
for i in range(1,n+1):
  ans+=f[i][-1]
ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n,s=reads()
a=list(reads())
mod= 998244353
@lru_cache(None)
def F(k):#ｆ１＋ｆ２＋．。。ｆｋ
  if k==1:
    res=[0]*(s+1)
    res[0]=1
    if a[0]<s+1:
      res[a[0]]=1
    return res
  res=F(k-1)
  k-=1
  for i in range(s,-1,-1):
    if i-a[k]>=0:
      res[i]+=res[i-a[k]]
        res[i]%=mod
  if a[k]<s+1:
      res[a[k]]+=1
  res[0]+=1
  return res
ans=0
for i in range(1,n+1):
  ls=F(i)
  ans+=ls[-1]
ans%=mod
print(ans)
Problem p03160 (python)

Fixed submission:
import sys,io
from functools import lru_cache
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
h=list(reads())
@lru_cache(None)
def cost(k):
    if k==0:
        return 0
    elif k==1:
        return abs(h[0]-h[1])
    return min(cost(k-1)+abs(h[k-1]-h[k]),cost(k-2)+abs(h[k-2]-h[k]))
print(cost(n-1))

Buggy submission (verdict: Runtime Error):
import sys,io
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
h=list(reads())
@lru_cache(None)
def cost(k):
    if k==0:
        return 0
    elif k==1:
        return abs(h[0]-h[1])
    return min(cost(k-1)+abs(h[k-1]-h[k]),cost(k-2)+abs(h[k-2]-h[k]))
print(cost(n-1))

Buggy submission (verdict: Runtime Error):
import sys,io
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
h=list(reads())
def cost(k):
    if k==0:
        return 0
    elif k==1:
        return abs(h[0]-h[1])
    return min(cost(k-1)+abs(h[k-1]-h[k]),cost(k-2)+abs(h[k-2]-h[k]))
print(cost(n-1))

Buggy submission (verdict: Runtime Error):
import sys,io
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
h=list(reads())
def cost(k):
    if k==0:
        return 0
    elif k==1:
        return abs(h[0]-h[1])
    return min(cost(k-1)+abs(h[k-1]-h[k]),cost(k-2)+abs(h[k-2]-h[k]))
print(cost(n-1))
Problem p03162 (python)

Fixed submission:
import sys,io
from functools import lru_cache
import numpy
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b,c=[0]*n,[0]*n,[0]*n
for i,line in enumerate(readlines()):
    a[i],b[i],c[i]=mp(line)
dp=[[0,0,0] for i in range(n+1)]
for k in range(1,n+1):
    one=dp[k-1][1]
    two=dp[k-1][2]
    zero=dp[k-1][0]
    dp[k][0]= one if one >= two else two
    dp[k][0]+=a[k-1]
    dp[k][1]= zero if zero >= two else two
    dp[k][1]+=b[k-1]
    dp[k][2]= one if one >= zero else zero
    dp[k][2]+=c[k-1]
#print(dp)
print(max(dp[n][0],dp[n][1],dp[n][2]))

Buggy submission (verdict: Runtime Error):
import sys,io
from functools import lru_cache
sys.setrecursion(10**6)
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b,c=[0]*n,[0]*n,[0]*n
for i,line in enumerate(readlines()):
    a[i],b[i],c[i]=mp(line)
dp=[]
@lru_cache(None)
def dp(k,choice):
    if k==0:
        return 0
    one=dp(k-1,1)+a[k-1]
    two=dp(k-1,2)+b[k-1]
    zero=dp(k-1,0)+c[k-1]
    if choice==0:
        return one if one >= two else two
    if choice==1:
        return zero if zero >= two else two
    if choice==2:
        return one if one >= zero else zero
print(max(dp(n,0),dp(n,1),dp(n,2)))
Problem p03164 (python)

Fixed submission:
# D問題とほぼ同じだが計算量が問題になる．
# 前回と違い重さの制約が，W<10^9なので，重さのノードを作ってしまうと，計算量がどう仕様もなくなる
# なので，価値に対してノードを作ってあげて，最小の重さを計算するようにする

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

W = []
V = []

for i in range(N):
    w,v = map(int,input().split())
    W.append(w)
    V.append(v)
# dp[v][i] := 商品iまで選択して，価値がv以下となった場合について，最小の重さ
import math
import numpy as np
dp = np.ones((10**3*(N+10))) * np.inf
dp[0] = 0
for v,w in zip(V,W):
    np.minimum(dp[:-v]+w, dp[v:],out=dp[v:])
print(np.where(dp<=W_max)[0][-1])

Buggy submission (verdict: Runtime Error):
    import sys,io
    from functools import lru_cache
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10**8)
    def read():
      return int(readline())
    def reads():
      return map(int, readline().split())
    def mp(arg):
      return map(int,arg.split())
    N,W=reads()
    weight,value=[0]*N,[0]*N
    for i in range(N):
        weight[i],value[i]=reads()
    dp=[[ 0 for _ in  range(W+1) ] for _ in range(N+1)]
    for i in range(N):
      for k in range(W+1):
        if (k >= weight[i]) :dp[i+1][k] = max(dp[i][k-weight[i]] + value[i], dp[i][k])
        else :dp[i+1][k] = dp[i][k]
    print("{}".format(dp[N][W]))
Problem p03165 (python)

Fixed submission:
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
s=input()
t=input()
dp=[[0 for i in range(len(t)+1)] for j in range(len(s)+1)]
for i,sele in enumerate(s):
  for j ,tele in enumerate(t):
    if sele==tele:
      dp[i+1][j+1]=dp[i][j] +1
    else :
      dp[i+1][j+1]=dp[i+1][j] if dp[i+1][j]>=dp[i][j+1] else dp[i][j+1]     
res=""
i=len(s)
j=len(t)
#print(dp)
while True:
#for k in range(9):
  #rint(i,j,dp[i][j])
  if i-1>=0:
    if dp[i-1][j]==dp[i][j]:
      i=i-1
      continue
  if j-1>=0:
    if dp[i][j-1]==dp[i][j]:
      j=j-1
      continue
  if i-1>=0 and j-1>=0:
    if dp[i-1][j-1]==dp[i][j]-1:
      j=j-1
      i=i-1
      res=s[i]+res
      #print(i,res)
      if dp[i][j]==0:
        break
      continue
  break
print(res)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
s=input()
t=input()
dp=[[0 for i in range(len(s)+1)] for j in range(len(t)+1)]
for i,sele in enumerate(s):
  for j ,tele in enumerate(t):
    if sele==tele:
      dp[i+1][j+1]=dp[i][j] +1
    else :
      dp[i+1][j+1]=dp[i+1][j] if dp[i+1][j]>=dp[i][j+1] else dp[i][j+1]     
print(dp[len(s)][len(t)])

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
s=input()
t=input()
dp=[["" for i in range(len(s)+1)] for j in range(len(t)+1)]
for i,sele in enumerate(s):
  for j ,tele in enumerate(t):
    if sele==tele:
      dp[i+1][j+1]=dp[i][j] +sele
    else :
      dp[i+1][j+1]=dp[i+1][j] if dp[i+1][j]>=dp[i][j+1] else dp[i][j+1]     
print(dp[len(s)][len(t)])

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
s=input()
t=input()
dp=[["" for i in range(len(s)+1)] for j in range(len(t)+1)]
for i,sele in enumerate(s):
  for j ,tele in enumerate(t):
    if sele==tele:
      dp[i+1][j+1]=dp[i][j] +sele
    else :
      dp[i+1][j+1]=dp[i+1][j] if dp[i+1][j]>=dp[i][j+1] else dp[i][j+1]     
print(dp[len(s)][len(t)])
Problem p03347 (python)

Fixed submission:
n=int(input())
res=0
a1=int(input())
if a1!=0:
  print(-1)
  exit()
try:a2=int(input())
except:
      print("0")
      exit()
for  i in range(n-2):
  if a2-a1>1:
    print("-1")
    exit()
  if a2<=a1:
    res+=a1
  a1=a2
  a2=int(input()) 
if a2-a1>1:
    print("-1")
    exit()
if a2<=a1:
    res+=a1
res+=a2
print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
res=0
a1=int(input())
if a1!=0:
  print(-1)
  exit()
a2=int(input())
for  i in range(n-2):
  if a2-a1>1:
    print("-1")
    exit()
  if a2<=a1:
    res+=a1
  a1=a2
  a2=int(input())
if a2-a1>1:
    print("-1")
    exit()
if a2<=a1:
    res+=a1
res+=a2
print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
res=0
a1=int(input())
if a1!=0:
  print(-1)
  exit()
a2=int(input())
for  i in range(n-2):
  if a2-a1>1:
    print("-1")
    exit()
  if a2<=a1:
    res+=a1
  a1=a2
  a2=int(input())
if a2-a1>1:
    print("-1")
    exit()
res+=a2
print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
res=0
a1=int(input())
if a1!=0:
  print(-1)
  exit()
a2=int(input())
for  i in range(n-2):
  if a2-a1>1:
    print("-1")
    exit()
  if a2<=a1:
    res+=a1
  a1=a2
  a2=int(input())
res+=a2
print(res)
Problem p02536 (python)

Fixed submission:
class unionfind():
    def __init__(self, n):
        self.parents = [-1 for i in range(n)]

    def find(self, a):
        if self.parents[a] < 0:
            return a
        self.parents[a] = self.find(self.parents[a])
        return self.parents[a]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if x < y:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self):
        return len(list(filter(lambda x: x < 0, self.parents))) - 1

n, m = map(int, input().split())
uf = unionfind(n)
for i in range(m):
    tmp = list(map(int, input().split()))
    uf.union(tmp[0] - 1, tmp[1] - 1)

print(uf.size())

Buggy submission (verdict: Runtime Error):
class unionfind():
    def __init__(self, n):
        self.parents = [-1 for i in range(n)]
    
    def find(self, a):
        if self.parents[a] < 0:
            return a
        self.parents[a] = self.find(a)
        return self.parents[a]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if x < y:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self):
        return len(list(filter(lambda x: x < 0, self.parents))) - 1

n, m = map(int, input().split())
uf = unionfind(n)
for i in range(m):
    tmp = list(map(int, input().split()))
    uf.union(tmp[0] - 1, tmp[1] - 1)

print(uf.size())
Problem p02642 (python)

Fixed submission:
from collections import Counter

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

A.sort()

ans = 0
tmp = [True for i in range(A[-1] + 1)]

for i in range(N - 1):
    if tmp[A[i]]:
        if A[i + 1] != A[i]:
            ans += 1
        for j in range(A[i], A[-1] + 1, A[i]):
            tmp[j] = False
if tmp[A[-1]]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
class_yoti = [[] for i in range(2 * 10 ** 5 + 1)]
A, B, C, D = [], [], [], []
max_rate = float('inf')

for i in range(N):
    tmpa, tmpb = map(int, input().split())
    A.append(tmpa), B.append(tmpb)
    class_yoti[tmpb].append(tmpa)

for i in range(Q):
    tmpa, tmpb = map(int, input().split())
    C.append(tmpa - 1), D.append(tmpb)

for i in range(2 * 10 ** 5 + 1):
    if class_yoti[i]:
        class_yoti[i].sort()
        if max_rate > class_yoti[i][-1]:
            max_rate = class_yoti[i][-1]

for i in range(Q):
    tmp = C[i]
    class_yoti[B[tmp]].remove(A[tmp])
    if class_yoti[B[tmp]]:
        class_yoti[B[tmp]].sort()

    B[tmp] = D[i]
    class_yoti[D[i]].append(A[tmp])
    class_yoti[D[i]].sort()

    max_rate = float('inf')
    for j in range(2 * 10 ** 5 + 1):
        if class_yoti[j]:
            max_rate = min(class_yoti[j][-1], max_rate)

    print(max_rate)
Problem p02647 (python)

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

for i in range(min(K, 50)):
    B = [0 for i in range(N)]
    for j in range(0, N):
        l = max(0, j - A[j])
        r = min(N - 1, j + A[j])
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    for j in range(1, N):
        B[j] += B[j - 1]
        
    A = B

[print(i, end=' ') for i in B]
print()

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

for _ in range(min(K, 50)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    for i in range(N):
        lamp[i] += lamp[i - 1]
    A = lamp

[print(A[i], end=' ') for i in range(N)]
print()

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

for _ in range(min(K, 50)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    for i in range(N):
        lamp[i] += lamp[i - 1]
    A = lamp

[print(A[i], end=' ') if i != N - 1 else print(A[i]) for i in range(N)]

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

for _ in range(min(K, N ** 0.5)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    ans = 0
    for i in range(N):
        ans += lamp[i]
        A[i] = min(ans, N)

[print(A[i], end=' ') if i != N - 1 else print(A[i]) for i in range(N)]
Problem p02678 (python)

Fixed submission:
from collections import deque
class UnionFind:
    def __init__(self, N):
        self.parents = [-1 for i in range(N)]
        self.unit = [0 for i in range(N)]
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]
    
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if x > y:
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x

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


lists = [False for i in range(N)]
lists[0] = True
a = N - 1
dicts = {i:[] for i in range(N)}
d = deque([0])

for i in range(M):
    tmpa, tmpb = map(lambda x: int(x) - 1, input().split()) 
    dicts[tmpa] += [tmpb]
    dicts[tmpb] += [tmpa]
    uf.union(tmpa, tmpb)

if -uf.parents[0] == N:
    print('Yes')
    while a > 0:
        tmp = d.popleft()
        for i in dicts[tmp]:
            if not lists[i]:
                if tmp != 0:
                    lists[i] = tmp
                else:
                    lists[i] = -1
                d.append(i)
                a -= 1
    
    for i in range(1, N):
        print(lists[i] + 1 if lists[i] != -1 else 1)
else:
    print('No')

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

lists = [False for i in range(N)]
lists[0] = True
a = N - 1
dicts = {i:[] for i in range(N)}
d = deque([0])

for i in range(M):
    tmpa, tmpb = map(lambda x: int(x) - 1, input().split()) 
    dicts[tmpa] += [tmpb]
    dicts[tmpb] += [tmpa]

print('Yes')
while a > 0:
    tmp = d.popleft()
    for i in dicts[tmp]:
        if not lists[i]:
            if tmp != 0:
                lists[i] = tmp
            else:
                lists[i] = -1
            d.append(i)
            a -= 1
    
for i in range(1, N):
    print(lists[i] + 1 if lists[i] != -1 else 1)
Problem p02696 (python)

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

def f(num):
    return(A * num) // B - A * (num // B)

print(f(min(B - 1, N)))

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

tmp = 0
a = 0
i = 0

if B > A:
    for i in range(B - 1, N + 1, B):
        if (s := (A * i) // B - A * (a)) > 0:
            tmp = max(s, tmp)
        else:
        break

if i >= N - B:
    for i in range(N, N - N % B - 2, -1):
        if (s := (A * i) // B - A * (i // B)) > 0:
            tmp = max(s, tmp)
        else:
            break

print(tmp)
Problem p02719 (python)

Fixed submission:
n, k = map(int, input().split())

if k > n:
    tmp = n
else:
    tmp = n % k

if tmp > k / 2:
    tmp = k - tmp

print(tmp)

Buggy submission (verdict: Runtime Error):
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n, k;
    scanf("%d %d", &n, &k);
    if (k == 1){
        printf("0\n");
    }else{
        while ((double)n >= (double)k / 2){
            n = abs(k - n);
        }
        printf("%d\n", n);
    }
    return 0;
}

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

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

def a(N, K):
    if abs(K - N) < K / 2:
        print(abs(K - N))
    else:
        a(abs(K - N), K)
        

if k == 1:
    print(0)
elif n < k / 2:
    print(n)
else:
    a(abs(k - n), k)

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

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

def a(N, K):
    if abs(K - N) < K / 2:
        print(abs(K - N))
    else:
        a(abs(K - N), K)
        

if k == 1:
    print(0)
elif n < k / 2:
    print(n)
else:
    a(abs(k - n), k)

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

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

def a(N, K):
    if abs(K - N) < K / 2:
        print(abs(K - N))
    else:
        a(abs(K - N), K)
        

if k == 1:
    print(0)
elif n < k / 2:
    print(n)
else:
    a(abs(k - n), k)