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

Fixed submission:
t,x = map(int,input().split())
print(t / x)

Buggy submission (verdict: Runtime Error):
# C Streamline
n,m = map(int,input().split())
Xs = list(map(int,input().split()))

if n >= m:
    print('0')
    exit()

Xs.sort()
XsDist = []

for i in range(len(Xs)):
    if not i == 0:
        XsDist.append(Xs[i] - Xs[i-1])

XsDist.sort()
print(sum(XsDist[:n+1]))
Problem p02831 (python)

Fixed submission:
# import math
a, b= map(int,input().split())
def lcm(x, y):
    return (x * y) // gcd(x, y)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 # print(gcd(a,b))

print(lcm(a,b))

Buggy submission (verdict: Runtime Error):
import math
a, b= map(int,input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
print(lcm(a,b))
Problem p02859 (python)

Fixed submission:
r = int(input())
print(r**2)

Buggy submission (verdict: Runtime Error):
r = int(input())
return r**2
Problem p03041 (python)

Fixed submission:
N,K=map(int,input().split())
S=input()
if S[K-1]=="A":
    ans=S[:K-1]+"a"+S[K:]
elif S[K-1]=="B":
    ans=S[:K-1]+"b"+S[K:]
if S[K-1]=="C":
    ans=S[:K-1]+"c"+S[K:]
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
if 1<=int(S[:2])<=12 and 13<=int(S[2:]) or int(S[2:])==0:
    print("MMYY")
elif 1<=int(S[2:])<=12 and 13<=int(S[:2]) or int(S[:2])==0:
    print("YYMM")
elif 1<=int(S[2:])<=12 and 1<=int(S[:2])<=12:
    print("AMBIGUOUS")2
elif 13<=int(S[2:]) or int(S[2:])==0 and 13<=int(S[:2]) or int(S[:])==0:
    print("NA")

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
if S[k-1]=="A":
    S[k-1]="a"
elif S[k-1]=="B":
    S[k-1]="b"
if S[k-1]=="C":
    S[k-1]="c"
print(S)
Problem p03042 (python)

Fixed submission:
S=input()
if 1<=int(S[:2])<=12 and (13<=int(S[2:]) or int(S[2:])==0):
    print("MMYY")
elif 1<=int(S[2:])<=12 and (13<=int(S[:2]) or int(S[:2])==0):
    print("YYMM")
elif 1<=int(S[2:])<=12 and 1<=int(S[:2])<=12:
    print("AMBIGUOUS")
elif (13<=int(S[2:]) or int(S[2:])==0) and (13<=int(S[:2]) or int(S[:])==0):
    print("NA")

Buggy submission (verdict: Runtime Error):
S=input()
if 1<=int(S[:2])<=12 and 13<=int(S[2:]) or int(S[2:])==0:
    print("MMYY")
elif 1<=int(S[2:])<=12 and 13<=int(S[:2]) or int(S[:2])==0:
    print("YYMM")
elif 1<=int(S[2:])<=12 and 1<=int(S[:2])<=12:
    print("AMBIGUOUS")2
elif 13<=int(S[2:]) or int(S[2:])==0 and 13<=int(S[:2]) or int(S[:])==0:
    print("NA")
Problem p03072 (python)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
ans=0
for i in range(len(H)):
    if i==0:
        ans+=1
    elif max(H[0:i])<=H[i]:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
ans=0
for i in range(len(H)):
    if i==1:
        ans+=1
    elif max(H[1:i-1])<=H[i]:
        ans+=1
print(ans)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())

for i in range(1,4):
  if i != A and i != B:
    print(i)

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

for i in range(1,4):
	if i != A and i != B:
      print(i)
Problem p02793 (python)

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

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

def lcm(a, b):
  return a * b // gcd (a, b)

alllcm = 1

for i in range(N):
  alllcm = lcm(alllcm, list[i])

ans = 0

for i in range(N):
  ans += alllcm // list[i]

print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import fractions

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

lcm = list[0]
for i in range(1, N):
    lcm = lcm * list[i] // fractions.gcd(lcm, list[i])



