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

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

A = list(map(int,input().split()))
MAX = max(max(A),K)
l = len(str(bin(MAX)))-2

AB = []
for i in range(N):
  s = str(bin(A[i]))
  temp = s[2:]
  lendif = l - len(temp)
  while lendif > 0:
    temp = "0"+temp
    lendif -= 1
  AB.append(temp)
#print(AB,l)

ans = 0
now = 0 #Kを超えていないかチェックする用。
for i in range(l): #桁数で回す。l-i桁から順にみていく。
  #cは0の数。dは1の数。
  c = 0; d = 0
  for j in range(N):
    if AB[j][i] == "0":
      c += 1
    else:
      d += 1
  if c > d: #0の方が多いので1にしたい。l-i桁目が1の時はKを超えてないか確認。
    if pow(2,l-1-i)+now > K:
      m = d
    else:
      now += pow(2,l-1-i)
      m = c
  else:
    m = d
  #print(m, now, pow(2,l-1-i))
  ans += pow(2,l-1-i)*m
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
UP = max(A)
UL = UP.bit_length()
KL = K.bit_length()
MAX = max(UL,KL)
INF = float("inf")
#dp[i][j]: 上からi桁目までを決めて、N未満で確定ならj=1、Nと一致しているならばj=0
dp = [[-INF] * 2 for _ in range(MAX+1)] #-INFにしておかないとないケースから来てしまう。
dp[0][0]=0
ZF = True
L = [[0]*2 for _ in range(MAX)]
for i in range(N):
  for j in range(MAX):
    if A[i]>>j&1 == 1:
      L[MAX-1-j][1] += 1
    else:
      L[MAX-1-j][0] += 1

#print(MAX,KL)
#print(L)
for i in range(MAX):
  fac = pow(2,(MAX-1-i))
  if fac > K: #ここのビットは必ず0．つまり1の個数がかけられる。
    dp[i+1][0] = dp[i][0] + fac*L[i][1]
  else:
    if K>>(KL-1-i)&1 == 1:
      kbit = 1
    else:
      kbit = 0
    #print(kbit,i)
    if kbit == 1: #どちらでも良い
      dp[i+1][1] = max(dp[i][1] + fac*max(L[i]), dp[i][0] + fac*L[i][0]) #未満
      dp[i+1][0] = dp[i][0] + fac*L[i][0] #一致, kbitが1なので0の個数
    else: #完全一致なら0のみ、それ以外ならどちらも
      dp[i+1][1] = max(dp[i][1] + fac*max(L[i]), dp[i][0] + fac*L[i][1]) #未満
      dp[i+1][0] = dp[i][0] + fac*L[i][1] #一致 kbitが0なので1の個数      
#print(dp)
ans = max(dp[MAX])
print(ans)
Problem p03142 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N,M = map(int,input().split())
ALL = [i for i in range(N)]
ALL = set(ALL)
Graph = [[] for _ in range(N)]
gyaku = [set([]) for _ in range(N)]
for i in range(N-1+M):
  a,b = map(int,input().split())
  a-=1;b-=1
  Graph[a].append(b)
  gyaku[b].add(a)
  ALL.discard(b)
#print(Graph,gyaku)
ALL = list(ALL);root = ALL[0]

used = set([])
TS = []
def dfs(v):
  if v in used:
    return
  used.add(v)
  for w in Graph[v]:
    if w in used:
      continue
    dfs(w)
    TS.append(w)
    
dfs(root)
TS.append(root)
TS.reverse()
#print(TS)
ans = [0 for _ in range(N)]
for i in range(N):
  now = TS[i]
  for nxt in Graph[now]:
    ans[nxt] = now+1
    
for x in ans:
  print(x)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ALL = [i for i in range(N)]
