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

Fixed submission:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    A.sort(reverse=True)
    # print(A)
    # s=sum(A)-min(A)
    A_set=list(set(A))
    A_set.sort(reverse=True)
    set_p=0
    # print(A_set)

    ans=0
    # print(A_set)
    # print([0]*len(A_set))
    arc={k: 0 for k in A_set}
    # print(type(arc))
    # print(A[0])
    arc[A_set[0]]=arc[A_set[0]]+1
    max=A_set[0]    #取得できる最大の心地よさ
    for a in A[1:]:
        # print(arc)
        arc[a]+=2

        ans+=max
        arc[max]-=1
        if arc[max]==0:
            set_p+=1
            max=A_set[set_p]


    print(ans)
    # comfort

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    A.sort(reverse=True)
    # print(A)
    # s=sum(A)-min(A)
    A_set=list(set(A))
    A_set.sort(reverse=True)
    set_p=0
    # print(A_set)

    ans=0
    arc=[0]*(A[0]+1)   #弧の数
    # print(A[0])
    arc[A[0]]+=1
    max=A[0]    #取得できる最大の心地よさ
    for a in A[1:]:
        arc[a]+=2

        ans+=max
        arc[max]-=1
        if arc[max]==0:
            set_p+=1
            max=A_set[set_p]



    print(ans)
    # comfort

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    A.sort(reverse=True)
    # print(A)
    # s=sum(A)-min(A)
    A_set=list(set(A))
    set_p=0

    ans=0
    arc=[0]*(A[0]+1)   #弧の数
    # print(A[0])
    arc[A[0]]+=1
    max=A[0]    #取得できる最大の心地よさ
    for a in A[1:]:
        arc[a]+=2

        ans+=max
        arc[max]-=1
        if arc[max]==0:
            set_p+=1
            max=A_set[set_p]



    print(ans)
    # comfort

if __name__ == '__main__':
    main()
Problem p02705 (python)

Fixed submission:
import math


def main():

    R = int(input())
    print(R*2*math.pi)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()

    N = [0]*int(input())
    A = list(map(int, input().split()))

    for i in A:
        N[i-1]+=1

    for i in N:
        print(i)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():

    N = [0]*int(input())
    A = list(map(int, input().split()))

    for i in A:
        N[i-1]+=1

    for i in N:
        print(i)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()

    N = [0]*int(input())
    A = list(map(int, input().split()))

    for i in A:
        N[i-1]+=1

    for i in N:
        print(i)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
   # file_input()

    N = [0]*int(input())
    A = list(map(int, input().split()))

    for i in A:
        N[i-1]+=1

    for i in N:
        print(i)


if __name__ == '__main__':
    main()
Problem p03319 (python)

Fixed submission:
import sys
import os

