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

Fixed submission:
H,N,*AB = map(int, open(0).read().split())
dp = [0]+[10**8]*H
for n in range(N):
  A,B = AB[2*n:2*(n+1)]
  for h in range(1,H+1): dp[h] = min(dp[h],dp[max(0,h-A)]+B)
print(dp[-1])

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

int main()
{
  int H,N,A,B;
  cin >> H >> N;
  vector<int> dp(H+1,100000001);
  dp[0] = 0;
  for(int n=0; n<N; n++){
    cin >> A >> B;
    for(int h=1; h<H+1; h++){
      dp[h] = min(dp[h],dp[max(0,h-A)]+B);
    }
  }
  cout << dp[H] << endl;
}

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

int main(int argc, char* argv[])
{
  int H,N,A,B;
  cin >> H >> N;
  vector<int> dp(H+1,1000000000);
  dp[0] = 0;
  for(int n=0; n<N; n++){
    cin >> A >> B;
    for(int h=1; h<H+1; h++){
      dp[h] = min(dp[h],dp[max(0,h-A)]+B);
    }
  }
  cout << dp[H];
  return 0;
}

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

int main(int argc, char* argv[])
{
  int H,N,A,B;
  cin >> H >> N;
  vector<int> dp(H+1,1000000000);
  dp[0] = 0;
  for(int n=0; n<N; n++){
    cin >> A >> B;
    for(int h=1; h<H+1; h++){
      dp[h] = min(dp[h], dp[max(0,h-A)]+B);
    }
  }
  cout << dp[H] << endl;
  return 0;
}
Problem p02803 (python)

Fixed submission:
H,W = map(int,input().split())
maze = [list(input()) for j in range(H)]

def bfs(h,w):
  checked = [[False for i in range(W)] for j in range(H)]
  q = [(h,w,0)] if maze[h][w]=="." else []
  checked[h][w] = True
  g_n = 0
  while q:
    h_,w_,n = q.pop(0)
    g_n = max(n, g_n)
    for i,j in zip([0,0,-1,1],[-1,1,0,0]):
      if (0<=h_+i<H) and (0<=w_+j<W):
        if checked[h_+i][w_+j]: continue
        checked[h_+i][w_+j] = True
        if maze[h_+i][w_+j]==".": q.append((h_+i,w_+j,n+1))
  return g_n

n = 0
for i in range(H):
  for j in range(W):
    n = max(n, bfs(i,j))
print(n)

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

def bfs(h,w):
  checked = [[False for i in range(W)] for j in range(H)]
  q = [(h,w,0)] if maze[h][w]=="." else []
  g_n = 0
  while q:
    h_,w_,n = q.pop(0)
    g_n = max(n, g_n)
    for i,j in zip([0,0,-1,1],[-1,1,0,0]):
      if (0<=h_+i<H) and (0<=w_+j<W):
        if checked[h_+i][w_+j]: continue
        checked[h_+i][w_+j] = True
        if maze[pt[0]][pt[1]]==".": q.append((h_+i,w_+j,n+1))
  return g_n

n = 0
for i in range(H):
  for j in range(W):
    n = max(n, bfs(i,j))
print(n)
Problem p02843 (python)

Fixed submission:
from functools import reduce
from operator import add
X = int(input())
if X <= 105:
  if X<100:  print(0)
  else: print(1)
else:
  dp = [1] + [0]*X
  dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = 1
  for i in range(106,X+1): dp[i] = min(reduce(add, [dp[i-(100+j)] for j in range(6)]),1)
  print(dp[-1])

Buggy submission (verdict: Runtime Error):
from functools import reduce
from operator import add
X = int(input())
if X < 100: print(0)
else:
  dp = [1] + [0]*X
  dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = 1
  for i in range(106,X+1): dp[i] = min(reduce(add, [dp[i-(100+j)] for j in range(6)]),1)
  print(dp[-1])
Problem p02845 (python)

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

T = 1
xyz = [0]*3
for Ai in A:
  if xyz.count(Ai)>0:
    T = (T * xyz.count(Ai))%1000000007
    xyz[xyz.index(Ai)] += 1
  else:
    T = 0
    break
print(T)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
xyz,T = [0,0,0],1
for Ai in A:
  n_Ai = xyz.count(Ai)
  T = (T*n_Ai))%1000000007
  if n_Ai>0: xyz.count(Ai)xyz[xyz.index(Ai)] += 1