ALL = set(ALL)
Graph = [[] for _ in range(N)]
gyaku = [set([]) for _ in range(N)]
for i in range(N-1+M):
  a,b = map(int,input().split())
  a-=1;b-=1
  Graph[a].append(b)
  gyaku[b].add(a)
  ALL.discard(b)
#print(Graph,gyaku)
ALL = list(ALL);root = ALL[0]

used = set([])
TS = []
def dfs(v):
  if v in used:
    return
  used.add(v)
  for w in Graph[v]:
    if w in used:
      continue
    dfs(w)
    TS.append(w)
    
dfs(root)
TS.append(root)
#TS.reverse()
#print(TS)
ans = [0 for _ in range(N)]
for i in range(N):
  now = TS[i]
  for j in range(i+1,N):
    #print(now,TS[j],gyaku[now])
    if TS[j] in gyaku[now]:
      ans[now] = TS[j]+1 #1index
      break
for x in ans:
  print(x)
Problem p03148 (python)

Fixed submission:
import heapq
N,K = map(int,input().split())

L = [[] for _ in range(N)]
All = []
s = set([])
for i in range(N):
  t,d = map(int,input().split())
  t-=1 #0スタートに
  heapq.heappush(L[t], -d) #最大から取り出したいので負にする。
  heapq.heappush(All,[-d,t]) #すべてから大きい順に取り出せるように 
  s.add(t)

#print(L,s)
point = 0
ns = 0 #現在の種類
later = []
now = []
syurui = set([])
while len(now) < K and All:
  temp = heapq.heappop(All)
  if temp[1] not in syurui:
    ns += 1
    point -= temp[0]
    syurui.add(temp[1])
    heapq.heappush(now, -1*temp[0])
  else:
    later.append(temp)
for i in later:
  heapq.heappush(All,i)

point += ns*ns
while len(now) < K:
  temp = heapq.heappop(All)
  point -= temp[0]
  heapq.heappush(now, -1*temp[0])

#print(ns,point)
#print(now,All,All[0][0])
while All and now[0] < -1*All[0][0]:
  temp = heapq.heappop(All)
  dele = heapq.heappop(now)
  #print(temp,dele)
  upoint = point - temp[0] - dele - ns*ns + (ns-1)**2
  #print(upoint,point)
  if upoint >= point:
    point = upoint
    ns -= 1
  else:
    break
    
print(point)
#print(All)
#print(now)

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

L = [[] for _ in range(N)]
All = []
s = set([])
for i in range(N):
  t,d = map(int,input().split())
  t-=1 #0スタートに
  heapq.heappush(L[t], -d) #最大から取り出したいので負にする。
  heapq.heappush(All,[-d,t]) #すべてから大きい順に取り出せるように 
  s.add(t)

#print(L,s)
point = 0
ns = 0 #現在の種類
later = []
now = []
syurui = set([])
while len(now) < K and All:
  temp = heapq.heappop(All)
  if temp[1] not in syurui:
    ns += 1
    point -= temp[0]
    syurui.add(temp[1])
    heapq.heappush(now, -1*temp[0])
  else:
    later.append(temp)
for i in later:
  heapq.heappush(All,i)

point += ns*ns
while len(now) < K:
  temp = heapq.heappop(All)
  point -= temp[0]
  heapq.heappush(now, -1*temp[0])

#print(ns,point)
#print(now,All)
while now[0] < -1*All[0][0]:
  temp = heapq.heappop(All)
  dele = heapq.heappop(now)
  #print(temp,dele)
  upoint = point - temp[0] - dele - ns*ns + (ns-1)**2
  #print(upoint,point)
  if upoint >= point:
    point = upoint
    ns -= 1
  else:
    break
    
print(point)
#print(All)
#print(now)
Problem p03230 (python)

Fixed submission:
N = int(input())
MAX = 450
A = [[1],[1]] #size = 2
#A = [[1,2],[2,3],[3.1]]
size = 0
for i in range(1,MAX):
  if i*(i+1)//2 == N:
    size = i+1
    break