ans = 0

for i in range(N):
  ans += int(lcm / list[i])

print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

lcm = lcm_list(list)

ans = 0

for i in range(N):
  ans += lcm // list[i]

print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

lcm = lcm_list(list)

ans = 0

for i in range(N):
  ans += int(lcm / list[i])

print(ans % (10**9 + 7))
Problem p02897 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print((N / 2) / N)

else:
    print(((N + 1) / 2) / N)

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

if N % 2 == 0:
    print((N / 2) / N)

else:
    print(((N + 1) / 2) / N)
Problem p02916 (python)

Fixed submission:
n = int(input())
a = input().split()
b = input().split()
c = input().split()

manzoku_do = 0
i = 0

manzoku_do = 0
i = 0

manzoku_do += int(b[int(a[i]) - 1])
i += 1

while i < n:
  manzoku_do += int(b[int(a[i]) - 1])
  
  if int(a[i - 1]) -1  == int(a[i])-1 - 1:
    manzoku_do += int(c[int(a[i -1]) -1 ])
  i += 1
    
    
print(manzoku_do)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split()
b = input().split()
c = input().split()

manzoku_do = 0
i = 0

manzoku_do += int(b[int(a[i])])
i += 1

while i < n:
  manzoku_do += int(b[int(a[i])])
  
  if int(a[i - 1]) == int(a[i]) - 1:
    manzoku_do += int(c[int(a[i -1])])
    i += 1
    
print(manzoku_do)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = input().split()
b = input().split()
c = input().split()

manzoku_do = 0
i = 0

manzoku_do += int(b[int(a[i])])
i += 1

while i < n:
  manzoku_do += int(b[int(a[i])])
  
  if a[i - 1] == a[i] - 1:
    manzoku_do += int(c[int(a[i -1])])
    i += 1
    
print(manzoku_do)
Problem p02790 (python)

Fixed submission:
n = [int(i) for i in input().split()]
print(str(min(n)) * max(n))

Buggy submission (verdict: Runtime Error):
n = min[int(i) for in in input().split()]
print(str(n)*int(n))
Problem p02859 (python)

Fixed submission:
r=int(input())
print(r**2)

Buggy submission (verdict: Runtime Error):
import math
def dis(p1,p2):
  return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5
 
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    ans+=dis(p[i],p[j])
print(ans*4/math.factorial(n))
Problem p02880 (python)

Fixed submission:
n = int(input())
list = [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,
       24,25,27,28,30,32,35,36,40,42,45,48,49,54,
       56,63,64,72,81]

if n in list:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
list = [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,
       24,25,27,28,30,32,35,36,40,42,45,48,49,54,
       56,63,64,72,81]

if list in n:
  print('Yes')
else:
  print('No')
Problem p02933 (python)

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

if a >= 3200:
  print(s)
else:
  print('red')

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N-1)]
A.sort()
 
cost=[0]*(N+1)
 
for _ in range(Q):
	a,b=map(int,input().split())
	cost[a]+=b
 
for a in A:
	cost[a[1]] += cost[a[0]]
print(*cost[1:])
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N-1)]
A.sort()

cost=[0]*(N+1)

for _ in range(Q):
	a,b=map(int,input().split())
	cost[a]+=b

for a in A:
	cost[a[1]] += cost[a[0]]
print(*cost[1:])

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

score = [0 for _ in range(N)]
 
# 子頂点番号:親頂点番号のdictを生成する
d = {}
for i in range(1,N):
  a,b = map(int,input().split())
  d[b] = a
      
# スコア加算処理
for i in range(1,Q+1):
  p,x = map(int,input().split())
  score[p-1] = x  
for i in range(1,len(score)):
  addScore = score[d[i+1]-1]
  score[i] += addScore
print(*score)
Problem p03072 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))

ans = 1
if len(h) >= 2:
  if h[0] <= h[1]:
    ans += 1
  for i in range(2,n):
    isCount = True
    if h[0] <= h[i]:
      if h[1] <= h[i]:
      	for j in range(1,i):
          if h[j] > h[i]:
          	isCount = False
      	if isCount:
          ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