print(T)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
xyz = [0,0,0]
T = 1
for Ai in A:
  T = (T*xyz.count(Ai))%1000000007
  xyz[xyz.index(Ai)] += 1
print(T)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
xyz,T = [0,0,0],1
for Ai in A:
  T = (T*xyz.count(Ai))%1000000007
  xyz[xyz.index(Ai)] += 1
print(T)

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

T = 1
xyz = [0]*3
for Ai in A:
  T = (T * sum([i==Ai for i in xyz]))%1000000007
  xyz[xyz.index(Ai)] += 1
print(T)

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

T = 1
xyz = [0]*3
for Ai in A:
  T = ((T%1000000007) * (sum([i==Ai for i in xyz])%1000000007))%1000000007
  xyz[xyz.index(Ai)] += 1
print(T)
Problem p02882 (python)

Fixed submission:
from math import tan, pi
a,b,x = map(int, input().split())
eps = 1e-6

def f(a,b,t):
  if pi/2-t<eps: return 0
  if b*tan(pi/2.-t) < a: return b*b*tan(pi/2.-t)/2.*a
  else: return a*a*b - a*a*tan(t)/2.*a
  
th_p, th_n = pi/2, 0.
for i in range(100000):
  th_m = (th_p + th_n)/2.
  err = f(a,b,th_m) - x
  if err**2 < eps**2: break
  elif err < 0: th_p = th_m
  else: th_n = th_m
print(180/pi*th_m)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int, input().split())
def f(a,b,t):
  if t < math.atan(a/b): return a*a*b - a*a*a*math.tan(t)/2
  elif t > math.atan(a/b): return a*b*b*math.tan(math.pi/2-t)/2
  else: return a*a*b/2
  
err = x-f(a,b,math.atan(a/b))
if abs(err) < 1e-6:
  print(math.degrees(math.atan(a/b)))
else:
  if err > 0:
    ths = [(math.atan(a/b) - 0)*i/3 for i in range(4)]
  else:
    ths = [(math.pi/2-math.atan(a/b))*i/3+math.atan(a/b) for i in range(4)]

  abs_err = map(abs,[x-f(a,b,th) for th in ths])
  eps = 1e-6
  while min(abs_err) > eps:
    err = [x-f(a,b,th) for th in ths]
    abs_err = list(map(abs,err))
    n_i = err.index(max([e for e in err if e<0]))
    p_i = n_i+1
    ths = [(ths[p_i]-ths[n_i])*i/3+ths[n_i] for i in range(4)]

  print(math.degrees(ths[abs_err.index(min(abs_err))]))

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int, input().split())
def f(a,b,t):
  if t < math.atan(a/b): return a*a*b - a*a*a*math.tan(t)/2
  elif t > math.atan(a/b): return a*b*b*math.tan(math.pi/2-t)/2
  else: return a*a*b/2
  
err = x-f(a,b,math.atan(a/b))
if abs(err) < 1e-6:
  print(math.atan(a/b))
else:
  if err < 0:
    ths = [(math.atan(a/b) - 0)*i/3 for i in range(4)]
  else:
    ths = [(math.pi/2-math.atan(a/b))*i/3 for i in range(4)]

  abs_err = map(abs,[x-f(a,b,th) for th in ths])
  eps = 1e-6
  while min(abs_err) > eps:
    err = [x-f(a,b,th) for th in ths]
    abs_err = list(map(abs,err))
    n_i = err.index(max([e for e in err if e<0]))
    p_i = n_i+1
    ths = [(ths[p_i]-ths[n_i])*i/3+ths[n_i] for i in range(4)]
  print(math.degrees(ths[abs_err.index(min(abs_err))]))
Problem p02900 (python)

Fixed submission:
def gcd(x,y):
  n,m = min(x,y), max(x,y)
  while n!=0:
    n, m = m%n, n
  
  return m

def prime_factorization(N):
  f = 2
  p_f = []
  while N%f==0:
    p_f.append(f)
    N //= f
  f = 3
  while f**2 <= N:
    if N%f==0:
      p_f.append(f)
      N //= f
    else: f+=2
  if N!=1: p_f.append(N)
  return p_f

