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

Fixed submission:
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N + 1)]
arrow = [0] * (N + 1)

for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
    
def bfs(st, graph):
    INF = 10 ** 18
    dist = [0] * len(graph)
    dist[st] = 1
    queue = deque([st])
    while queue:
        q = queue.popleft()
        for r in graph[q]:
            if dist[r] == 0:
                dist[r] = q
                queue.append(r)
    return dist

answer = bfs(1, graph)[2:]
print("Yes")
for a in answer:
    print(a)

Buggy submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N + 1)]
arrow = [0] * (N + 1)

for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
    
def bfs(st, graph):
    INF = 10 ** 18
    dist = [0] * len(graph)
    dist[st] = 1
    queue = deque([st])
    while queue:
        q = queue.popleft()
        for r in graph[q]:
            if dist[r] == 0:
                dist[r] = q
                queue.append(r)
    return dist

answer = bfs(1, graph)[2:]
print("Yes")
for a in answer:
    print(a)
Problem p02698 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

def LLL(a, ls):
    INF = 10 ** 15
    
    flag = 0
    prev = 0
    indx = 0
    ls_i = bisect_left(ls, a)
    if a < ls[ls_i]:
        flag = 1
        prev = ls[ls_i]
        indx = ls_i
    ls[ls_i] = min(ls[ls_i], a)

    ls_ii = bisect_left(ls, INF)
    return ls_ii, ls, flag, prev, indx

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = [0] + list(map(int, input().split()))
UV = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for uv in UV:
    u, v = uv
    graph[u].append(v)
    graph[v].append(u)
#print(graph)

INF = 10 ** 15

LIS = [INF for i in range(N + 2)]

answer = [0] * (N + 1)
def dfs(prev, n, LIS):
    answer[n], LIS, flag, prv, indx = LLL(A[n], LIS)
    #print(n, LIS, flag, prv, indx)
    for g in graph[n]:
        if g != prev:
            dfs(n, g, LIS)
    if flag:
        LIS[indx] = prv

dfs(-1, 1, LIS)

for a in answer[1:]:
    print(a)

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

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

def LIS(arr):
    from bisect import bisect_left
    INF = 10 ** 15
    
    len_arr = len(arr)
    LIS = [INF for i in range(len_arr + 1)]
  
    for a in arr:
      LIS_i = bisect_left(LIS, a)
      LIS[LIS_i] = min(LIS[LIS_i], a)

    for i in range(len_arr + 1):
      if LIS[i] == INF:
        return i

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = [0] + list(map(int, input().split()))
UV = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for uv in UV:
    u, v = uv
    graph[u].append(v)
    graph[v].append(u)
#print(graph)

answer = [0] * (N + 1)
def dfs(prev, n, lst):
    answer[n] = LIS(lst)
    for g in graph[n]:
        if g != prev:
            dfs(n, g, lst + [A[g]])

dfs(-1, 1, [A[0]])

for a in answer[1:]:
    print(a)
Problem p02788 (python)

Fixed submission:
import sys
input = sys.stdin.buffer.readline

from bisect import bisect_right

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
X = [x for x, h in XH]

check = [0] * (N + 1)