def file_input():
    f = open('ARC099/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    N,K=map(int, input().split())
    A_li=list(map(int, input().split()))
    # print(min)

    print(-(-(N-K)//(K-1))+1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os

def file_input():
    f = open('ARC099/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    N,K=map(int, input().split())
    A_li=list(map(int, input().split()))
    # print(min)

    print(-(-N//(K-1))

if __name__ == '__main__':
    main()
Problem p02985 (python)

Fixed submission:
N,K=list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N-1)]
MOD = 10**9+7

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

counted = [0]* (N+1) #counted[i]: ノードiはカウント済み

adjucent_dict = {}
for a,b in AB:
  adjucent_dict.setdefault(a, set()).add(b)
  adjucent_dict.setdefault(b, set()).add(a)
  
from collections import deque

dq = deque([])

for i in range(1,N+1):
  if len(adjucent_dict[i])==1:
    dq.append(i)
    
#print(dq)

ans = K
while dq:
  v = dq.popleft()
  # assert(len(adjucent_dict[v])==1)
  parent = adjucent_dict[v].pop() #かならずlen(~)=1のはず
  adjucent_dict[parent].remove(v)
  #print(v, K - (len(adjucent_dict[parent])+1))
  ans *= max(0, K - (len(adjucent_dict[parent])+1))
  ans %= MOD
  
  if len(adjucent_dict[parent])==1:
    dq.append(parent)
  if len(adjucent_dict[parent])==0:
    break
  
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N-1)]
MOD = 10**9+7

counted = [0]* (N+1) #counted[i]: ノードiはカウント済み

adjucent_dict = {}
for a,b in AB:
  adjucent_dict.setdefault(a, set()).add(b)
  adjucent_dict.setdefault(b, set()).add(a)
  
from collections import deque

dq = deque([])

for i in range(1,N+1):
  if len(adjucent_dict[i])==1:
    dq.append(i)
    
#print(dq)

ans = 1
while dq:
  v = dq.popleft()
  # assert(len(adjucent_dict[v])==1)
  parent = adjucent_dict[v].pop() #かならずlen(~)=1のはず
  adjucent_dict[parent].remove(v)
  #print(v, K - (len(adjucent_dict[parent])+1))
  ans *= K - (len(adjucent_dict[parent])+1)
  ans %= MOD
  
  if len(adjucent_dict[parent])==1:
    dq.append(parent)
  if len(adjucent_dict[parent])==0:
    ans *= K
    ans %= MOD
    break
  
print(ans)
Problem p03006 (python)

Fixed submission:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

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

from itertools import permutations
from collections import Counter
l = [((A[0]-B[0]),(A[1]-B[1])) for A,B in permutations(XY,2)]
c = Counter(l)
print(N - c.most_common()[0][1] )

Buggy submission (verdict: Runtime Error):
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

from itertools import permutations
from collections import Counter
l = [((A[0]-B[0]),(A[1]-B[1])) for A,B in permutations(XY,2)]
c = Counter(l)
print(N - c.most_common()[0][1] )
Problem p03007 (python)

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

Anega = [a for a in A if a<=0]
Aposi = [a for a in A if a>0]

if Anega and Aposi:
  print(sum(Aposi)-sum(Anega))
  temp = Anega[-1]
  for a in Aposi[:-1]:
    print(*(temp,a))
    temp = temp-a
  print(*(Aposi[-1],temp))
  temp = Aposi[-1]-temp
  for a in Anega[:-1]:
    print(*(temp,a))
    temp = temp-a

elif Aposi:
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))

else:
  print(A[-1] - sum(A[:-1]))
  temp = A[-1]
  for a in A[:-1]:
    print(*(temp,a))
    temp = temp-a

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

'''
Anega = [a for a in A if a<0]
Azero = [a for a in A if a==0]
Aposi = [a for a in A if a>0]

if len(A) == len(Anega):
  print(-sum(A[:-1]) + A[-1])
  a = A[-1]
  for i in range(2,N+1):
    print(*(a, A[-i]))
    a = a - A[-i]
    
if len(A) == len(Aposi):
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))
  
if Azero:
  print(sum(Aposi)-sum(Anega))
  for _ in range(len(Azero)-1):
    print(*(0,0))
  a = 0
  for i in range(0,len(Aposi)-1):
    print(*(a, Aposi[i]))
    a = a-Aposi[i]
  print(*(Aposi[-1],a))
  a = Aposi[-1] -a
  
  for b in Anega:
    print(*(a,b))
    a = a-b
'''
        

      
      
Anega = [a for a in A if a<=0]
Aposi = [a for a in A if a>0]

if Anega:
  print(sum(Aposi)-sum(Anega))
  temp = Anega[-1]
  for a in Aposi[:-1]:
    print(*(temp,a))
    temp = temp-a
  print(*(Aposi[-1],temp))
  temp = Aposi[-1]-temp
  for a in Anega[:-1]:
    print(*(temp,a))
    temp = temp-a
    
  
else:
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))
Problem p03026 (python)

Fixed submission:
N=int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)] #N-1
C = list(map(int, input().split())) #N
C.sort()

M = sum(C[:-1])