ans = 1
if h[0] <= h[1]:
  ans += 1

isCount = True
for i in range(2,n):
  if h[0] <= h[i]:
    if h[1] <= h[i]:
      for j in range(1,i):
        if h[j] > h[i]:
          isCount = False
      if isCount:
        ans += 1
      isCount = True
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

ans = 1
if h[0] <= h[1]:
  ans += 1

isCount = True
for i in range(2,n):
  if h[0] <= h[i]:
    if h[1] <= h[i]:
      for j in range(1,i):
        if h[j] > h[i]:
          isCount = False
      if isCount:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

ans = 1
if h[0] <= h[1]:
  ans += 1

isCount = True
for i in range(2,n):
  if h[0] <= h[i]:
    if h[1] <= h[i]:
      for j in range(1,i):
        if h[j] > h[i]:
          isCount = False
      if isCount:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
 
ans = 1
if h[0] <= h[1]:
  ans += 1
 
for i in range(2,n):
  if h[0] <= h[i]:
    if h[1] <= h[i]:
      if h[i-1] <= h[i]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

ans = 1
if h[0] < h[1]:
  ans += 1

for i in range(2,n):
  if h[0] <= h[i]:
    if h[1] <= h[i]:
      if h[i-1] <= h[i]:
        ans += 1
print(ans)
Problem p02948 (python)

Fixed submission:
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
    
days_limit = M

jobs = AB[:]
from collections import defaultdict
jobs_dict = defaultdict(lambda: [])
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    if hq:
        ans += -1 * heapq.heappop(hq)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
days_limit = M

jobs = AB[:]
jobs_dict = {i: [] for i in range(M+1)}
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    if hq:
        ans += -1 * heapq.heappop(hq)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M  = map(int, input().split())
AB = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    AB[i] = (a, b)
days_limit = M

jobs = AB[:]
jobs_dict = {i: [] for i in range(M+1)}
for d, r in jobs:
    jobs_dict[d].append(r)
#print(jobs_dict)

import heapq
hq = []

ans = 0
for d in range(1, M+1):
    for r in jobs_dict[d]:
        heapq.heappush(hq,-r)
    ans += -1 * heapq.heappop(hq)
print(ans)
Problem p02955 (python)

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

nums = A[:]

sum_n = sum(nums)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

divisors = sorted(list(make_divisors(sum_n)), reverse=True)
#print('DIV', divisors)


for d in divisors:
    mod_nums = list(map(lambda x: x%d, nums[:]))
    mod_nums = sorted(mod_nums)
    #print(mod_nums)
    x = 10**10
    for i in range(0, len(mod_nums)+1):
        if sum(mod_nums[:i]) == sum(list(map(lambda x: d-x, mod_nums[i:]))):
            x = sum(mod_nums[:i])
            break
    #print(d, x)
    if x <= K:
        ans = d
        break
            
print(ans)

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

nums = A[:]

sum_n = sum(nums)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

divisors = sorted(list(make_divisors(sum_n)), reverse=True)
#print('DIV', divisors)


for d in divisors:
    mod_nums = list(map(lambda x: x%d, nums[:]))
    mod_nums = sorted(mod_nums)
    #print(mod_nums)
    x = 10**10
    for i in range(1, len(mod_nums)-1):
        if sum(mod_nums[:i]) == sum(list(map(lambda x: d-x, mod_nums[i:]))):
            x = sum(mod_nums[:i])
            break
    #print(d, x)
    if x <= K:
        ans = d
        break
            
        
        



print(ans)

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

nums = A[:]

sum_n = sum(nums)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

divisors = sorted(list(make_divisors(sum_n)), reverse=True)
#print('DIV', divisors)


for d in divisors:
    mod_nums = list(map(lambda x: x%d, nums[:]))
    mod_nums = sorted(mod_nums)
    #print(mod_nums)
    x = 10**10
    for i in range(1, len(mod_nums)):
        if sum(mod_nums[:i]) == sum(list(map(lambda x: d-x, mod_nums[i:]))):
            x = sum(mod_nums[:i])
            break
    #print(d, x)
    if x <= K:
        ans = d
        break
            
        
        