if size == 0:
  print("No")
  exit()
now = 2
while now < size:
  start = now*(now-1)//2+1
  last = [start+i for i in range(now)]
  for j in range(len(A)):
    A[j].append(last[j])
  A.append(last)
  now += 1
print("Yes")
print(len(A))
#ini = [len(A)-1]
for x in A:
  x.insert(0,len(A)-1)
  print(*x)

Buggy submission (verdict: Runtime Error):
N = int(input())
num = (N-2)**(0.5)
if N == 3:
  print("Yes");print(3)
  A = [2, 1, 2]; print(*A)
  A = [2, 2, 3]; print(*A)
  A = [2, 3, 1]; print(*A); exit()
if num%1 != 0:
  print("No");exit()
num = int(num)
ans = []
for i in range(num):
  temp = [1] + [2+j+num*i for j in range(num)]
  ans.append(temp)
for i in range(num):
  temp = [2+i+num*j for j in range(num)] + [N]
  ans.append(temp)
print("Yes")
print(num*2)
for x in ans:
  ret = [num+1] + x
  print(*ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
num = (N-2)**(0.5)
if N == 3:
  print("Yes")
  A = [2, 1, 2]; print(*A)
  A = [2, 2, 3]; print(*A)
  A = [2, 3, 1]; print(*A); exit()
if num%1 != 0:
  print("No");exit()
num = int(num)
ans = []
for i in range(num):
  temp = [1] + [2+j+num*i for j in range(num)]
  ans.append(temp)
for i in range(num):
  temp = [2+i+num*j for j in range(num)] + [N]
  ans.append(temp)
print("Yes")
for x in ans:
  ret = [num+1] + x
  print(*ret)
Problem p03241 (python)

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

s = M//N
for i in reversed(range(1,s+1)):
  if M%i == 0:
    ans = i
    break
print(ans)

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

s = M//N
for i in range(1,s):
  if M%i == 0:
    ans = i
print(ans)
Problem p03290 (python)

Fixed submission:
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

for bit in range(1 << d): #d個左にシフトする。d=2なら100となって十進法なら4。
    count = 0
    sum = 0
    nokori = [i+1 for i in range(d)]

    for i in range(d): #与えられbitにおいてすべて足し算する。
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
            nokori.remove(i + 1)

    # G 点に満たなければ nokori のうち一番大きいものを解く
    if sum < g:
        use = max(nokori)
        n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
        count += n
        sum += n * use * 100

    if sum >= g:
        ans = min(ans, count)

print(ans)

Buggy submission (verdict: Runtime Error):
D,G = map(int,input().split())

P = []
C = []
for i in range(D):
  tempP, tempc = map(int, input().split())
  P.append(tempP)
  C.append(tempC)

print(P,C)
Problem p03323 (python)

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

if N<=8 and M<= 8:
  print("Yay!")
else:
  print(":(")

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

if N<=8 and M<= 8:
  print("Yay!")
else:
  print(":(")
Problem p03393 (python)

Fixed submission:
S = str(input())
N = len(S)
L = list(S)
L = set(L)
if N != 26: #含まないものがある
  for i in range(26):
    temp = chr(i+97)
    if temp not in L:
      ans = S+temp
      print(ans)
      exit()
M = []
All = [chr(97+i) for i in range(26)]
#print(All)
for i in range(25):
  now = 25-i
  M.append(S[now])
  if S[now] > S[now-1]:
    M.sort()
    for x in M:
      if x > S[now-1]:
        temp = x
        ans = S[:now-1]+temp
        print(ans)
        exit()
  
print(-1)

Buggy submission (verdict: Runtime Error):
S = str(input())
N = len(S)
L = list(S)
L = set(L)
if N != 26: #含まないものがある
  for i in range(26):
    temp = chr(i+97)
    if temp not in L:
      ans = S+temp
      print(ans)
      exit()
M = []
for i in range(25):
  now = 25-i
  if S[now] > S[now-1]:
    ans = S[:now-1]+min(M)
    print(ans)
    exit()
  M.append(S[now])
print(-1)
Problem p03421 (python)

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

if A+B > N+1:
  print("-1")
  exit()
if A == 1:
  if B== N:
    ans = [i+1 for i in reversed(range(N))]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if B == 1:
  if A== N:
    ans = [i+1 for i in range(N)]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if A >= B:
  Flag = True
else:
  Flag = False
  A,B = B,A
#print((N+A-1)//A, B)
if A*B<N:
  print("-1")
  exit()
else:
  L = [1 for _ in range(B)]
  nokori = N-B
  for i in range(B):
    if A-L[i] >0:
      temp = min(A-L[i],nokori)
      L[i] += temp
      nokori -= temp
    if nokori == 0:
      break
  now = 0
  P = [[] for _ in range(B)]
  for i,num in enumerate(L):
    for j in range(num):
      now += 1
      P[-i-1].append(now)
  #print(P)
  ans = P
  output = []
  for i in range(len(ans)):
    for j in ans[i]:
      output.append(j)
  if Flag:
    print(*output)
  else:
    output = output[::-1]
    print(*output)

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

if A+B > N+1:
  print("-1")
  exit()
if A == 1:
  if B== N:
    ans = [i+1 for i in reversed(range(N))]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if B == 1:
  if A== N:
    ans = [i+1 for i in range(N)]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if A >= B:
  Flag = True
else:
  Flag = False
  A,B = B,A
if (N+A-1)//A > B:
  print("-1")
  exit()
else:
  L = [[] for _ in range(B)]
  for i in range(B):
    temp = ""
    for j in range(A):
      if j+1+i*A <= N:
        temp += str(j+1+i*A)
        L[-i-1] = "".join(temp)
  ans = "".join(L)
  if Flag:
    s = " ".join([n for n in ans])
    print(s)
  else:
    t = reversed(list(ans))
    ans = " ".join(t)
    print(ans)
  exit()
Problem p03476 (python)

Fixed submission:
N = int(input())
MAX=110000
S = [_+2 for _ in range(MAX)]
old = S
i = 0
while True:
  new = set([])
  t = old[i]
  for j in range(len(old)):
    if old[j] == t or old[j]%t != 0:
      new.add(old[j])
  if len(old) == len(new):
    break
  old = list(new)
  old.sort()
  i += 1


#print(old)
A = [0 for _ in range(MAX)]  
for i in range(MAX):
  if i%2 == 0:
    continue
  if i in new and (i+1)//2 in new:
    A[i] = 1
SUM = [0 for _ in range(MAX)] 
for i in range(1,MAX):
  SUM[i] += A[i]+SUM[i-1]
#print(SUM)

for i in range(N):
  l,r = map(int,input().split())
  ans = SUM[r]-SUM[l-1]
  print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
MAX=11000
S = [_+2 for _ in range(MAX)]
old = S
i = 0
while True:
  new = set([])
  t = old[i]
  for j in range(len(old)):
    if old[j] == t or old[j]%t != 0:
      new.add(old[j])
  if len(old) == len(new):
    break
  old = list(new)
  old.sort()
  i += 1


#print(old)
A = [0 for _ in range(MAX)]  
for i in range(MAX):
  if i%2 == 0:
    continue
  if i in new and (i+1)//2 in new:
    A[i] = 1
SUM = [0 for _ in range(MAX)] 
for i in range(1,MAX):
  SUM[i] += A[i]+SUM[i-1]
#print(SUM)

for i in range(N):
  l,r = map(int,input().split())
  ans = SUM[r]-SUM[l-1]
  print(ans)
Problem p03488 (python)

Fixed submission:
S = str(input())
N = len(S)
x,y = map(int,input().split())
X = []; Y =[]
Flag = True #Trueならx軸、Falseならy軸
seq = 0
for i in range(N):
  if S[i] == "T":
    if Flag:
      X.append(seq)
    if not Flag:
      Y.append(seq)
    Flag = not Flag
    seq = 0
  else:
    seq += 1
    if i == N-1:
      if Flag:
        X.append(seq)
      if not Flag:
        Y.append(seq)
#print(X,Y)
num = 8100 #真ん中
MAX = num*2+1
#X方向i回目でjにいる
dpx = [0 for _ in range(MAX)]
dpx[num] = 1
dpy = [0 for _ in range(MAX)]
dpy[num] = 1
for i in range(len(X)):
  px = [0 for _ in range(MAX)]
  px,dpx = dpx,px
  step = X[i]
  for j in range(MAX):
    if j -step >= 0:
      dpx[j] = max(dpx[j],px[j-step])
    if j + step < MAX and i != 0: #一番最初は左に戻れない
      dpx[j] = max(dpx[j],px[j+step])
for i in range(len(Y)):
  py = [0 for _ in range(MAX)]
  py,dpy = dpy,py
  step = Y[i]
  for j in range(MAX):
    if j -step >= 0:
      dpy[j] = max(dpy[j],py[j-step])
    if j + step < MAX:
      dpy[j] = max(dpy[j],py[j+step])
x += num;y+= num
#print(dpx)
#print(dpy)
if dpx[x] == 1 and dpy[y] == 1:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = str(input()); n = len(s)
gx,gy = map(int,input().split())
Yoko = []; Tate = []
Flag = 0; cnt = 0
Max_x = 0; Max_y = 0
for i in range(n):
  if s[i] == "F":
    cnt += 1
    if i == n-1: #最後なら登録
      if Flag == 0:
        Max_x += cnt
        Yoko.append(cnt)
      else:
        Max_y += cnt
        Tate.append(cnt)      
  else: #T
    if Flag == 0:
      Max_x += cnt
      Yoko.append(cnt)
    else:
      Max_y = cnt
      Tate.append(cnt)
    cnt = 0
    Flag = Flag^1
#print(Yoko,Tate)
MAX_dpx = Max_x*2+1
dp = [0 for _ in range(MAX_dpx)]
dp[Max_x] = 1

for i,x in enumerate(Yoko):
  p = [0 for _ in range(MAX_dpx)]
  p,dp = dp,p
  for j in range(MAX_dpx):
    if i == 0: #i=0の時は右向きだけ
      if 0<=j+x<MAX_dpx:
        dp[j+x] = max(dp[j+x], p[j])
    else:
      if 0<=j+x<MAX_dpx:
        dp[j+x] = max(dp[j+x], p[j])
      if 0<=j-x<MAX_dpx:
        dp[j-x] = max(dp[j-x], p[j])
  #print(dp)
#print(dp)
#print(gx+Max_x,MAX_dpx)
if gx+Max_x >= MAX_dpx or dp[gx+Max_x] == 0:
  print("No");exit()

MAX_dpy = Max_y*2+1
dp = [0 for _ in range(MAX_dpy)]
dp[Max_y] = 1

for i,y in enumerate(Tate):
  p = [0 for _ in range(MAX_dpy)]
  p,dp = dp,p
  for j in range(MAX_dpy):
    if 0<=j+y<MAX_dpy:
       dp[j+y] = max(dp[j+y], p[j])
    if 0<=j-y<MAX_dpy:
      dp[j-y] = max(dp[j-y], p[j])
  #print(dp)
#print(dp)
if gy+Max_y >= MAX_dpy or dp[gy+Max_y] == 0:
  print("No")
else:
  print("Yes")
Problem p03579 (python)

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

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

michi = [[] for i in range(N)]
for i in range(M):
  tempa, tempb = map(int,input().split())
  michi[tempa-1].append(tempb-1)
  michi[tempb-1].append(tempa-1)
#print(michi)
  
colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for to in michi[v]:
    if colors[to] == color:
      return False
    if colors[to] == 0 and not dfs(to,-color):
      return False
  return True

if dfs(0,1):
  a = colors.count(1)
  b = colors.count(-1)
  #print(colors)
  print(a*b-M)
else:
  print(N*(N-1)//2 - M)

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

michi = [[] for i in range(N)]
for i in range(M):
  tempa, tempb = map(int,input().split())
  michi[tempa-1].append(tempb-1)
  michi[tempb-1].append(tempa-1)
#print(michi)
  
colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for to in michi[v]:
    if colors[to] == color:
      return False
    if colors[to] == 0 and not dfs(to,-color):
      return False
  return True

if dfs(0,1):
  a = colors.count(1)
  b = colors.count(-1)
  #print(colors)
  print(a*b-M)
else:
  print(N*(N-1)//2 - M)

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

michi = [[] for i in range(N)]
for i in range(M):
  tempa, tempb = map(int,input().split())
  michi[tempa-1].append(tempb-1)
  michi[tempb-1].append(tempa-1)
print(michi)
  
colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for to in michi[v]:
    if colors[to] == color:
      return False
    if colors[to] == 0 and not dfs(to,-color):
      return False
  return True

if dfs(0,1):
  a = colors.count(1)
  b = colors.count(-1)
  print(colors)
  print(a*b-M)
else:
  print(N*(N-1)//2 - M)
Problem p03611 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
dic = {}
for i in range(N):
  if A[i] not in dic:
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1

ans = []
for i in range(MAX+1):
  mae = 0;ima=0;tsugi = 0
  if i in dic:
    ima = dic[i]
  if i-1 in dic:
    mae = dic[i-1]
  if i+1 in dic:
    tsugi = dic[i+1]
  temp = mae + ima + tsugi
  ans.append(temp)
print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
dic = {}
for i in range(N):
  if A[i] not in dic:
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1

ans = []
for i in range(1,MAX+1):
  mae = 0;ima=0;tsugi = 0
  if i in dic:
    ima = dic[i]
  if i != 1:
    if i-1 in dic:
      mae = dic[i-1]
  if i+1 <= MAX:
    if i+1 in dic:
      tsugi = dic[i+1]
  temp = mae + ima + tsugi
  ans.append(temp)
print(max(ans))
Problem p03837 (python)

Fixed submission:
import heapq
N,M = map(int,input().split())
INF = float("inf")
edge = [[] for _ in range(N)]
#print(load)
#dis = [[] for _ in range(N)]
List = [] #0は未使用、1は使用
for i in range(M):
  a,b,c = map(int,input().split())
  a-=1;b-=1
  edge[a].append([c,b,i])
  edge[b].append([c,a,i])
  List.append([c,a,b,i])

def dijkstra_heap(s):
  d = [INF for _ in range(N)]
  used = [True for _ in range(N)]
  d[s] = 0
  used[s] = False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while len(edgelist):
    minedge = heapq.heappop(edgelist)
    if not used[minedge[1]]: #すでに探索済みの場合にはスキップ
      continue
    v = minedge[1]
    d[v] = minedge[0]
    #L.add(minedge[2]) #この道を使用したと記録
    used[v] = False
    for e in edge[v]:
      if used[e[1]]:
        heapq.heappush(edgelist,[e[0]+d[v],e[1],e[2]])
  return d

L = set([])
for i in range(N):
  dist = dijkstra_heap(i)
  for c, s, g, ID in List: #道のリストの一つ一つの点を見て、それが最短距離で使われているか確認
    if dist[s] + c == dist[g]:
      L.add(ID)
ans = M -len(L)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
INF = float("inf")
load = [[[INF, 0] for _ in range(N)] for _ in range(N)]
#print(load)
#dis = [[] for _ in range(N)]
#ID = [0 for _ in range(M)] #、0は未使用、1は使用
for i in range(M):
  a,b,c = map(int,input().split())
  a-=1;b-=1
  load[a][b] = [c,0]
  load[b][a] = [c,0]
  #dis[a].append([b,i])
  #dis[b].append([a,i])
#for i in range(N):
for i in range(N):
  load[i][i] = [0,0]
#print(load)

for k in range(N):
  for i in range(N):
    for j in range(N):
      if load[i][j][0] > load[i][k][0]+load[j][k][0]:
        load[i][j][1] = 1
#print(load)
ans = 0
for i in range(N):
  for j in range(i+1,M):
    if load[i][j][1] == 1:
      ans += 1
print(ans)
Problem p03855 (python)

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

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

# 道路のUnionFind
uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)
 
# 鉄道のUnionFind
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)
 
# 道路と鉄道の連結の組み合わせ（根のペアのカウント）
c = defaultdict(int)
for i in range(N):
    c[(uf1.find(i), uf2.find(i))] += 1

# 回答を出力
for i in range(N):
    print(c[(uf1.find(i), uf2.find(i))])

Buggy submission (verdict: Runtime Error):
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

      
from collections import defaultdict
 
N, K, L = map(int, input().split())

# 道路のUnionFind
uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)
 
# 鉄道のUnionFind
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)
 