adjacent_dict={}
for a,b in AB:
  adjacent_dict.setdefault(a, set()).add(b)
  adjacent_dict.setdefault(b, set()).add(a)
  

leafs = []
adjacents = [0] * (N+1) # a[i]: 頂点i
for k, v in adjacent_dict.items():
  adjacents[k] = len(v)
  if len(v)==1:
    leafs.append(k)

nodes = leafs.copy() #小さい値を入れたい順のノード
visited = [0] * (N+1) # visited[i]: 頂点i
for n in nodes:
  visited[n] = 1
  
#while leafs:
#  next_leafs = set()
#  for l in leafs:
#    for u in adjacent_dict[l]:
#      acjacents[u] -= 1
#      next_leafs.add(u)
  
  
while leafs:
  new_stack = []
  for v in leafs:
    for u in adjacent_dict[v]:
      adjacents[u] -= 1
      if visited[u]==0:
        visited[u]=1
        new_stack.append(u)
  leafs = [v for v in new_stack if adjacents[v]==1]
  nodes.extend(leafs)
  if not leafs:
    nodes.extend(new_stack) #最後に隣接0のノードが残ったとき
    break
  for u in [v for v in new_stack if adjacents[v]!=1]:
    visited[u] = 0
    
  
ans = [0]*(N)
for i in range(N):
  ans[nodes[i]-1] = C[i]
  
print(M)
print(*ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)] #N-1
C = list(map(int, input().split())) #N
C.sort()

M = sum(C[:-1])

adjacent_dict={}
for a,b in AB:
  adjacent_dict.setdefault(a, set()).add(b)
  adjacent_dict.setdefault(b, set()).add(a)
  

leafs = []
adjacents = [0] * (N+1) # a[i]: 頂点i
for k, v in adjacent_dict.items():
  adjacents[k] = len(v)
  if len(v)==1:
    leafs.append(k)

nodes = leafs.copy() #小さい値を入れたい順のノード
visited = [0] * (N+1) # visited[i]: 頂点i
for n in nodes:
  visited[n] = 1
  
stack = leafs.copy()
while stack:
  new_stack=[]
  for v in stack:
    for u in adjacent_dict[v]:
      adjacents[u] -= 1
      if visited[u]==0:
        visited[u]=1
        nodes.append(u)
        new_stack.append(u)
  stack = [v for v in new_stack if adjacents[v]==0]
  
ans = [0]*(N)
for i in range(N):
  ans[nodes[i]-1] = C[i]
  
print(M)
print(*ans)
Problem p03040 (python)

Fixed submission:
Q = int(input())
Queries = [list(map(int, input().split())) for _ in range(Q)]

import heapq as hp
L = [-(-(10**9+1))] # 最小ヒープなので負を入れる
R = [10**9+1] # そのまま
hp.heapify(L)
hp.heapify(R)
odd = False
sum_b = 0
sum_l = 0
sum_r = 0