print(ans)
Problem p02990 (python)

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

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


blue = K
red = N - K

for i in range(1, K+1):
    try:
        pos = i 
        red_c = combinations_count(red+1, pos)


        blue_c =  combinations_count(blue - 1, i - 1)
        #print(red_c, blue_c)
        print(red_c * blue_c % (10 ** 9 + 7))
    except:
        print(0)

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

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


blue = K
red = N - K

for i in range(1, K+1):
    pos = i 
    red_c = combinations_count(red+1, pos)
    
    
    blue_c =  combinations_count(blue - 1, i - 1)
    #print(red_c, blue_c)
    print(red_c * blue_c % (10 ** 9 + 7))
Problem p03075 (python)

Fixed submission:
antennas = []
for _ in range(5):
    x = int(input())
    antennas.append(x)
k = int(input())

import itertools

ans = True
for x, y in list(itertools.combinations(antennas,2)):
    dist = abs(x - y)
    if dist > k:
        ans = False
        break

if ans == True:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

val_list = []


A_list = sorted(A_list, reverse=True)
B_list = sorted(B_list, reverse=True)
C_list = sorted(C_list, reverse=True)

for a in range(len(A_list)):
    if a + 1 > K:
        break
    for b in range(len(B_list)):
        if b + 1 > K:
            break
        if (a+1) * (b+1) > K:
            break
            
        for c in range(len(C_list)):
            if c + 1 > K:
                break
            if (a+1) * (b+1) * (c+1) > K:
                break
        
            val_list.append(A_list[a] + B_list[b] + C_list[c])

val_list = sorted(val_list, reverse=True)
for i in range(K):
    print(val_list[i])
Problem p03104 (python)

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

def cal_xor(X):
    X = X+1
    xor_sum = 0
    digit = 1
    while digit < X:
        digit *= 2
        bit_count = (X // digit) * (digit // 2)
        bit_count += max(0, (X % digit) - (digit // 2))
        
        if bit_count % 2 == 1:
            xor_sum += digit // 2
    
    return xor_sum
        

ans = cal_xor(A-1) ^ cal_xor(B)
print(ans)

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

AB = list(range(A, B+1))

ans = []
while AB[-1] != 0:
    div = lambda x: x // 2
    rem = lambda x: x % 2
    
    AB_bit = list(map(rem, AB))
    AB = list(map(div, AB))
    ans.append(str(sum(AB_bit) % 2))

ans.append('0')
ans.reverse()
ans_10 = int(''.join(ans), 2)
print(ans_10)

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

AB = list(range(A, B+1))

ans = []
while AB[-1] != 0:
    div = lambda x: x // 2
    rem = lambda x: x % 2
    
    AB_bit = list(map(rem, AB))
    AB = list(map(div, AB))
    ans.append(str(sum(AB_bit) % 2))
    
ans.reverse()
ans_10 = int(''.join(ans), 2)
print(ans_10)
Problem p03107 (python)

Fixed submission:
S = str(input())

s = S

zero = s.count('0')
one = s.count('1')

zero_one_diff = max(zero, one) - min(zero, one)
print(len(s) - zero_one_diff)

Buggy submission (verdict: Runtime Error):
S = str(input())

def del_cube(s, i):
    s = s[:i] + s[i+2:]
    return s

def dfs(s):
    ans_list = []
    flag = True
    if '10' in s:
        flag = False
        s_10 = s.replace('10', '')
        ans_list.append(dfs(s_10))
    if '01' in s:
        flag = False
        s_01 = s.replace('01', '')
        ans_list.append(dfs(s_01))
    
            
    if flag == True:
        return(len(s))
    else:
        return(min(ans_list))
    
print(len(S) - dfs(S))

Buggy submission (verdict: Runtime Error):
S = str(input())

def del_cube(s, i):
    s = s[:i] + s[i+2:]
    return s

def dfs(s):
    ans_list = []
    flag = True
    for i in range(len(s) - 1):
        if s[i] == '0' and s[i+1] == '1' or s[i] == '1' and s[i+1] == '0':
            flag = False
            del_s = del_cube(s, i)
            ans_list.append(dfs(del_s))
            
    if flag == True:
        return(len(s))
    else:
        return(min(ans_list))
    
print(len(S) - dfs(S))
Problem p03108 (python)

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

AB = []

for _ in range(M):
    A_i, B_i = map(int, input().split())
    AB.append([A_i, B_i])

class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)] # 親なら -1 * サイズ
        
    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    def size(self, x):
        x = self.root(x)
        return -1 * self.parent[x]
    
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        x_size = self.size(x)
        y_size = self.size(y)
        if x_size < y_size:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True
        
max_inconvenience = N * (N - 1) // 2 
ans = [max_inconvenience]
uf = UnionFind(N)
for bridge in reversed(AB):
    x = uf.root(bridge[0] - 1)
    y = uf.root(bridge[1] - 1)

    if x != y:
        x_size = uf.size(x)
        y_size = uf.size(y)
        ans_tmp = max_inconvenience - x_size * y_size
        max_inconvenience = ans_tmp
        uf.union(x, y)
    else:
        ans_tmp = max_inconvenience
    ans.append(ans_tmp)
    
for a in reversed(ans[:-1]):
    print(a)

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

AB = []

for _ in range(M):
    A_i, B_i = map(int, input().split())
    AB.append([A_i, B_i])
    
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)] # 親なら -1 * サイズ
        
    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    def size(self, x):
        x = self.root(x)
        return -1 * self.parent[x]
    
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        x_size = self.parent[x]
        y_size = self.parent[y]
        if x_size < y_size:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True
        