A, B = list(map(int, input().split(" ")))
print(1+len(set(prime_factorization(gcd(A, B)))))

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
  n,m = min(x,y), max(x,y)
  while n!=0:
    n, m = m%n, n
  
  return m

def prime(N):
  p = [i+1 for i in range(N)]
  for i in range(2,N+1):
    p = [i_p for i_p in p if i_p%i!=0 or i_p/i==1]

  return p
def prime_factorization(N):
  n = N
  P = prime(int(N**0.5))
  p_f = [1]
  while n != 1:
    for p in P[1:]:
      if n%p == 0:
        p_f.append(p)
        n = n / p
        break
  return p_f
A, B = list(map(int, input().split(" ")))
print(len(set(prime_factorization(gcd(A, B))))
Problem p02901 (python)

Fixed submission:
N, M = list(map(int, input().split(" ")))
abc = [[0, 0, 0] for i in range(M)]
for i in range(M):
  abc[i][0], abc[i][1] = list(map(int, input().split(" ")))
  c = list(map(int, input().split(" ")))
  for j in c:
    cbits = (1 << j-1) 
    abc[i][2] |= cbits

dp = [0 if i == 0 else float("inf") for i in range(2**N)]
for i in range(M):
  for j in range(2**N):
    if dp[j|abc[i][2]] > dp[j]+abc[i][0]:
      dp[j|abc[i][2]] = dp[j]+abc[i][0]
print(dp[-1] if dp[-1] != float("inf") else -1)

Buggy submission (verdict: Runtime Error):
import math
N, M = list(map(int, input().split(" ")))
abc = [[0, 0, 0] for i in range(M)]
for i in range(M):
  abc[i][0], abc[i][1] = list(map(int, input().split(" ")))
  c = list(map(int, input().split(" ")))
  for j in range(N):
    cbits = (1 << j) * (j+1 in c)
    abc[i][2] |= cbits

dp = [0 if i == 0 else math.inf for i in range(2**N)]
for i in range(M):
  for j in range(2**N):
    dp[j|abc[i][2]] = min(dp[j]+abc[i][0], dp[j|abc[i][2]])
print(dp[-1] if dp[-1] != math.inf else -1)

Buggy submission (verdict: Runtime Error):
import math
N, M = list(map(int, input().split(" ")))
abc = [[0, 0, 0] for i in range(M)]
for i in range(M):
  abc[i][0], abc[i][1] = list(map(int, input().split(" ")))
  c = list(map(int, input().split(" ")))
  for j in range(N):
    cbits = (1 << j) * (j+1 in c)
    abc[i][2] |= cbits

dp = [0 if i == 0 else math.inf for i in range(2**N)]
for i in range(M):
  for j in range(2**N):
    dp[j|abc[i][2]] = min(dp[j]+abc[i][0], dp[j|abc[i][2]])
print(dp[-1] if dp[-1] != math.inf else -1)

Buggy submission (verdict: Runtime Error):
import math
N, M = list(map(int, input().split(" ")))
abc = [[0, 0, 0] for i in range(M)]
for i in range(M):
  abc[i][0], abc[i][1] = list(map(int, input().split(" ")))
  c = list(map(int, input().split(" ")))
  for j in range(N):
    cbits = (1 << j) * (j+1 in c)
    abc[i][2] |= cbits

dp = [0 if i == 0 else math.inf for i in range(2**N)]
for i in range(M):
  for j in range(2**N):
    dp[j|AB[i][2]] = min(dp[j]+AB[i][0], dp[j|AB[i][2]])
print(dp[-1] if dp[-1] != math.inf else -1)
Problem p03377 (python)

Fixed submission:
A, B, X = map(int, input().split(" "))
if X==A: print("YES")
elif X<A: print("NO")
else:
  if (X-A)<=B: print("YES")
  else: print("NO")

Buggy submission (verdict: Runtime Error):
A, B, X = map(int, raw_input().split(" "))
if A==X or (X-A)<=B: print("YES")
else: print("NO")

Buggy submission (verdict: Runtime Error):
A, B, X = map(int, raw_input().split(" "))
if (X-A)<=B and X>A: print("YES")
else: print("NO")
Problem p03378 (python)

Fixed submission:
N, M, X = map(int, input().split(" "))
A = map(int, input().split(" "))
left, right = 0,0
for ai in A:
  if ai < X: left+=1
  else: right+=1
print(min(right, left))

Buggy submission (verdict: Runtime Error):
N, M, X = map(int, raw_input().split(" "))
A = map(int, raw_input().split(" "))
r = len([ai for ai in A if ai < X])
l = len([ai for ai in A if ai > X])
print(min((r,l))

Buggy submission (verdict: Runtime Error):
N, M, X = map(int, raw_input().split(" "))
A = map(int, raw_input().split(" "))
left, right = 0,0
for ai in A:
  if ai < X: left+=1
  else: right+=1
print(min(right, left))

Buggy submission (verdict: Runtime Error):
N, M, X = map(int, input().split(" "))
A = map(int, raw_input().split(" "))
print(min([len([i for i in A if i >= X+1]), len([i for i in A if i <= X-1])]))
Problem p03379 (python)

Fixed submission:
N = int(input())
X = [int(i) for i in input().split()]
X_sorted = sorted(X)

X_med = X_sorted[N//2-1:N//2+1]
for xi in X:
  if xi <= X_med[0]: print(X_med[1])
  else: print(X_med[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [int(i) for i in input().split()]
for i in range(N): print((lambda j: sorted([x for k, x in enumerate(X) if not k == j]))(i)[N/2-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [int(i) for i in input().split()]
for i in range(N): print((lambda j: sorted([x for k, x in enumerate(X) if not k == j]))(i)[N/2-1])
Problem p03679 (python)

Fixed submission:
X, A, B = map(int, input().split())
if B <= A: print('delicious')
elif B <= A + X: print('safe')
else: print('dangerous')

Buggy submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
x = [False]*N
n,i = (0, 0)
while x[n] == False:
    x[n] = True
    n = a[n]-1
    i+=1
    if n==1:
        print(i)
        break
else:
    print(-1)
Problem p03680 (python)

Fixed submission:
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
x = [False]*N
n,i = (0, 0)
while x[n] == False:
    x[n] = True
    n = a[n]-1
    i+=1
    if n==1:
        print(i)
        break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
x = [False]*N
n,i = (1, 0)
while x[n-1] == False:
    x[n] = True
    n = a[n-1]
    i+=1
    if n==2:
        print(i)
        break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
if not(2 in a):
    print(-1)

x = [False]*N
n,i = (1, 0)
while x[n] == False:
    x[n] = True
    n = a[n-1]
    i+=1
    if n==2:
        print(i)
        break
else:
    print(-1)
Problem p03681 (python)

Fixed submission:
import math
N, M = map(int, input().split())
if N-M == 0:
    n = 2*math.factorial(N)*math.factorial(M)
    n %= int(7+1e9)
    print(n)
elif abs(N-M) == 1:
    n = math.factorial(N)*math.factorial(M)
    n %= int(7+1e9)
    print(n)
else:
    print(0)

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

if N-M == 0:
    n = 2*math.factorial(N)*math.factorial(M)
    n %= int(7+1e9)
    print(n)
elif abs(N-Mi) == 1:
    n = math.factorial(N)*math.factorial(M)
    n %= int(7+1e9)
    print(n)
else:
    print(0)
Problem p02555 (python)

Fixed submission:
S = int(input())
dp=[1]+[0 for i in range(S)]
i = 3
k=1000000007
if S <3:
  print(0)
else:
  while i <= S:
    dp[i]=(dp[i-1]+dp[i-3])%k
    i+=1
  print(dp[S])

Buggy submission (verdict: Runtime Error):
S = int(input())
dp=[1]+[0 for i in range(S)]
i = 3
k=1000000007
while True:
  dp[i]=(dp[i-1]+dp[i-3])%k
  if i == S:
    print(dp[-1])
    break
  i+=1
Problem p02573 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
 
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
 
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
 
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
 
    
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
 
n, m = map(int, input().split())
uf = UnionFind(n)
 
for i in range(m):
    a, b = map(int, input().split())
    uf.Unite(a, b)
 
ans = 0
 
for i in range(n):
    ans = max(ans, uf.Count(i))
 
print(ans)

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

N,M = map(int,input().split())
dic = {}
sets = {0}
for _ in range(M):
  a,b = map(int,input().split())
  if a in sets or b in sets:
    if a in sets and b in sets:
      tmp_a = 0
      tmp_b = 1
      # つなげる処理
      for key in dic.keys():
        if a in dic[key]:
          tmp_a = key
        if b in dic[key]:
          tmp_b = key
      if tmp_a != tmp_b:
        dic[tmp_a].union(dic[tmp_b])
        del dic[tmp_b]
      else:
        dic[tmp_a].add(a)
        dic[tmp_a].add(b)
    else:
      # 入っている方に追加する処理
      for vls in dic.values():
        if a in vls or b in vls:
          vls.add(a)
          vls.add(b)
  else:
    dic[_] = {a,b}
  sets.add(a)
  sets.add(b)

mx = 0

for vals in dic.values():
  mx = max(mx,len(vals))
print(mx)

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

N,M = map(int,input().split())
dic = {}
sets = {0}
for _ in range(M):
  a,b = map(int,input().split())
  if a in sets or b in sets:
    if a and b in sets:
      tmp_a = 0
      tmp_b = 1
      # つなげる処理
      for key in dic.keys():
        if a in dic[key]:
          tmp_a = key
        elif b in dic[key]:
          tmp_b = key
      if tmp_a != tmp_b:
        dic[tmp_a].union(dic[tmp_b])
        del dic[tmp_b]
      else:
        dic[tmp_a].add(a)
        dic[tmp_a].add(b)
    else:
      # 入っている方に追加する処理
      for vls in dic.values():
        if a in vls or b in vls:
          vls.add(a)
          vls.add(b)
  else:
    dic[_] = {a,b}
  sets.add(a)
  sets.add(b)

mx = 0

for vals in dic.values():
  mx = max(mx,len(vals))
print(mx)
Problem p02579 (python)

Fixed submission:
from collections import deque
 
 
walk = [(1, 0), (-1, 0), (0, 1), (0, -1)]
warp = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
        (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
        (0, -2), (0, -1), (0, 1), (0, 2),
        (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2),]
 
 
def get_warped(walked, map_):
    warped = deque()
    while walked:
        h, w = walked.popleft()
        for i, j in warp:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                warped.append((h2, w2))
                map_[h2][w2] = map_[h][w] + 1
    return warped, map_
 
 
def get_walked(candidate, map_):
    walked = deque()
    while candidate:
        h, w = candidate.popleft()
        walked.append((h, w))
        for i, j in walk:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                candidate.append((h2, w2))
                map_[h2][w2] = map_[h][w]
    return walked, map_
 
H, W = map(int, input().split())
s_h, s_w = [i-1 for i in map(int, input().split())]
d_h, d_w = [i-1 for i in map(int, input().split())]
map_ = [list(input()) for i in range(H)]
 
candidate = deque([(s_h, s_w)])
map_[s_h][s_w] = 0
 
while candidate:
    walked, map_ = get_walked(candidate, map_)
    candidate, map_ = get_warped(walked, map_)
 
for h in range(H):
    for w in range(W):
        if map_[h][w] == '.':
            map_[h][w] = -1
 
print(map_[d_h][d_w])

Buggy submission (verdict: Runtime Error):
H,W = map(int , input().split())
sh,sw = map(int , input().split())
eh,ew = map(int , input().split())
mv = [[-1,0],[1,0],[0,-1],[0,1]]
warplist = []
for h in range(-2,2,1):
  for w in range(-2,2,1):
    if h!=0 and w!=0:
      warplist.append([h,w])
maze = []
goned = [[None]*(W) for j in range(H)]
for i in range(H):
  maze.append(input())

def wfs(h,w):
  goned[h][w] = cnt
  for vh,vw in mv:
    tgh = h + vh
    tgw = w + vw
    if 0 <= tgh <= H-1 and 0 <= tgw <= W-1 :
      if goned[tgh][tgw] is None and maze[tgh][tgw] != "#":
        wfs(tgh,tgw)
        wps.append([tgh,tgw])

def warp(h,w):
  for vh,vw in warplist:
    tgh = h + vh
    tgw = w + vw
    if 0 <= tgh <= H-1 and 0 <= tgw <= W-1 :
      if goned[tgh][tgw] is None and maze[tgh][tgw] != "#":
        tgs.append([tgh,tgw])
wps=[]
tgs = [[sh-1,sw-1]]
cnt = 0
while len(tgs)>0:
  wps=[]
  for tg in tgs:
    wfs(tg[0],tg[1])
  tgs = []
  for wp in wps:
    warp(wp[0],wp[1])
  cnt+=1
print(-1 if goned[eh][ew] is None else goned[eh][ew])
Problem p02584 (python)

Fixed submission:
X, K, D = map(int, input().split())
 
Xa = abs(X)
Xs = Xa // D
Xm = Xa % D
 
if (K <= Xs):
    print(abs(Xa-D*K))
elif (K-Xs) % 2 == 0:
    print(abs(Xm))
else:
    print(abs(D-Xm))

Buggy submission (verdict: Runtime Error):
import math
 
X,K,D = map(int, input().split())
tm = round(X/D)
if K <= tm:
  print(abs(X+D*K)if absabs(X+D*K) < abs(X-D*K)else abs(X-D*K))
else:
  if (K-tm)%2==1:
    print(abs(X-D*(tm+1)) if abs(X-D*(tm+1)) < abs(X-D*(tm-1))else abs(X-D*(tm-1)))
  else:
    print(abs(X+D*K)if absabs(X+D*K) < abs(X-D*K)else abs(X-D*K))

Buggy submission (verdict: Runtime Error):
import math

X,K,D = map(int, input().split())
tm = round(X/D)
if K <= tm:
  print(abs(X-D*K))
else:
  if (K-tm)%2==1:
    if math.modf(X/D)<0.5:
      print(abs(X-D*(tm+1)))
    else:
      print(abs(X-D*(tm-1)))
  else:
    print(abs(X-D*tm))
Problem p03471 (python)

Fixed submission:
a,sums= list(map(int,input().split()))
yuki = sums//10000
taishi = (sums%10000) //5000
noguchi = (sums%5000) //1000
while a>yuki+taishi+noguchi:
  if ((a-(yuki+taishi+noguchi))%4==0)&(taishi>0):
    taishi-=1
    noguchi+=5
  elif yuki>0:
    yuki-=1
    taishi+=2
  else:
    break
if a==yuki+taishi+noguchi:
  print(yuki,taishi,noguchi)
else:
  print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
a,sums= list(map(int,input().split()))
print(a)
yuki = sums//10000
taishi = (sums%10000) //5000
noguchi = (sums%5000) //1000
while a<yuki+taishi+noguchi:
  if a-(yuki+taishi+noguchi)%4==0:
    taishi-=1
    noguchi+=5
  else:
    yuki-=1
    taishi+=2
if a==yuki+taishi+noguchi:
  print(yuki,taishi,noguchi)
else print("-1 -1 -1")
Problem p03773 (python)

Fixed submission:
A,B = map(int,input().split())
print((A+B) % 24)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
return A+B % 24
Problem p04045 (python)

Fixed submission:
a = input().split()
tg = a[0]
ok_nums = set(str(i) for i in range(10))
ng_nums = set(i for i in input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
intg = int(tg)
while intg > rt:
  if ok_nums >= set(d for d in str(i)):
    rt = i
  else:
    i+=1

print(rt)

Buggy submission (verdict: Runtime Error):
a = input().split()
tg = a[0]
ok_nums = set("1","2","3","4","5","6","7","8","9","0")
ng_nums = set(input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
while True:
  if ok_nums >= set(d for d in str(i)):
    print(i)
    break
  else:
    i+=1
Problem p02787 (python)

Fixed submission:
INF = 10**12
maxH = 2 * 10**4 + 10

def solve():
    H, N = map(int, input().split())
    ABs = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [INF] * (maxH+1)
    dp[0] = 0
    for A, B in ABs:
        for h in range(maxH-A+1):
            h2 = h + A
            dp2 = dp[h] + B
            if dp2 < dp[h2]:
                dp[h2] = dp2

    print(min(dp[H:]))


solve()

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

def solve():
    INF = float('inf')

    def min2(x, y): return x if x <= y else y

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

    items.sort()

    dp = [INF] * (H+1)
    dp[0] = 0
    for vi, wi in items:
        for j in range(H-vi+1):
            dp[j+vi] = min2(dp[j+vi], dp[j]+wi)
        for j in range(H-vi+1, H+1):
            dp[H] = min2(dp[H], dp[j]+wi)
#        print(dp)

    print(dp[H])


solve()