# 道路と鉄道の連結の組み合わせ（根のペアのカウント）
c = {}
for i in range(N):
    if (uf1.find(i), uf2.find(i)) in c:
      c[(uf1.find(i), uf2.find(i))] += 1
    else:
      c[(uf1.find(i), uf2.find(i))] = 1      

# 回答を出力
for i in range(N):
    print(c[(uf1.find(i), uf2.find(i))])
Problem p02573 (python)

Fixed submission:
# cf. 16315733
N, M = list(map(int, input().split()))
# upperは、根なら-その木の長さを、枝ならその木の根の要素のインデックスを指す。
upper = [-1] * N
# xの根を返す
def root(x):
  # xが根なら
  if upper[x] < 0:
    return x
  # xが枝なら
  else:
    # 根のインデックスをさかのぼる
    upper[x] = root(upper[x])
    # 根のインデックスを返す
    return upper[x]

# x,yが同じグループにあるかどうか判定する
def equiv(x, y):
  return root(x) == root(y)

def unite(x, y):
  x, y = root(x), root(y)
  if x != y:
    if upper[y] < upper[x]:
      #xとyの値をスワップ、必ずupper[y] >= upper[x]とするつまりxのほうが高い
      x,y = y,x
    # 要素の数を足す：結合後の要素の数を求める
    upper[x] += upper[y]
    # yの根をxにする（木が高い方を根にする）
    upper[y] = x
  return x == y

for i in range(M):
  a, b = list(map(int, input().split()))
  unite(a-1, b-1)
print(-min(upper))

Buggy submission (verdict: Runtime Error):
import collections
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
  A[i],B[i] = map(int,input().split())
ans = 0
f = [-1]*N
for i in range(M):
  if f[A[i]-1] == -1 and f[B[i]-1] == -1:
    f[A[i]-1] = i
    f[B[i]-1] = i
  elif f[A[i]-1] != -1 and f[B[i]-1] == -1:
    f[B[i]-1] = f[A[i]-1]
  else:
    f[A[i]-1] = f[B[i]-1]
ff = [i for i in f if i != -1]
print(max(collections.Counter(ff).values()))
Problem p02606 (python)

Fixed submission:
L,R,d = map(int,input().split())
ans=0
for i in range(L,R+1):
  if (i%d == 0):
    ans+=1
    
print(ans)

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

def pcrem(n,cnt):
  if (n==0):
    print(cnt)
    return 0
  pc = bin(n).count("1")
  pcrem(n%pc,cnt+1)

for i in range(N):
  f = X^(1<<N-i-1)
  pcrem(f,0)