for q in Queries:
  if len(q)==1 and q[0]==2:
    print(*(-L[0], sum_b + abs(sum_l-sum_r)))
    
  else:
    _, a, b = q
    sum_b += b

    l = -hp.heappop(L)
    r = hp.heappop(R)
    
    X = sorted([l, r, a])
    if odd==False:
      sum_l -= l
      sum_r -= r
      hp.heappush(L,-X[0])
      hp.heappush(L,-X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[2]
      odd=True
    elif odd==True:
      sum_r -= r
      hp.heappush(L,-X[0])
      hp.heappush(R,X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[1] + X[2]
      odd=False

Buggy submission (verdict: Runtime Error):
Q = int(input())
Queries = [list(map(int, input().split())) for _ in range(Q)]

import heapq as hp
L = [10**9+1] # 最小ヒープなので負を入れる
R = [10**9+1] # そのまま
hp.heapify(L)
hp.heapify(R)
odd = False
sum_b = 0
sum_l = 0
sum_r = 0

flag = 1

for q in Queries:
  if len(q)==1 and q[0]==2:
    if flag ==0:
      print(*(-L[0], sum_b + abs(sum_l-sum_r)))
    else:
      print(*(-L[0], sum_b)
      flag = 1

  else:
    _, a, b = q
    sum_b += b

    l = -hp.heappop(L)
    r = hp.heappop(R)
    sum_l -= l
    sum_r -= r
    X = sorted([l, r, a])
    if odd==False:
      hp.heappush(L,-X[0])
      hp.heappush(L,-X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]+X[1]
      sum_r += X[2]
      odd=True
    elif odd==True:
      hp.heappush(L,-X[0])
      hp.heappush(R,X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[1] + X[2]
      odd=False
Problem p03063 (python)

Fixed submission:
N = int(input())
S = input()
answers = []

from itertools import accumulate

white_cumsum = list(accumulate([1 if s=='.' else 0 for s in S]))
black_cumsum = list(accumulate([1 if s=='#' else 0 for s in S]))

answers.append(white_cumsum[-1])
answers.append(black_cumsum[-1])

for i in range(N):
  answers.append(black_cumsum[i] + white_cumsum[-1] - white_cumsum[i])
    
answer = min(answers)
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [abs(int(input())) for _ in range(N)]
#A.sort()
s = sum(A)

def mulmod(p,q,mod):
  return ((p%mod)*(q%mod))%mod
def powermod(p,n,mod):
  if n==0: return 1
  if n==1: return p%mod
  else:    return powermod(p,n//2,mod)**2 * (p**(n%2)) %mod
def dividemod(p,q,mod):
  # modは素数
  return mulmod(p, powermod(q,mod-2,mod), mod)

mod = 998244353

dp = [[0]*(s+1) for _ in range(N)]
# dp[n][s] An-1(0-index)まで加えて、Rの和がsになるのが何通りか（残りのG,Bまで含めて）
dp[0][0] = 2
dp[0][A[0]] = 1
temp_sum = A[0]

for i in range(1,N):
  for j in range(A[i]):
    dp[i][j] = (dp[i-1][j]*2) %mod
  for j in range(A[i], temp_sum+1):
    dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) %mod
  for j in range(temp_sum+1, temp_sum+1 + A[i]):
    dp[i][j] = (dp[i-1][j-A[i]]) %mod
  temp_sum += A[i]


def part_sum(a,A):
  p=mod
  #初期化
  N=len(a)
  dp=[[0 for i in range(A+1)] for j in range(N+1)]
  dp[0][0]=1

  #DP
  for i in range(N):
    for j in range(A+1):
      if a[i]<=j: #i+1番目の数字a[i]を足せるかも
        dp[i+1][j]=dp[i][j-a[i]]+ dp[i][j]% p
      else: #入る可能性はない
        dp[i+1][j]=dp[i][j]%p
  return dp[N][A]

ps = part_sum(A, s//2)

if s%2 != 0:
    answer = (powermod(3, N, mod) - 3*sum(dp[N-1][(s+1)//2:]))%mod
else:
    answer = (powermod(3, N, mod) - 3*(sum(dp[N-1][(s+1)//2:]) - ps))%mod



print(answer)
Problem p03064 (python)

Fixed submission:
N = int(input())
A = [abs(int(input())) for _ in range(N)]
#A.sort()
s = sum(A)

def mulmod(p,q,mod):
  return ((p%mod)*(q%mod))%mod
def powermod(p,n,mod):
  if n==0: return 1
  if n==1: return p%mod
  else:    return powermod(p,n//2,mod)**2 * (p**(n%2)) %mod
def dividemod(p,q,mod):
  # modは素数
  return mulmod(p, powermod(q,mod-2,mod), mod)

mod = 998244353

dp = [[0]*(s+1) for _ in range(N)]
# dp[n][s] An-1(0-index)まで加えて、Rの和がsになるのが何通りか（残りのG,Bまで含めて）
dp[0][0] = 2
dp[0][A[0]] = 1
temp_sum = A[0]

for i in range(1,N):
  for j in range(A[i]):
    dp[i][j] = (dp[i-1][j]*2) %mod
  for j in range(A[i], temp_sum+1):
    dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) %mod
  for j in range(temp_sum+1, temp_sum+1 + A[i]):
    dp[i][j] = (dp[i-1][j-A[i]]) %mod
  temp_sum += A[i]


def part_sum(a,A):
  p=mod
  #初期化
  N=len(a)
  dp=[[0 for i in range(A+1)] for j in range(N+1)]
  dp[0][0]=1

  #DP
  for i in range(N):
    for j in range(A+1):
      if a[i]<=j: #i+1番目の数字a[i]を足せるかも
        dp[i+1][j]=dp[i][j-a[i]]+ dp[i][j]% p
      else: #入る可能性はない
        dp[i+1][j]=dp[i][j]%p
  return dp[N][A]

ps = part_sum(A, s//2)

if s%2 != 0:
    answer = (powermod(3, N, mod) - 3*sum(dp[N-1][(s+1)//2:]))%mod
else:
    answer = (powermod(3, N, mod) - 3*(sum(dp[N-1][(s+1)//2:]) - ps))%mod



print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [abs(int(input())) for _ in range(N)]
#A.sort()
s = sum(A)

def mulmod(p,q,mod):
  return ((p%mod)*(q%mod))%mod
def powermod(p,n,mod):
  if n==0: return 1
  if n==1: return p%mod
  else:    return powermod(p,n//2,mod)**2 * (p**(n%2)) %mod
def dividemod(p,q,mod):
  # modは素数
  return mulmod(p, powermod(q,mod-2,mod), mod)

mod = 998244353

import numpy as np

dp = [np.zeros(s+1) for _ in range(N)]


# dp[n][s] An-1(0-index)まで加えて、Rの和がsになるのが何通りか（残りのG,Bまで含めて）
dp[0][0] = 2
dp[0][A[0]] = 1
temp_sum = A[0]

for i in range(1,N):
  dp[i] = np.mod((np.roll(dp[i-1], A[i]) + dp[i-1]*2), mod)
  temp_sum += A[i]

def part_sum(a,A):
  p=mod
  #初期化
  N=len(a)
  dp=[[0 for i in range(A+1)] for j in range(N+1)]
  dp[0][0]=1

  #DP
  for i in range(N):
    for j in range(A+1):
      if a[i]<=j: #i+1番目の数字a[i]を足せるかも
        dp[i+1][j]=dp[i][j-a[i]]+ dp[i][j]% p
      else: #入る可能性はない
        dp[i+1][j]=dp[i][j]%p
  return dp[N][A]

ps = part_sum(A, s//2)

if s%2 != 0:
    answer = (powermod(3, N, mod) - 3*sum(dp[N-1][(s+1)//2:]))%mod
else:
    answer = (powermod(3, N, mod) - 3*(sum(dp[N-1][(s+1)//2:]) - ps))%mod

answer = int(answer)

print(answer)
Problem p03076 (python)

Fixed submission:
A = [int(input()) for _ in range(5)]
 
y = min([10] + [x%10 for x in A if x%10])
 
print(sum([10*(x//10 + bool(x%10)) for x in A]) -10 + y)

Buggy submission (verdict: Runtime Error):
A = [int(input()) for _ in range(5)]

y = min([x%10 for x in A if x%10])

print(sum([10*(x//10 + bool(x%10)) for x in A]) -10 + y)
Problem p03088 (python)

Fixed submission:
import re, copy
import itertools
N= int(input())

pat='(AGC|ACG|GAC|AGAC|AGTC|AGCC|AAGC|ATGC|AGGC)'
repattern = re.compile(pat)

memo={}

for s in itertools.product('ATGC', repeat=3):
  if not repattern.search(''.join(s)):
  	memo[''.join(s)] = 1
  
for _ in range(3,N):
  new_memo={}
  for k,v in memo.items():
    for c in 'ATGC':
      if not repattern.search(k+c):
        new_memo[(k+c)[-3:]] = new_memo.get((k+c)[-3:],0)+v
  memo=new_memo

print(sum(memo.values())%(10**9+7))

Buggy submission (verdict: Runtime Error):
import re, copy
import itertools
N= int(input())

pat='(AGC|ACG|GAC|AGAC|AGTC|AGCC|AAGC|ATGC|AGGC)'
repattern = re.compile(pat)

memo={}

for s in itertools.product('ATGC', repeat=3):
  if not repattern.search(''.join(s)):
  	memo[''.join(s)] = 1
  
for _ in range(3,N):
  new_memo={}
  for k,v in memo.items():
    for c in 'ATGC':
      if not repattern.search(k+c):
        new_memo[(k+c)[-3:]] = new_memo.get((k+c)[-3:],0)+v
  memo=new_memo

print(sum(memo.values())%(10**9+7)
Problem p03105 (python)

Fixed submission:
import math


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

print(min(math.floor(B/A), C))

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

roots = [(i,1) for i in range(N+1)] # root, num_islands_in_group

inconveniences = [0]*(M+1)
inconveniences[-1] = N*(N-1)//2 #すべての橋が崩落するとNC2

def find_root(a, roots=roots):
  if roots[a][0] == a:
    return roots[a]
  else:
    roots[a] = find_root(roots[a][0])
  return roots[a]

def reduce_inconvenience_with_unite(a, b, roots=roots):
  root_a, n_a = find_root(a)
  root_b, n_b = find_root(b)
  if root_a == root_b:
    return 0
  else:
    if n_a > n_b:
      roots[root_a] = (root_a, n_a + n_b)
      roots[root_b] = (root_a, n_a + n_b)
    else:
      roots[root_a] = (root_b, n_a + n_b) 
      roots[root_b] = (root_b, n_a + n_b)
    return n_a * n_b

for i, ab in enumerate(AB[:0:-1]): #実は1個めの橋は全く関係ない
  a, b = ab
  inconveniences[M-1-i] = inconveniences[M-i] - reduce_inconvenience_with_unite(a,b)

for inc in inconveniences[1:]:
  print(inc)
Problem p03129 (python)

Fixed submission:
N, K=list(map(int,input().split()))
 
if (N+1)//2 >= K:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
N, K=input().split()

if (N+2)//3 >= K:
  print('YES')
else:
  print('NO')
Problem p03145 (python)

Fixed submission:
X = list(map(int, input().split()))
X.sort()
print(int(0.5*X[0]*X[1]))

Buggy submission (verdict: Runtime Error):
X = list(map(int, input().split()))
X.sort()
print(0.5*(X[0]*X[1])
Problem p03211 (python)

Fixed submission:
s=input()
l=len(s)

mindiff=1000

for i in range(l-2):
  if mindiff > abs(int(s[i:i+3])-753):
    mindiff=abs(int(s[i:i+3])-753)

print(mindiff)

Buggy submission (verdict: Runtime Error):
import math

s=input()
l=len(s)

ans=0
mindiff=1000

for i in range(l-2):
  if mindiff > math.abs(int(s[i:i+3])-753):
    ans=int(s[i:i+3])
    mindiff=math.abs(int(s[i:i+3])-753)

print(ans)
Problem p03282 (python)

Fixed submission:
S=input()
K=int(input())

for i, s in enumerate(S):
  if int(s)==1:
    if i+1 < K:
      continue
    if i+1==K:
      print('1')
      break
  else:
    print(s)
    break

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

if K==1:
  print(N[0])
  
else:
  if N[0]==1:
    print(N[1])
  else:
    print(N[0])
Problem p03353 (python)

Fixed submission:
s=input()
K=int(input())

memo=set()
for i in range(len(s)):
  for j in range(1,min(len(s)-i+1,K+1)):
    memo.add(s[i:i+j])
    
memo=list(memo)
memo.sort()
#print(memo)
print(memo[K-1])

Buggy submission (verdict: Runtime Error):
s=input()
K=int(input())

_set=set()

for i in range(len(s)-1):
  for j in range(i+1, len(s)):
    _set.add(s[i:j])

#print(sorted(list(_set)))
print(sorted(list(_set))[K-1])
Problem p03575 (python)

Fixed submission:
class UnionFind():
  def __init__(self):
    self.roots = {}
    self.nums = {}

  def find_root(self, a):
    if a not in self.roots:
      self.nums[a] = 1
      return a
    else:
      self.roots[a] = self.find_root(self.roots[a])
      return self.roots[a]

  def unite(self, a, b):
    root_a = self.find_root(a)
    root_b = self.find_root(b)
    n_a = self.nums[root_a]
    n_b = self.nums[root_b]
    if root_a == root_b:
      return
    else:
      if n_a > n_b: #多い方に合流させる
        self.roots[root_b] = root_a
        self.nums[root_a] = n_a + n_b
        del self.nums[root_b]
      else:
        self.roots[root_a] = root_b
        self.nums[root_b] = n_a + n_b
        del self.nums[root_a]
      return
  
  def is_union(self, a,b):
    return self.find_root(a) == self.find_root(b)

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

answer = 0
for i in range(M):
  temp = AB[:i] + AB[i+1:]
  ai, bi = AB[i]
  uf = UnionFind()
  for ab in temp:
    a,b = ab
    uf.unite(a,b)
  answer += not uf.is_union(ai, bi)


print(answer)

Buggy submission (verdict: Runtime Error):
class UnionFind():
  def __init__(self):
    self.roots = {}
    self.nums = {}

  def find_root(self, a):
    if a not in self.roots:
      self.nums[a] = 1
      return a
    else:
      self.roots[a] = self.find_root(self.roots[a])
      return self.roots[a]

  def unite(self, a, b):
    root_a = self.find_root(a)
    root_b = self.find_root(b)
    n_a = self.nums[root_a]
    n_b = self.nums[root_b]
    if root_a == root_b:
      return
    else:
      if n_a > n_b: #多い方に合流させる
        self.roots[root_b] = root_a
        self.nums[root_a] = n_a + n_b
        del self.nums[root_b]
      else:
        self.roots[root_a] = root_b
        self.nums[root_b] = n_a + n_b
        del self.nums[root_a]
      return
  
  def is_union(self, a,b):
    return self.find_root(a) == self.find_root(b)

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

answer = 0
for i in range(N):
  temp = AB[:i] + AB[i+1:]
  ai, bi = AB[i]
  uf = UnionFind()
  for ab in temp:
    a,b = ab
    uf.unite(a,b)
  answer += not uf.is_union(ai, bi)


print(answer)
Problem p03583 (python)

Fixed submission:
N=int(input())

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

for h in range(N//4 +1, min(3501, 3*N//4 +1)):
  for n in range((N*h)//(4*h-N), min(3501, (2*N*h)//(4*h-N))):
    x = 4*h*n - N*n - N*h
    y = N*h*n
    if x>0 and not y%x:
      print('{} {} {}'.format(h,n,y//x))
      exit()

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

for h in range(N//4, min(3501, 3*N//4 +1)):
  for n in range((N*h)//(4*h-N), min(3501, (2*N*h)//(4*h-N))):
    x = 4*h*n - N*n - N*h
    y = N*h*n
    if x>0 and not y%x:
      print('{} {} {}'.format(h,n,y//x))
      exit()

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

for h in range(N//4, min(3501, 3*N//4 +1)):
  for n in range((N*h)//(4*h-N), min(3501, (2*N*h)//(4*h-N))):
    x = 4*h*n - N*n - N*h
    y = N*h*n
    if x<=0 or y%x:
      continue
    else:
      print('{} {} {}'.format(h,n,y//x))
      exit()