index = 0
pt = XH[index][0] + 2 * D
ht = (-(-XH[index][1] // A)) * A
minus = ht
answer = -(-XH[index][1] // A)
bi = bisect_right(X, pt)
check[bi] += ht

while 1:
  flag = 1
  for i in range(index, N):
    minus -= check[i]
    XH[i][1] -= minus
    check[i] = 0
    if XH[i][1] > 0:
      index = i
      flag = 0
      break
  if flag:
    break
  pt = XH[index][0] + 2 * D
  ht = (-(-XH[index][1] // A)) * A
  minus += ht
  answer += -(-XH[index][1] // A)
  bi = bisect_right(X, pt)
  check[bi] += ht
                 
print(answer)

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

N, D, A = map(int, input().split())
XH = [list(map(int, input().split()))for _ in range(N)]

XH.sort()
print(XH)


for i in range(N):
    bit_add_sec(bit1, bit2, i, i, XH[i][1])


bit1 = [0] * (N + 1)
bit2 = [0] * (N + 1)

def bit_add(b, i, v):
    while i <= N:
        b[i] += v
        i += i & - i
        
def bit_sum(b, i):
    s = 0
    while i:
        s += b[i]
        i -= i & -i
    return s

def bit_add_sec(b1, b2, l, r, x):
    bit_add(b1, l, -x * (l - 1))
    bit_add(b2, l, x)
    bit_add(b1, r + 1, x * r)
    bit_add(b2, r + 1, -x)

def bit_sum_sec(b1, b2, l, r, x):
    res = 0
    res += bit_sum(b1, r) + bit_sum(b2, r) * r
    res -= bit_sum(b1, l - 1) + bit_sum(b2, l - 1) * (l - 1)
    return res
Problem p02805 (python)

Fixed submission:
import math

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    """
    3点を通る円の中心と半径を取得
    """
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if d == 0:
      return (0, 0), 0
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
    return (x, y), r
  
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
answer = []
if N == 2:
  xy1, xy2 = XY
  x1, y1 = xy1
  x2, y2 = xy2
  answer.append(((x2 - x1)**2 + (y2 - y1)**2)**0.5 / 2)
else:
  for i in range(N):
    xi, yi = XY[i]
    for j in range(i + 1, N):
      xj, yj = XY[j]      
      r = ((xi - xj)**2 + (yi - yj)**2)**0.5/2
      x0, y0 = ((xi + xj) / 2, (yi + yj) / 2)
      flag = 1
      for ii in range(N):
        xii, yii = XY[ii]
        if ((x0 - xii)**2 + (y0 - yii)**2)**0.5 > r:
          flag = 0
          break
      if flag:
        answer.append(r)

  for i in range(N):
    xi, yi = XY[i]
    for j in range(i + 1, N):
      xj, yj = XY[j]
      for k in range(j + 1, N):
        xk, yk = XY[k]
        xy0, r = get_circle_center_and_radius(xi, yi, xj, yj, xk, yk)
        x0, y0 = xy0
        
        if r:
          flag = 1
          for ii in range(N):
            xii, yii = XY[ii]
            if ((x0 - xii)**2 + (y0 - yii)**2)**0.5 > r:
              flag = 0
              break
          if flag:
            answer.append(r)
print(min(answer))

Buggy submission (verdict: Runtime Error):
import math

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    """
    3点を通る円の中心と半径を取得
    """
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if d == 0:
      return (0, 0), 0
    x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
    y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
    r = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
    return (x, y), r
  
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
answer = []
if N == 2:
  xy1, xy2 = XY
  x1, y1 = xy1
  x2, y2 = xy2
  answer.append(((x2 - x1)**2 + (y2 - y1)**2)**0.5 / 2)
else:
  for i in range(N):
    xi, yi = XY[i]
    for j in range(i + 1, N):
      xj, yj = XY[j]
      for k in range(j + 1, N):
        xk, yk = XY[k]
        xy0, r = get_circle_center_and_radius(xi, yi, xj, yj, xk, yk)
        x0, y0 = xy0
        
        if r:
          flag = 1
          for ii in range(N):
            xii, yii = XY[ii]
            if ((x0 - xii)**2 + (y0 - yii)**2)**0.5 > r:
              flag = 0
              break
          if flag:
            answer.append(r)
print(min(answer))
Problem p02821 (python)

Fixed submission:
from bisect import bisect_left

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

A.sort()
left = 0
right = max(A) * 2 + 1

while left + 1 < right:
  mid = (left + right) // 2
  
  cnt = 0
  for i in range(N):
    cnt += N - bisect_left(A, mid - A[i])
  if cnt >= M:
    left = mid
  else:
    right = mid

Acum = [0]
for a in A:
  Acum.append(Acum[-1] + a)

answer = 0
cnt = 0
for i in range(N):
  bi = bisect_left(A, left - A[i])
  answer += (Acum[-1] - Acum[bi]) + (N - bi) * A[i]
  cnt += (N - bi)
answer -= (cnt - M) * left

print(answer)

Buggy submission (verdict: Runtime Error):
import bisect
 
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
def cnt(a, m):
  cnt_tmp = 0
  for aa in a:
    bi = bisect.bisect_left(a, m - aa)
    #print(a, m, m - aa, bi)
    cnt_tmp += N - bi
  return cnt_tmp
 
A.sort()
 
l = 0
r = 10**10
 
while l+1<r:
  mid = (l + r) // 2
  cnt_loop1 = cnt(A, mid)
  #cnt_loop2 = cnt(A, mid+1)
  #print(mid, cnt_loop1, cnt_loop2)
  
  if cnt_loop1 >= M and cnt_loop2 < M:
    break
  if cnt_loop1 >= M:
    l = mid
  else:
    r = mid
#print(mid, cnt_loop1, cnt_loop2)
 
S = [0] * (N+1)
for i in range(1, N+1):
  S[i] = S[i-1]+A[i-1]
#print(S[N])
 
answer = 0
for aa in A:
  bi = bisect.bisect_left(A, mid - aa)
  answer += S[N] - S[bi] + (N - bi) * aa
print(answer-(cnt_loop1-M)*mid)
Problem p02839 (python)

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

dp = [[0 for _ in range(W)] for _ in range(H)]

SIZE = 20000

D = abs(A[0][0] - B[0][0])
dp[0][0] = 1 << SIZE - D | 1 << SIZE + D
#print("dp:", dp)

for i in range(H):
  for j in range(W):
    D = abs(A[i][j] - B[i][j])
    dp[i][j] |= dp[i - 1][j] << D | dp[i - 1][j] >> D
    dp[i][j] |= dp[i][j - 1] << D | dp[i][j - 1] >> D

#for i in range(H):
#  a = list(map(lambda x: bin(x)[2::], dp[i]))
#  print(a)

for i in range(SIZE):
  if (dp[-1][-1] >> (SIZE + i)) & 1:
    print(i)
    exit()

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

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
SIZE = 10

AB = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        AB[i][j] = abs(A[i][j] - B[i][j])


dp = [[0 for _ in range(W)] for _ in range(H)]

dp[0][0] = 1 << (SIZE + AB[i][j] - 1) | 1 << (SIZE - AB[i][j] - 1)
for i in range(H):
    for j in range(W):
        dp[i][j] |= (dp[i - 1][j] << AB[i][j]) | (dp[i - 1][j] >> AB[i][j])
        dp[i][j] |= (dp[i][j - 1] << AB[i][j]) | (dp[i][j - 1] >> AB[i][j])

for i in range(SIZE):
    if (dp[-1][-1] >> (i + SIZE)) & 1:
        print(i)
        exit()

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

C = [[] for _ in range(H)]
for i in range(H):
  for j in range(W):
    C[i].append(abs(A[i][j] - B[i][j]))
#print(C)

ww = max([sum(C[i]) for i in range(H)])
hh = max([sum([C[j][i] for j in range(H)]) for i in range(W)])

dp = [[[0 for _ in range(hh + ww + 1)] for _ in range(W)] for _ in range(H)]
#print(dp)

dp[0][0][C[0][0]] = 1
for i in range(H):
  for j in range(W):
    for k in range(hh + ww + 1):
      if dp[i-1][j][k]:
        dp[i][j][k + C[i][j]] = 1
        dp[i][j][abs(k - C[i][j])] = 1
      if dp[i][j-1][k]:
        dp[i][j][k + C[i][j]] = 1
        dp[i][j][abs(k - C[i][j])] = 1

for i in range(hh + ww + 1):
  if dp[H-1][W-1][i]:
    print(i)
    exit()
Problem p02882 (python)

Fixed submission:
import math
a,b,x=map(int,input().split())
 
if a*b//2*a>=x:
  print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
  if a*b*b==x:
    print(0)
  else:
    print(90-math.degrees(math.atan(a/(2*b-2*x/a/a))))

Buggy submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())

if a*a*b%2==0:
  if a*a*b//2==x:
    print(0)
    exit()

if a*a*b/2>x:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
  print(90-math.degrees(math.atan(a/(2*b-2*x/a/a))))

Buggy submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())

if a*a*b/2>=x:
  if a*a*b/2==x:
    print(0)
  else:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
  print(90-math.degrees(math.atan(a/(2*b-2*x/a/a))))

Buggy submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())

if a*b//2*a>=x:
  print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
  print(90-math.degrees(math.atan(a/(2*b-2*x/a/a))))
Problem p02903 (python)

Fixed submission:
H,W,A,B=map(int,input().split())
#print(H,W,A,B)

h=[A*H+i*(W-2*A) for i in range(H)]
w=[B*W+i*(H-2*B) for i in range(W)]
#print(h)
#print(w)


for i,hh in enumerate(h):
  if hh in w:
    #print(i,w.index(hh))

    aa=[]
    for a in range(H-i):
      aa.append(W-A)
    for a in range(i):
      aa.append(A)
    #print("aa",aa)    

    bb=[]
    for b in range(W-w.index(hh)):
      bb.append(H-B)
    for b in range(w.index(hh)):
      bb.append(B)
    #print("bb",bb)    
    
    for a in range(H):
      pp=""
      for b in range(W):
        #print(a,b)
        if aa[a]>0 and bb[b]>0:
          pp+="1"
          aa[a]-=1
          bb[b]-=1
        else:
          pp+="0"
      print(pp)
    exit()

print("No")

Buggy submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
#print(H,W,A,B)

if H==1:
  print("1"*A+"0"*(W-A))
  exit()

if W==1:
  for i in range(H):
    if i<B:
      print("1")
    else:
      print("0")
  exit()
  
if A*H==B*W:
  X="1"*A+"0"*(W-A)
  for i in range(0,H*A,A):
    print(X[i%W:]+X[:i%W])
  exit()

print("No")
Problem p02921 (python)

Fixed submission:
S,T=input(),input()
res=0
if(S[0]==T[0]): res+=1
if(S[1]==T[1]): res+=1
if(S[2]==T[2]): res+=1
print(res)

Buggy submission (verdict: Runtime Error):
S,T=input(),input()
print((S==T).sum())
Problem p02937 (python)

Fixed submission:
import bisect

s,t=input(),input()
ls=len(s)
lt=len(t)
A=[[] for i in range(26+1)]
L=[0 for i in range(26+1)]

for i in range(ls):
  A[ord(s[i])-96].append(i+1)
  L[ord(s[i])-96]+=1
#print(A)

tmp=0
ans=0
for i in range(lt):
  ii=ord(t[i])-96

  if L[ii]==0:
    print(-1)
    exit()
  else:
    iii=bisect.bisect(A[ii],tmp)
    #print(t[i],A[ii],tmp,iii,ans)
    if iii==L[ii]:
      ans+=ls-tmp+A[ii][0]
      tmp=A[ii][0]
    else:
      ans+=A[ii][iii]-tmp
      tmp=A[ii][iii]
print(ans)

Buggy submission (verdict: Runtime Error):
s=input() #数値入力 「N」だけの入力のとき
t=input()  #数値入力 「N」だけの入力のとき
sa=list(s)
ta=list(t)
ans2
x=0
y=0
ans= [[] for i in range(26)]
for i in range(len(s)):
    ans[ord(sa[i])-96-1].append(i)
print(ans)
for i in range(len(t)):
    if len(ans[ord(ta[i])-97])==0:
        ans2=-1
        break;
    else:
        x_old=x
        for j in ans[ord(ta[i])-97]:
            if j>x:
                x=j
        if x_old==x:
            x=0
            y+=1
            for j in ans[ord(ta[i])-97]:
                if j>x:
                    x=j
print(y*len(s)+x+1)
Problem p02952 (python)

Fixed submission:
n=int(input())  #数値入力 「N」だけの入力のとき
#n=11
l=len(str(n))
if l ==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(9+n-99)
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+n-9999)
elif l==6:
    print(9+900+90000)

Buggy submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき
#n=11
#l=len(str(n))
if l ==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(9+n-99)
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+n-9999)
elif l==6:
    print(9+900+90000)
Problem p02958 (python)

Fixed submission:
n=int(input())  #数値入力 「N」だけの入力のとき
#n= 5  #数値入力 「N」だけの入力のとき
c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#c=[5, 2, 3, 4, 1]
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if c[i]-d[i]:
        f+=1
#print(f)
if f == 0 or f == 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき
c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if d[i]-d[i]:
        f+=1
if f == 0 or f == 2:
    print("YES")
else:
    print("NO)
Problem p02963 (python)

Fixed submission:
S=int(input())

x1,y1=0,0
x2,y2=10**9,1

y3=-(-S//10**9)
x3=y3*10**9-S

print(x1,y1,x2,y2,x3,y3)

Buggy submission (verdict: Runtime Error):
S=int(input())
x1,y1=0,0
x2,y2=10**9,1

if S//10**9==0:
  y3=0
  x3=S
else:
  y3=-(-S/10**9//1)
  x3=10**9*x3-S
print(x1,y1,x2,y2,x3,y3)
Problem p02981 (python)

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

Buggy submission (verdict: Runtime Error):
A,P = map(int,input().split())
print((A*3+P)//2)

Buggy submission (verdict: Runtime Error):
A,P = map(int,input().split())
print((A*3+P)//2)

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

print(min(N*A,B))

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

print(max(N*A,B))
Problem p02991 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline

from collections import deque

N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())
INF = 10 ** 15

if M == 0:
  print(-1)
  exit()

graph = [[] for _ in range(3 * M + 1)]
for u, v in UV:
  graph[u].append(v + M)
  graph[u + M].append(v + 2 * M)
  graph[u + 2 * M].append(v)

queue = deque([S])
dist = [INF] * (3 * M + 1)
dist[S] = 0

while queue:
  q = queue.popleft()
  for g in graph[q]:
    if dist[g] > dist[q] + 1:
      dist[g] = dist[q] + 1
      queue.append(g)
print(dist[T] // 3 if dist[T] != INF else -1)

Buggy submission (verdict: Runtime Error):
print("reference: yaketate08")

from collections import deque

N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

graph = [[] for i in range(N + 1)]
for U, V in UV:
    graph[U].append(V)

INF = 10 ** 9

U = [[INF for _ in range(N)] for i in range(3)]
U[0][S] = 0 # S != T なのでこの表記はOK

#そうか、余りの数で最小のものを都度探す。
que = deque([(S, 0)])
while que:
    v, t = que.popleft()
    u = (t + 1) % 3
    d = U[t][v]
    if t == 2:
        d += 1
    Uu = U[u]
    for w in G[v]:
        if Uu[w] != INF:
            continue
        que.append((w, u))
        Uu[w] = d
print(U[0][T] if U[0][T] < INF else -1)
Problem p02993 (python)

Fixed submission:
S = list(input())
if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3]:
    print("Good")
else:
    print("Bad")

Buggy submission (verdict: Runtime Error):
def z_algorithm(s):
  n = len(s)
  z = [None] * n
  z[0] = n
  
  i = 1
  j = 0
  while i < n:
    while i + j < n and s[j] == s[i + j]:
      j += 1
    z[i] = j
    if j == 0:
      i += 1
      continue
    k = 1
    while i + k < n and z[k] + k < j:
      z[i + k] = z[k]
      k += 1
    i += k
    j -= k
  return z

S = input()
T = input()
z = z_algorithm(T + "$" + S)

length = len(T)
for i in range(len(z)):
  if z[i] == length:
    index = i - length - 1
    print(index)

Buggy submission (verdict: Runtime Error):
S = list(input)
if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3]:
    print("Bad")
else:
    print("Good")
Problem p02995 (python)

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

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

CD=int(C*D/gcd(C,D))
Ac=A if A%C==0 else A+(C-A%C)
Ad=A if A%D==0 else A+(D-A%D)
Acd=A if A%CD==0 else A+(CD-A%CD)

Rc=(B-Ac)//C+1 if Ac>=A and Ac<=B else 0
Rd=(B-Ad)//D+1 if Ad>=A and Ad<=B else 0
Rcd=(B-Acd)//CD+1 if Acd>=A and Acd<=B else 0

print(B-A+1-(Rc+Rd-Rcd))

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D=map(int,input().split())
CD = C*D/math.gcd(C,D)

def S(A,B,X):
    A = A if A%X==0 else A+(X-A%X)
    if B>A:
        return int((B-A)//X+1)
    else:
        return 0

print(B-A+1-(S(A,B,C)+S(A,B,D)-S(A,B,CD)))
Problem p03000 (python)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))
#print(L)

D=0
for i in range(N):
  D+=L[i]
  if D>X:
    print(i+1)
    break
  if i==N-1:
    print(i+2)
    break

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

D=0
for i in range(N+1):
  D+=L[i]
  if D>X:
    break
    
print(i+1)
Problem p03006 (python)

Fixed submission:
import collections

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort()

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

pq = []
for i in range(N):
  xi, yi = xy[i][0], xy[i][1]
  for j in range(i + 1, N):
    xj, yj = xy[j][0], xy[j][1]
    p, q = xj - xi, yj - yi
    pq.append((p, q))
#print(pq)

c = list(collections.Counter(pq).values())
c.sort()
print(N - c[-1])

Buggy submission (verdict: Runtime Error):
import collections

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

pq = []
for i in range(N):
  xi, yi = xy[i][0], xy[i][1]
  for j in range(i + 1, N):
    xj, yj = xy[j][0], xy[j][1]
    p, q = xj - xi, yj - yi
    pq.append((p, q))
#print(pq)

c = list(collections.Counter(pq).values())
c.sort()
print(N - c[-1])
Problem p03032 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K = map(int, readline().split())
V = list(map(int, readline().split()))

answer = 0

for i in range(min(N, K)+1):
  for j in range(i+1):
    U = V[:j]+V[N-(i-j):]
    U.sort()
    rid = K - i
    for k in range(len(U)):
      if rid == 0:
        break
      if U[k] < 0:
        rid -= 1
        U[k] = 0
      else:
        break
    answer = max(sum(U), answer)   
print(answer)

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

first_sum = sum(V)

answer = 0
for i in range(min(N + 1, K + 1)):
  for j in range(i + 1):
    left = j
    right = i - j
    
    q = []
    for k in range(left):
      q.append(V[k])
    for k in range(N - right, N):
      q.append(V[k])
    q.sort()
    
    tmp = sum(q)
    for k in range(min(K - i, len(q))):
      if q[k] < 0:
        tmp -= q[k]
      else:
        break
    answer = max(answer, tmp)
    
print(answer)N, K = map(int, input().split())
V = list(map(int, input().split()))

first_sum = sum(V)

answer = 0
for i in range(min(N + 1, K + 1)):
  for j in range(i + 1):
    left = j
    right = i - j
    
    q = []
    for k in range(left):
      q.append(V[k])
    for k in range(N - right, N):
      q.append(V[k])
    q.sort()
    
    tmp = sum(q)
    for k in range(min(K - i, len(q))):
      if q[k] < 0:
        tmp -= q[k]
      else:
        break
    answer = max(answer, tmp)
    
print(answer)
Problem p03035 (python)

Fixed submission:
A,B = map(int,input().split())
if A<=5:
    print(0)
elif A<=12:
    print(int(B/2))
else:
    print(B)

Buggy submission (verdict: Runtime Error):
A,B map(int,input().split())
if A<=5:
    print(0)
elif A<=12:
    print(B/2)
else:
    print(B)