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

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

def d(tree, array, v):
  next_v = tree.get(v)
  
  for nv, nd in next_v:
    if array[nv] == -1:
      array[nv] = array[v] + nd
      d(tree, array, nv)
  

n = int(input())
tree = {}

for i in range(n-1):
  a,b,c = map(int, input().split())
  a -= 1
  b -= 1
  
  array = tree.get(a, [])
  array.append((b,c))
  tree[a] = array
  
  array = tree.get(b, [])
  array.append((a,c))
  tree[b] = array
  
q,k = map(int, input().split())
k -= 1

array = [-1] * n
array[k] = 0

d(tree, array, k)

ans = []
for i in range(q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  
  ans.append(array[x] + array[y])
  
for i in range(len(ans)):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

def d(tree, array, v):
  next_v = tree.get(v)
  
  for nv, nd in next_v:
    if array[nv] == -1:
      array[nv] = array[v] + nd
      d(tree, array, nv)
  

n = int(input())
tree = {}

for i in range(n-1):
  a,b,c = map(int, input().split())
  a -= 1
  b -= 1
  
  array = tree.get(a, [])
  array.append((b,c))
  tree[a] = array
  
  array = tree.get(b, [])
  array.append((a,c))
  tree[b] = array
  
q,k = map(int, input().split())
k -= 1

array = [-1] * n
array[k] = 0

d(tree, array, k)

ans = []
for i in range(q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  
  ans.append(array[x] + array[y])
  
for i in range(len(ans)):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
def d(tree, array, v):
  next_v = tree.get(v)
  
  for nv, nd in next_v:
    if array[nv] == -1:
      array[nv] = array[v] + nd
      d(tree, array, nv)
  

n = int(input())
tree = {}

for i in range(n-1):
  a,b,c = map(int, input().split())
  a -= 1
  b -= 1
  
  array = tree.get(a, [])
  array.append((b,c))
  tree[a] = array
  
  array = tree.get(b, [])
  array.append((a,c))
  tree[b] = array
  
q,k = map(int, input().split())
k -= 1

array = [-1] * n
array[k] = 0

d(tree, array, k)

ans = []
for i in range(q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  
  ans.append(array[x] + array[y])
  
for i in range(len(ans)):
  print(ans[i])
Problem p02777 (python)

Fixed submission:
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
if s==u: a-=1
else: b-=1
print(a,b)

Buggy submission (verdict: Runtime Error):
s,t=map(int,input().split())
a,b=map(int,input().split())
if s==input(): a-=1
else: b-=1
print(a,b)
Problem p02781 (python)

Fixed submission:
from functools import lru_cache
n=int(input())
k=int(input())
@lru_cache(None)
def cal(n,k):
  if n<10:
    if k==0: return 1
    if k==1: return n
    return 0
  q,r=divmod(n,10)
  ret=0
  if k>=1:
    ret+=cal(q,k-1)*r
    ret+=cal(q-1,k-1)*(9-r)
  ret+=cal(q,k)
  return ret

print(cal(n,k))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
@lru_cache(None)
n=int(input())
k=int(input())
def cal(n,k):
  if n<10:
    if k==0: return 1
    if k==1: return n
    return 0
  q,r=divmod(n,10)
  ret=0
  if k>=1:
    ret+=cal(q,k-1)*r
    ret+=cal(q-1,k-1)*(9-r)
  ret+=cal(q,k)
  return ret

print(cal(n,k))
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
try:
  a = int(input())
except EOFError:
  a = 0
P = [0]*(N+1)
P[0] = 1
if a == 1:
  P[1] = 0
  try:
    a = int(input())
  except EOFError:
    pass
    
else:
  P[1] = 1

for i in range(2,N+1):
  if i == a:
    P[i] = 0
    try:
      a = int(input())
    except EOFError:
      continue
  else:
    P[i] = P[i-1] + P[i-2]
print(P[-1]%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = int(input())
P = [0]*(N+1)
P[0] = 1
if a == 1:
  P[1] = 0
  try:
    a = int(input())
  except EOFError:
    pass
    
else:
  P[1] = 1

for i in range(2,N+1):
  if i == a:
    P[i] = 0
    try:
      a = int(input())
    except EOFError:
      continue
  else:
    P[i] = P[i-1] + P[i-2]
print(P[-1]%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = int(input())
P = [0]*(N+1)
P[0] = 1
if a == 1:
  P[1] = 0
  a = int(input())
else:
  P[1] = 1

for i in range(2,N+1):
  if i == a:
    P[i] = 0
    try:
      a = int(input())
    except EOFError:
      continue
  else:
    P[i] = P[i-1] + P[i-2]
print(P[-1]%1000000007)
Problem p03053 (python)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

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

H,W = map(int,input().split())
D = [list(input()) for i in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        sy = i
        sx = j
        if D[sy][sx] == ".":
            Q = deque()
            Q.append((sx,sy))
            dist = [[-1]*W for i in range(H)]
            dist[sy][sx] = 0
            dx = [1,0,-1,0]
            dy = [0,-1,0,1]
            while Q:
                x,y = Q.popleft()
                if D[y][x] == "#":
                    d = dist[y][x]
                    ans = max(ans,d)
                    break
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if 0<=nx<=W-1 and 0<=ny<=H-1 and dist[ny][nx] == -1:
                        Q.append((nx,ny))
                        dist[ny][nx] = dist[y][x]+1

print(ans)

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

H,W = map(int,input().split())
D = [list(input()) for i in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        sy = i
        sx = j
        if D[sy][sx] == ".":
            Q = deque()
            Q.append((sx,sy))
            dist = [[-1]*W for i in range(H)]
            dist[sy][sx] = 0
            dx = [1,0,-1,0]
            dy = [0,-1,0,1]
            while Q:
                x,y = Q.popleft()
                if D[y][x] == "#":
                    d = dist[y][x]
                    ans = max(ans,d)
                    break
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if 0<=nx<=W-1 and 0<=ny<=H-1 and dist[ny][nx] == -1:
                        Q.append((nx,ny))
                        dist[ny][nx] = dist[y][x]+1

print(ans)
Problem p03221 (python)

Fixed submission:
N, M = map(int, input().split())
PY = [list(map(int,input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)
  
PY.sort(key=lambda x:x[1])
pcount = {i:0 for i in range(1,N+1)}
ID = {i:"" for i in range(1,M+1)}

for i in range(M):
  pcount[PY[i][0]] += 1
  PY[i].append("{:0=6}".format(PY[i][0]) + "{:0=6}".format(pcount[PY[i][0]]))
PY.sort(key=lambda x:x[2])
for i in range(M):
  print(PY[i][3])

Buggy submission (verdict: Runtime Error):
import bisect
N, M = map(int, input().split())
city = []
table = [0]*M
count = [0]*M
for i in range(M):
  P, Y = map(int, input().split())
  P -= 1
  city.append((i,P,Y))
city.sort(key=lambda x:x[2])
for i, P, Y in city:
  count[P] += 1
  x = str(count[P])
  P = str(P+1)
  ans = P.zfill(6)+x.zfill(6)
  table[i] = ans
for i in range(M):
  print(table[i])
Problem p03265 (python)

Fixed submission:
x1, y1, x2, y2 = map(int, input().split())
  
dx, dy = x2-x1, y2-y1
x3, y3, x4, y4 = x2-dy, y2+dx, x1-dy, y1+dx

print(x3, y3, x4, y4)

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

l = max(abs(x1-x2), abs(x2-y2))

if x1 == x2 and y1 > y2:
  x3, y3, x4, y4 = x2+l, y2, x1+l, y1
elif x1 < x2 and y1 == y2:
  x3, y3, x4, y4 = x2, y2+l, x1, y1+l
elif x1 == x2 and y1 < y2:
  x3, y3, x4, y4 = x2-l, y2, x1-l, y1
elif x1 > x2 and y1 == y2:
  x3, y3, x4, y4 = x2, y2-l, x1, y1-l
print(x3, y3, x4, y4)
Problem p03745 (python)

Fixed submission:
N = int(input())
if N == 1:
  print(1)
  exit()
A = [int(i) for i in input().split()]
ans = 1
if A[1] - A[0] > 0:
  pre = 1
elif A[1] - A[0] == 0:
  pre = 0
else:
  pre = -1

for i in range(2,N):
  if A[i] - A[i-1] > 0:
    now = 1
  elif A[i] - A[i-1] == 0:
    now = pre
  else:
    now = -1
  if now*pre < 0:
    ans += 1
    pre = 0
  else:
    pre = now
  
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
ans = 1
if A[1] - A[0] > 0:
  pre = 1
elif A[1] - A[0] == 0:
  pre = 0
else:
  pre = -1

for i in range(2,N):
  if A[i] - A[i-1] > 0:
    now = 1
  elif A[i] - A[i-1] == 0:
    now = 0
  else:
    now = -1
  if now*pre < 0:
    ans += 1
    pre = 0
  else:
    pre = now
  
print(ans)
Problem p03774 (python)

Fixed submission:
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, 10**9
  ans = 1
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a, b, c, d = [],[],[],[]

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, INF
  ans = 1
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)
Problem p03805 (python)

Fixed submission:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]
visited = {i:False for i in range(N)}
visited[0] = True
ans = 0

def DFS(x):
#  print(visited)
  global ans
  nextx = []
  if False not in visited.values():
    ans += 1
    return
  for i in range(M):
    if x in ab[i]:
      xcol = ab[i].index(x)
      if visited[ab[i][1-xcol]-1]:
        continue
      else:
        nextx.append(ab[i][1-xcol])
#  print(nextx)
  for i in nextx:
    visited[i-1] = True
    DFS(i)
    visited[i-1] = False
  return

DFS(1)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]
visited = {i:False for i in range(M)}
visited[0] = True
ans = 0

def DFS(x):
  global ans
  nextx = []
  if False not in visited.values():
    ans += 1
    return
  for i in range(M):
    if x in ab[i]:
      xcol = ab[i].index(x)
      if visited[ab[i][1-xcol]-1]:
        continue
      else:
        nextx.append(ab[i][1-xcol])
  for i in nextx:
    visited[i-1] = True
    DFS(i)
    visited[i-1] = False
  return

DFS(1)
print(ans)
Problem p03806 (python)

Fixed submission:
N, Ma, Mb = map(int, input().split())
table = []
for i in range(N):
  a,b,c = map(int, input().split())
  table.append([a,b,c])
inf = 10**9
dp = [[[inf]*401 for i in range(401)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(1,N+1):
  a,b,c = table[i-1]
  for j in range(401):
    for k in range(401):
      dp[i][j][k] = dp[i-1][j][k]
      if 400>=j-a>=0 and 400>=k-b>=0:
        dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a][k-b]+c)
ans = 10**9
i = 1
while max(Ma,Mb)*i <= 400:
  ans = min(ans,dp[N][Ma*i][Mb*i])
  i += 1
if ans == 10**9:
  ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
N,Ma,Mb = map(int,input().split())
table = []
sum_a,sum_b,sum_c = 0,0,0

for i in range(N):
  a,b,c=map(int,input().split())
  sum_a += a 
  sum_b += b
  sum_c += c
  table.append((a,b,c))
  
INF = sum_c+1
ans = INF
dp=[[[INF]*(sum_a+1) for i in range(sum_b+1)] for i in range(N+1)]
dp[0][0][0] = 0
for i in range(1,N+1):
  a,b,c = table[i-1]
  for ca in range(sum_a+1):
    for cb in range(sum_b+1):
      dp[i][ca][cb] = min(dp[i-1][ca][cb],dp[i][ca][cb])
      if ca+a < sum_a and cb+b < sum_b:
        dp[i][ca+a][cb+b] = min(dp[i][ca+a][cb+b],dp[i][ca][cb]+c)

for ca in range(sum_a+1):
  for cb in range(sum_b+1):
    if ca*Ma == cb*Mb and ca*cb != 0:
      for i in range(N+1):
        ans = min(ans,dp[i][ca][cb])
print(ans if ans != INF else -1)

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

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

for i in range(2**N):
  a, b = 0, 0
  cost = []
  for j in range(N):
    if (i>>j) & 1:
      cost.append(abc[j][2])
      a += abc[j][0]
      b += abc[j][1]
  if a/Ma == b/Mb and sum(cost) > 0:
    tmp.append(sum(cost))
print(min(tmp))
Problem p03774 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os


N, M = list(map(int, input().split()))
students = []
checkpoints = []

for i in range(N):
    a, b = list(map(int, input().split()))
    students.append([a, b])

for i in range(M):
    a, b = list(map(int, input().split()))
    checkpoints.append([a, b])

for student in students:
    min_dist = float('inf')
    min_i = None
    for i, checkpoint in enumerate(checkpoints):
        manhattan_dist = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
        if manhattan_dist < min_dist:
            min_dist = manhattan_dist
            min_i = i
    print(min_i + 1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os

N, M = list(map(int, input().split()))
students = []
checkpoints = []

for i in range(N):
    a, b = list(map(int, input().split()))
    students.append([a, b])

for i in range(N):
    a, b = list(map(int, input().split()))
    checkpoints.append([a, b])

for student in students:
    min_dist = float('inf')
    min_i = None
    for i, checkpoint in enumerate(checkpoints):
        manhattan_dist = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
        if manhattan_dist < min_dist:
            min_dist = manhattan_dist
            min_i = i
    print(min_i + 1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import pprint
from queue import Queue


N, M = list(map(int, input().split()))
students = []
checkpoints = []

for i in range(N):
    a, b = list(map(int, input().split()))
    students.append([a, b])

for i in range(N):
    a, b = list(map(int, input().split()))
    checkpoints.append([a, b])

for student in students:
    min_dist = float('inf')
    min_i = None
    for i, checkpoint in enumerate(checkpoints):
        manhattan_dist = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
        if manhattan_dist < min_dist:
            min_dist = manhattan_dist
            min_i = i
    print(min_i + 1)
Problem p02571 (python)

Fixed submission:
import numpy as np

s = input()
t = input()

len_s = len(s)
len_t = len(t)

ma = 0
for i in range(len_s - len_t + 1):
    ma = max(ma, np.sum(np.array(list(s[i: i + len_t])) == np.array(list(t))))

ans = len_t - ma

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

s = input()
t = input()

len_s = len(s)
len_t = len(t)

ma = 0
for i in range(len_s - len_t + 1):
    ma = max(ma, np.sum(np.array(list(s[i: i + len_t])) == np.array(list(t))))

ans = len_t - ma

print(ans)
Problem p02725 (python)

Fixed submission:
import numpy as np

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

a_array.append(k + a_array[0])

a_diff = np.diff(a_array)
ans = np.sum(a_diff) - np.max(a_diff)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

a_array.append(k + a_array[0])

a_diff = np.diff(a_array)
ans = np.sum(a_diff) - np.max(a_diff)
print(ans)
Problem p02753 (python)

Fixed submission:
s = input()

s_count_A = s.count('A')

if s_count_A == 0 or s_count_A == 3:
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

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

lS = ''
for _ in range(Q):
    query = input().split()
    if query[0] == '1':
        lS, S = S, lS
    else:
        if query[1] == '1':
            lS += query[2]
        else:
            S += query[2]

print(lS[::-1] + S)
Problem p02781 (python)

Fixed submission:
def f(s, t, k):
 n = len(s)
 if k > n: return 0
 a = max(t, int(s[0]))
 if a == 0: return f(s[1:], t, k)
 if k == 1: return a + (n - 1) * 9
 z = 0
 if k - 1 <= n: z += f(s[1:], 9, k)
 z += (a - 1) * f(s[1:], 9, k - 1)
 z += f(s[1:], t, k - 1)
 return z

s = input()
k = int(input())
print(f(s, 0, k))

Buggy submission (verdict: Runtime Error):
s=input()*2;n=len(s)//2;X=[(0,0)]*4
for j in range(n+1):
 for k in range(3,-1,-1):
  a=int(s[n-j])
  X[k]=(X[k][0]+9*X[k-1][0],X[k][0]+(a-1)*X[k-1][0]+X[k-1][1]if a else X[k][1])if k else 1
print(X[int(input())][1])

Buggy submission (verdict: Runtime Error):
def f(s,t,k):
 n=len(s)
 a=max(t,int(s[0]))
 z=0
 if k>n:z=0
 elif a==0:z=f(s[1:],t,k)
 elif k==1:z=a+(n-1)*9
 else:
  if k-1<=n:z+=f(s[1:],9,k)
  z+=(a-1)*f(s[1:],9,k-1)
  z+=f(s[1:],t,k-1)
 return z
print(f(input(),0,int(input())))

Buggy submission (verdict: Runtime Error):
def f(s,t,k):
 n=len(s)
 a=max(t,int(s[0]))
z=0
 if k>n:z=0
 elif a==0:z=f(s[1:],t,k)
 elif k==1:z=a+(n-1)*9
 else:
  if k-1<=n:z+=f(s[1:],9,k)
  z+=(a-1)*f(s[1:],9,k-1)
  z+=f(s[1:],t,k-1)
 return z
print(f(input(),0,int(input())))

Buggy submission (verdict: Runtime Error):
def f(s,t,k):
 n=len(s)
 a=max(t,int(s[0]))
 if k>n:z=0
 elif a==0:z=f(s[1:],t,k)
 elif k==1:z=a+(n-1)*9
 else:
  z=0
  if k-1<=n:z+=f(s[1:],9,k)
  z+=(a-1)*f(s[1:],9,k-1)
  z+=f(s[1:],t,k-1)
 return z
print(f(input(),0,int(input())))
Problem p02773 (python)

Fixed submission:
N=int(input())
S = {}
for i in range(N):
    let = input()
    try:
        S[let] += 1
    except:
        S[let] = 1
max_val = max(S.values())
answers = []
for k,v in S.items():
    if v == max_val:
        answers.append(k)
answers.sort()
for ans in answers:
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S = {}
for i in range(N):
    let = input()
    try:
        S[let] += 1
    except:
        S[let] = 1
max_val = max(S.values())
answers = []
for k,v in S.items():
    if v == max_val:
        answers.append(k)
ansewrs.sort()
for ans in ansewrs:
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S = {}
for i in range(n):
    let = input()
    try:
        S[let] += 1
    except:
        S[let] = 1
max_val = max(S.values())
key for key in d:
    if S[key] == max_val:
        print('\d'.join(S[key]))

Buggy submission (verdict: Runtime Error):
N = int(input())
*S = map(int, open(0).read().split())
SS = {}
for i in range(N):
    if S[i] in SS:
        SS[S[i]] +=1
    else:
        SS[S[i]] = 1
SS = ser = ser.sort_values(ascending=False)
for i in range(N+1):
    print(SS[i])
    if SS[i] != SS[i + 1]:
        break
Problem p03835 (python)

Fixed submission:
K,S=map(int,input().split())
ans = 0
z = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z >= 0 and z <= K:
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
K,S=map(int,input().split())
ans = 0
z = 0
for x in range(K):
    for y in range(K):
        z = S - x - y
        if z >= 0 and Z <= K:
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
K,S=map(int,input().split())
ans = 0
for x in range(K):
    for y in range(K):
        z = S - x - y
        if z >= 0 and Z <= K:
            ans += 1
print(ans)
Problem p02831 (python)

Fixed submission:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

a,b = map(int, input().split())
ans = a*b
c = gcd(a,b)
print(ans//c)

Buggy submission (verdict: Runtime Error):
import math

a,b = map(int, input().split())
ans = a*b
ans = ans//math.gcd(a,b)
print(ans)
Problem p02912 (python)

Fixed submission:
import heapq

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

a = [-i for i in list(map(int, input().split()))]
heapq.heapify(a)

for i in range(m):
    p = heapq.heappop(a)
    p = (-p)//2
    heapq.heappush(a, -p)
    
print(-sum(a))

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(m):
    a[0] = a[0]//2
    if a[0]<a[1]:
        a.sort(reverse=True)
print(sum(a))
Problem p02951 (python)

Fixed submission:
a, b, c=map(int,input().split())
x = min(a-b,c)
print(c-x)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split())
print(c-a+b)
Problem p03041 (python)

Fixed submission:
n,k = map(int, input().split())
s = list(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
print("".join(s))

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
s = str(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
print(s)
Problem p03207 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
print(int(max(a)*0.5+sum(a)-max(a)))

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [int(input()) for i in range(n)]

p.sort()
print(sum(p) - int(a[-1]/2))
Problem p03209 (python)

Fixed submission:
n,x = map(int, input().split())
a = [1]
p = [1]
for i in range(n):
    a.append(a[i]*2 + 3)
    p.append(p[i]*2 + 1)

def f(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=1 + a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1] + 1 + f(n-1,x-2-a[n-1])

print(f(n,x))

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())
burger = []
for i in range(n+1):
    if i == 0:
        burger.append("p")
    else:
        burger.append("b" + burger[i-1] + "p" + burger[i-1] + "b")
s = str(burger[n])
layer = s[:x]
print(layer.count("p"))
Problem p03252 (python)

Fixed submission:
import collections
s = input()
t = input()
s = collections.Counter(s)
t = collections.Counter(t)
if sorted(s.values()) == sorted(t.values()):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

dict_st = {}
dict_st = {}

for x, y in zip(s, t):
    if x not in dict_st:
        dict_st[x] = y 
    else:
        if dict_st[x] != y:
            print("No")
            break

    if y not in dict_ts:
        dict_ts[y]=x
    else:
        if dict_ts[y]!=x:
            print("No")
            break
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
import collections
s = input()
t = input()
s = collections.Counter(s)
t = collections.Counter(t)
if sorted(s.values()) == sorted(t.values):
  print("Yes")
else:
  print("No")
Problem p02571 (python)

Fixed submission:
a=list(input())
b=list(input())
l=[]
for i in range(len(a)-len(b)+1):
  c=0
  for j in range(len(b)):
    if a[j+i]==b[j]:
      c+=1
  l.append(c)
print(len(b)-max(l))

Buggy submission (verdict: Runtime Error):
s=list(input())
t=list(input())
l=[]
for i in range(len(s)-len(t)+1):
    c=0
    for j in range(len(t)):
        if s[j+i]==t[j]:
            c+=1
            l.append(c)
print(len(t)-max(l))
Problem p02819 (python)

Fixed submission:
import math
s = int(input())
if s ==2:
  print(2)
else:
  for i in range(s,2*s):
    if i%2==0:
      continue
    for k in range(3,round(math.sqrt(s))+1,2):
      t = 1
      if i%k ==0:
        t = 0
        break
    if t ==1:
      print(i)
      break

Buggy submission (verdict: Runtime Error):
import math
s = int(input())
for i in range(s,2*s):
  if i%2==0:
    continue
  for k in range(3,round(math.sqrt(s))+1,2):
    t = 1
    if i%k ==0:
      t = 0
      break
  if t ==1:
    print(i)
    break