max_inconvenience = N * (N - 1) // 2 
ans = [max_inconvenience]
uf = UnionFind(N)
for bridge in reversed(AB):
    x = uf.root(bridge[0] - 1)
    y = uf.root(bridge[1] - 1)

    if x != y:
        x_size = uf.size(x)
        y_size = uf.size(y)
        ans_tmp = max_inconvenience - x_size * y_size
        max_inconvenience = ans_tmp
        uf.union(x, y)
    else:
        ans_tmp = max_inconvenience
    ans.append(ans_tmp)
    
for a in reversed(ans[:-1]):
    print(a)
Problem p03634 (python)

Fixed submission:
N = int(input())
ABC = []
for _ in range(N-1):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))

Q, K = map(int, input().split())
XY = []
for _ in range(Q):
    x,y = map(int, input().split())
    XY.append((x,y))
    
edges = ABC[:]

graph = {}
for a,b,c in edges:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = c
    graph[b][a] = c


from heapq import heappush, heappop

def dijkstra(graph, start):
    A = [None] * (N+1)
    queue = [(0, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    heappush(queue, (path_len + edge_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]

shortest = dijkstra(graph, K)
#print(shortest)

questions = XY

for x,y in questions:
    ans = shortest[x] + shortest[y]
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))

edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N)] for i in range(N)] 
for x,y,z in edges:
    graph[x-1][y-1] = z
    graph[y-1][x-1] = z
for i in range(N):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import itertools
line = R_LIST
for l in itertools.permutations(line):
    #print(l)
    tmp_len = 0
    for a,b in zip(l[:-1], l[1:]):
        tmp_len += shortest[a-1][b-1]

    #print(tmp_len)
    ans = min(ans, tmp_len)
print(ans)
Problem p02792 (python)

Fixed submission:
n = input()
 
d = [ [0] * 10 for _ in range(10) ]
for i in range( 1, int( n ) + 1 ):
  k = str(i)
  d[ int( k[ 0 ])][ int( k[ -1 ])] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += d[i][j] * d[j][i]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
max_N = 2 * 10 ** 5

d = [[0] * 10 for _ in range(10)]
for i in range(1,int(n)):
  k = str(i)
  d[int(k[0])][int(k[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += d[i][j] * d[j][i]
print(ans)