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

Fixed submission:
import heapq
 
N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    heapq.heappush(h, int(input()))
  
min_height = 1000000000
h = heapq.nsmallest(N, h)
for start in range(0, N - k + 1):
    end = start + k - 1
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)

Buggy submission (verdict: Runtime Error):
N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    heapq.heappush(h, int(input()))
  
min_height = 1000000000
h.sort()
for start in range(0, N - k + 1):
    end = start + k - 1
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)

Buggy submission (verdict: Runtime Error):
import heapq

N, k = int(input()), int(input())

h = []
while N > 0:
  heapq.heappush(h, int(input()))
  N -= 1
  
trees = heapq.nlargest(k, h)
if len(trees) <= 1:
  print(0)
else:
  print(trees[-1] - trees[0])
Problem p03207 (python)

Fixed submission:
n = input()
a = []
for i in range(int(n)):
    a.append(int(input()))

print(int(sum(a) - (max(a) / 2)))

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

m = 0
s = 0
for i in input_.splitlines():
    n = int(i)
    if i > max:
        max = i
    sum += n

print(sum - (max / 2))
Problem p03315 (python)

Fixed submission:
S = input()
ans = 0
for i in S:
  if i == "+":
    ans += 1
  else:
    ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0
for i in S:
  if i == "+":
    ans++
  else:
    ans--
print(ans)
Problem p03208 (python)

Fixed submission:
S = input()
S = S.split()
N = int(S[0])
K = int(S[1])
h = [int(input()) for i in range(N)]
h.sort()
ans = 10**9 + 1
for i in range(N - K + 1):
    tmp = h[i + K - 1] - h[i]
    if(tmp < ans):
        ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
S = S.split()
N = int(S[0])
K = int(S[1])
h = [int(input()) for i in range(N)]
h.sort()
ans = 10**9 + 1
for i in range(N - K + 1):
    tmp = h[i + 3 - 1] - h[i]
    if(tmp < ans):
        ans = tmp
print(ans)
Problem p03209 (python)

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

a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

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

a, p = [1], [1]
for i in range(N):
a.append(a[i] * 2 + 3)
p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  elif X == 2 + a[N-1]:
    return p[N-1] + 1
  elif X == 3 + 2 * a[N-1]:
    return 2 * p[N-1] + 1
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))

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

a, p = [1], [1]
for i in range(N):
　a.append(a[i] * 2 + 3)
　p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
　if N == 0:
　　return 0 if X <= 0 else 1
　elif X <= 1 + a[N-1]:
　　return f(N-1, X-1)
　else:
　　return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))
Problem p03208 (python)

Fixed submission:
N, K = (int(x) for x in input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy submission (verdict: Runtime Error):
N, K = (int(x) for x in input().split())
h = [int(input()) for i in range(K)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))
Problem p03208 (python)

Fixed submission:
nnk = input().split(" ")
n = int(nnk[0])
k = int(nnk[1])

hs = [int(input()) for l in range(n)]
hs.sort()

hmmm = []
for m in range(n-k+1):
    hmmm.append(hs[k+m-1] - hs[m])

hmmm.sort()
print(hmmm[0])

Buggy submission (verdict: Runtime Error):
n = nnk[0]
k = nnk[1]

hs = [int(input()) for l in range(n)]
hs.sort()

num = n - k + 1

hmmm = []
for l in range(num):
    hmmm.append(hs[k+l-1] - hs[l])

hmmm.sort()
print(hmm[0])

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-


nnk = list(map(lambda x: int(x), input().split(" ")))
n = nnk[0]
k = nnk[1]

hs = [int(input()) for l in range(n)]
hs.sort()

num = n - k + 1

hmmm = []
for l in range(num):
    hmmm.append(hs[k+l-1] - hs[l])

hmmm.sort()
print(hmm[0])
Problem p03207 (python)

Fixed submission:
from sys import stdin
a = stdin.readline()
w=int(a)
j=1
sumvalue=0
maxvalue=0
w2=[]
while j<=w:
    z = stdin.readline().rstrip('\n')
    sumvalue+=int(z)
    maxvalue=max(maxvalue,int(z))
    j+=1
print(sumvalue-int(maxvalue/2))

Buggy submission (verdict: Runtime Error):
from sys import stdin
a = stdin.readline().rstrip()
w=int(a)
j=1
sumvalue=0
maxvalue=0
while j<=w:
    a = stdin.readline().rstrip()
    sumvalue+=int(a)
    maxvalue=max(maxvalue,int(a))
print(sumvalue-int(maxvalue/2))
Problem p03208 (python)

Fixed submission:
from sys import stdin
a = stdin.readline().split(" ")
num=int(a[0])
find=int(a[1])
j=1
w2=[]
while j<=num:
    z = stdin.readline().rstrip('\n')
    w2.append(int(z))
    j+=1
w2.sort()
minnum=w2[find-1]-w2[0]
for i in range(len(w2)-find+1):
    minnum=min(minnum,w2[i+find-1]-w2[i])
print(minnum)

Buggy submission (verdict: Runtime Error):
from sys import stdin
a = stdin.readline().split(" ")
num=int(a[0])
find=int(a[1])
j=1
w2=[]
while j<=num:
    z = stdin.readline().rstrip('\n')
    w2.append(int(z))
    j+=1
w2.sort()
minnum=w2[find-1]-w2[0]
for i in range(len(w2)-2):
    minnum=min(minnum,w2[i+find-1]-w2[i])
print(minnum)
Problem p03250 (python)

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

one.sort()
print(10*one[2]+one[1]+one[0])

Buggy submission (verdict: Runtime Error):
one=list(input())
#print(one)
two=list(input())

for num,i in enumerate(one):
    if i not in z:
        z[i]=[num]
    else:
        z[i].append(num)
p={}
for num,i in enumerate(two):
    if i not in p:
        p[i]=[num]
    else:
        p[i].append(num)
w=[]
#print(p)
#print(z)
for k,v in z.items():
    w.append(v)
o=[]
for k,v in p.items():
    o.append(v)
print("Yes") if w==o else print("No")
Problem p03252 (python)

Fixed submission:
def main():
    data0 = input()
    data1 = input()

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while True:
        if data0 == "":
            break

        data0 = data0.replace(data0[0], "")
        data1 = data1.replace(data1[0], "")

        if len(data0) != len(data1):
            print('No')
            exit()

    print('Yes')

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
one=list(input())
#print(one)
two=list(input())

for num,i in enumerate(one):
    if i not in z:
        z[i]=[num]
    else:
        z[i].append(num)
p={}
for num,i in enumerate(two):
    if i not in p:
        p[i]=[num]
    else:
        p[i].append(num)
w=[]
#print(p)
#print(z)
for k,v in z.items():
    w.append(v)
o=[]
for k,v in p.items():
    o.append(v)
print("Yes") if w==o else print("No")

Buggy submission (verdict: Runtime Error):
one=list(input())
#print(one)
two=list(input())
if one==[] or two==[]
z={}
for num,i in enumerate(one):
    if i not in z:
        z[i]=[num]
    else:
        z[i].append(num)
p={}
for num,i in enumerate(two):
    if i not in p:
        p[i]=[num]
    else:
        p[i].append(num)
w=[]
#print(p)
#print(z)
for k,v in z.items():
    w.append(v)
o=[]
for k,v in p.items():
    o.append(v)
print("Yes") if w==o else print("No")
Problem p03209 (python)

Fixed submission:
def cal(N, i):
    if N > 0:
        return 2 * cal(N - 1, i) + i
    elif N == 0:
        return 1
    else:
        return 0

def pCal(N ,X):
    total = cal(N, 3)
    half = total // 2
    pTmp = cal(N - 1, 1)
    if X == 1 and N == 0:
        return 1
    elif X <= N:
        return 0
    elif X < half:
        return pCal(N - 1, X - 1)
    elif X == half:
        return pTmp
    elif X == half + 1:
        return pTmp + 1
    elif total > X > half + 1:
        return (pTmp + 1) + pCal(N - 1, X - (half + 1))
    elif X == total:
        return cal(N, 1)
N, X = list(map(int, input().split()))
print(pCal(N, X))

Buggy submission (verdict: Runtime Error):
def cal(N, i):
    if N > 0:
        return 2 * cal(N - 1, i) + i
    elif N == 0:
        return 1
    else:
        return 0

def pCal(N ,X):
    total = cal(N, 3)
    half = total // 2
    pTmp = cal(N - 1, 1)
    if X == 1 and N == 0:
        return 1
    elif X <= N:
        return 0
    elif X < half:
        return pCal(N - 1, X - 1)
    elif X == half:
        return pTmp
    elif X == half + 1:
        return pTmp + 1
    elif total > X > half + 1:
        return (pTmp + 1) + pCal(N - 1, X - (half + 1))
    elif x == total:
        return cal(N, 1)
N, X = list(map(int, input().split()))
print(pCal(N, X))

Buggy submission (verdict: Runtime Error):
def cal(N, i):
    if N > 0:
        return 2 * cal(N - 1, i) + i
    elif N == 0:
        return 1
    else:
        return 0

def pCal(N ,X):
    total = cal(N, 3)
    half = total // 2
    pTmp = cal(N - 1, 1)
    if X == 1 and N == 0:
        return 1
    elif X <= N:
        return 0
    elif X < half:
        return pCal(N - 1, X - 1)
    elif X == half:
        return pTmp
    elif X == half + 1:
        return pTmp + 1
    elif total > X > half + 1:
        return (pTmp + 1) + pCal(N - 1, X - (half + 1))
    else x == total
        return cal(N, 1)
N, X = list(map(int, input().split()))
print(pCal(N, X))
Problem p03253 (python)

Fixed submission:
N, M = map(int, input().split())
a1, a2 = 2, M
a = {}
while (a1 - 1) ** 2 <= a2 or a1 == a2:
    if a2 % a1 == 0:
        a2 //= a1
        if a1 in a:
            a[a1] += 1
        else:
            a[a1] = 1
    else:
        a1 += 1
p = 1
if a2 != 1:
    a[a2] = 1
for v in a.values():
    tmp = 1
    for i in range(v):
        tmp = tmp * (v + N - 1 - i) // (i + 1)
    p *= tmp
print(p % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
from collections import Counter
from math import factorial as f
N, M = map(int, input().split())
a1, a2 = 2, M
a = []
while a2 != 1:
    if a2 % a1 == 0:
        a.append(a1)
        a2 //= a1
    else:
        a1 += 1
ca = Counter(a)
sa = sum(ca.values())
p = 1
for v in ca.values():
    p *= f(sa + v - 1) // (f(v) * f(sa - 1))
print(p * (f(N) // (f(sa) * f(N - sa))) % (10 ** 9 + 7))
Problem p03222 (python)

Fixed submission:
import itertools

H,W,K = map(int, input().split())
p = 1000000007

if K - 1 > H:
    print(0)
    exit(0)
if W == 1:
    print(1)
    exit(0)

R = []
for r in itertools.product( [0,1], repeat=(W-1) ):
    if 1 not in list(map(lambda i : r[i]*r[i+1], range(len(r)-1)) ):
        R.append(r)


M = [ (
    len( list( filter( lambda r:r[0]==0, R) ) ),
    len( list( filter( lambda r:r[0]==1, R) ) ),
    0
) ]
for c in range(1,W-1):
    M.append((
        len( list( filter( lambda r:r[c]==0 and r[c-1]==0, R) ) ),
        len( list( filter( lambda r:r[c]==1, R) ) ),
        len( list( filter( lambda r:r[c-1]==1, R) ) )
    ))
M.append((
    len( list( filter( lambda r:r[W-2]==0, R) ) ),
    0,
    len( list( filter( lambda r:r[W-2]==1, R) ) )
))

count = [1] + [0]*(W-1)
for h in range(H):
    count_ = [0] * W
    for num,c in zip(count, range(len(count))):
        for m,n in zip(M[c], [0,+1,-1]):
            if c+n >= 0 and c+n < W:
                count_[c+n] += num * m
    count = count_
        
print(count_[K-1]%p)

Buggy submission (verdict: Runtime Error):
import itertools

H,W,K = map(int, input().split())
p = 1000000007

if K - 1 > H:
    print(0)
    exit(0)

R = []
for r in itertools.product( [0,1], repeat=(W-1) ):
    if 1 not in list(map(lambda i : r[i]*r[i+1], range(len(r)-1)) ):
        R.append(r)


M = [ (
    len( list( filter( lambda r:r[0]==0, R) ) ),
    len( list( filter( lambda r:r[0]==1, R) ) ),
    0
) ]
for c in range(1,W-1):
    M.append((
        len( list( filter( lambda r:r[c]==0 and r[c-1]==0, R) ) ),
        len( list( filter( lambda r:r[c]==1, R) ) ),
        len( list( filter( lambda r:r[c-1]==1, R) ) )
    ))
M.append((
    len( list( filter( lambda r:r[W-2]==0, R) ) ),
    0,
    len( list( filter( lambda r:r[W-2]==1, R) ) )
))

count = [1] + [0]*(W-1)
for h in range(H):
    count_ = [0] * W
    for num,c in zip(count, range(len(count))):
        for m,n in zip(M[c], [0,+1,-1]):
            if c+n >= 0 and c+n < W:
                count_[c+n] += num * m
    count = count_
        
print(count_[K-1]%p)

Buggy submission (verdict: Runtime Error):
import itertools

H,W,K = map(int, input().split())
p = 1000000007

if K - 1 > H:
    print(0)
    exit(0)

R = []
for r in itertools.product( [0,1], repeat=(W-1) ):
    if 1 not in list(map(lambda i : r[i]*r[i+1], range(len(r)-1)) ):
        R.append(r)


M = [ (
    len( list( filter( lambda r:r[0]==0, R) ) ),
    len( list( filter( lambda r:r[0]==1, R) ) ),
    0
) ]
for c in range(1,W-1):
    M.append((
        len( list( filter( lambda r:r[c]==0 and r[c-1]==0, R) ) ),
        len( list( filter( lambda r:r[c]==1, R) ) ),
        len( list( filter( lambda r:r[c-1]==1, R) ) )
    ))
M.append((
    len( list( filter( lambda r:r[W-2]==0, R) ) ),
    0,
    len( list( filter( lambda r:r[W-2]==1, R) ) )
))

print(R)
print(M)

count = [1] + [0]*(W-1)
for h in range(H):
    count_ = [0] * W
    for num,c in zip(count, range(len(count))):
        for m,n in zip(M[c], [0,+1,-1]):
            if c+n >= 0 and c+n < W:
                count_[c+n] += num * m
    count = count_
        
print(count_[K-1]%p)
Problem p03253 (python)

Fixed submission:
import math
from scipy.misc import comb

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

def factorize(M):
    P = []
    F = []
    for m in range(2, int(math.sqrt(M))+1):
        n = 0
        while M % m == 0:
            M/= m
            n +=1
        if n != 0:
            P.append(m)
            F.append(n)
    if M != 1:
        P.append(M)
        F.append(1)
    return P,F

P, F = factorize(M)

X = 1
for f in F:
    X *= int(comb(N+f-1, f, exact=True))
    X %= int(pow(10,9)+7)

print(X)

Buggy submission (verdict: Runtime Error):
import math
import scipy.special

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

def factorize(M):
    P = []
    F = []
    for m in range(2, int(math.sqrt(M))+1):
        n = 0
        while M % m == 0:
            M/= m
            n +=1
        if n != 0:
            P.append(m)
            F.append(n)
    if M != 1:
        P.append(M)
        F.append(1)
    return P,F

P, F = factorize(M)

X = 1
for f in F:
    X *= int(scipy.special.comb(N+f-1, f, exact=True))
    X %= int(pow(10,9)+7)

print(X)
Problem p03272 (python)

Fixed submission:
n, i = map(int,input().split())
print(n-i+1)

Buggy submission (verdict: Runtime Error):
n, i = map(int,input().aplit())

print(n - i + 1)
Problem p03209 (python)

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

a,p = [1],[1]

#バーガーの厚みとパティの総数を求める

for i in range(n):
    a.append(2 * a[i] + 3)
    p.append(2 * p[i] + 1)

def f(N,X):
    if N == 0:
        if X <= 0:
            return 0

        else:
            return 1

    elif X <= 1 + a[N-1]:
        return f(N -1,X-1)

    else:#if X <= 2 + 2 * a[N-1]:
        return p[N-1] + 1 + f(N -1, X-2-a[N-1])

print(f(n,x))

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

a, p = [1], [1]

for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)
def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N-1]:
		return f(N-1, X-1)
	else:
		return p[N-1] + 1 + f(N-1, X-2-a[N-1])

 print(f(N, X))
Problem p03705 (python)

Fixed submission:
N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

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

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

Buggy submission (verdict: Runtime Error):
import sys

N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])



if(N[1] > N[2]):
    print("0")
    exit(1)

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

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

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    print("0")
    exit(1)

if(N[1] > N[2]):
    print("0")
    exit(1)

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

Buggy submission (verdict: Runtime Error):
import sys

N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    print("0")
    sys.exit(1)

if(N[1] > N[2]):
    print("0")
    sys.exit(1)

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

Buggy submission (verdict: Runtime Error):
import sys

N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    print("0")
    sys.exit(1)

if(N[1] > N[2]):
    print("0")
    sys.exit(1)

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)
Problem p03250 (python)

Fixed submission:
l = sorted(list(map(int, input().split())))
print(l[0] + int(str(l[2]) + str(l[1])))

Buggy submission (verdict: Runtime Error):
l = sorted(ist(map(int, input().split())))
print(l[0] + int(str(l[1]) + str(l[2])))
Problem p03803 (python)

Fixed submission:
a, b = map(int, input().split())

if (a > b and b != 1) or (a==1 and b!=1):
    print('Alice')
elif (b > a and a!=1) or (a!=1 and b==1):
    print('Bob')
else:
    print('Draw')

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

if (a > b and b != 1) or (a==1 and b!=1):
    print('Alice')
elif (b > a a!=1) and (a!=1 and b==1):
    print('Bob')
else:
    print('Draw')
Problem p03631 (python)

Fixed submission:
n = input()
if n[2]+n[1]+n[0] == n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
if n[2]n[1]n[0] == n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
if n[2][1][0] == n:
    print("Yes")
else:
    print("No")
Problem p03775 (python)

Fixed submission:
import math

N = int(input())
answer = []
b = 0
for a in range(1,round(math.sqrt(N))+1):
  if N%a == 0:
    b = N//a
    answer.append(max(len(str(a)), len(str(b))))
print(min(answer))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
ans = []
for i in range(1,round(math.sqrt(N))):
    if N%i == 0:
        ans.append(len(str(N//i)))
print(min(ans))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
answer = []
b = 0
for a in range(1,round(sqrt(N))+1):
  if N%a == 0:
    b = N//a
    answer.append(max(len(str(a)), len(str(b))))
print(min(answer))

Buggy submission (verdict: Runtime Error):
N = int(input())
answer = []
b = 0
for a in range(1,round(abs(N))):
  if N%a == 0:
    b = N//a
    answer.append(max(len(str(a)), len(str(b))))
print(min(answer))

Buggy submission (verdict: Runtime Error):
N = int(input())
answer = 1000
b = 0
for a in range(round(abs(N))):
  if N&a == 0:
    b = N/a
    if answer < min(len(str(a)), len(str(b))):
      answer = min(len(str(a)), len(str(b)))
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
answer = 1000
for a in range(round(abs(N))):
  if N&a == 0:
    b = N/a
    if answer < min(len(str(a)), len(str(b))):
      answer = min(len(str(a)), len(str(b)))
print(answer)
Problem p03634 (python)

Fixed submission:
N = int(input())
route = [{} for _ in range(N)]
dist = [-1] * N
for i in range(N - 1):
    a, b, d = map(int, input().split())
    route[a-1][b-1] = d
    route[b-1][a-1] = d

Q, K = map(int, input().split())
dist[K-1] = 0
dfs_stack = [K-1]
while dfs_stack:
    s = dfs_stack.pop()
    for t, t_dist in route[s].items():
        if dist[t] == -1:
            dist[t] = dist[s] + t_dist
            dfs_stack.append(t)
for i in range(Q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    print(dist[x] + dist[y])

Buggy submission (verdict: Runtime Error):
def get_path(start, goal, prev):
    path = []
    now = goal
    path.append(now)
    while True:
        path.append(prev[now])
        if prev[now] == start: break
        now = prev[now]
    path.reverse()
    return path

def search(glaph, start, goal):
    MAX_VAL = 0x10000000
    g_size = len(glaph)
    visited = [False] * g_size
    cost = [MAX_VAL] * g_size
    prev = [None] * g_size
    cost[start] = 0
    prev[start] = start
    now = start
    while True:
        min = MAX_VAL
        next = -1
        visited[now] = True
        for i in range(g_size):
            if visited[i]: continue
            if glaph[now][i]:
                tmp_cost = glaph[now][i] + cost[now]
                if cost[i] > tmp_cost:
                    cost[i] = tmp_cost
                    prev[i] = now
            if min > cost[i]:
                min = cost[i]
                next = i
        if next == -1: break
        now = next
    return [get_path(start, goal, prev), cost[goal]]

N = int(input())
route = [[0 for i in range(N)] for j in range(N)]
for i in range(N - 1):
    a, b, d = map(int, input().split())
    route[a-1][b-1] = d
    route[b-1][a-1] = d
Q, K = map(int, input().split())

for i in range(Q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    path, cost1 = search(route, x, K - 1)
    path, cost2 = search(route, K - 1, y)
    cost = cost1 + cost2
    print(cost)
Problem p03242 (python)

Fixed submission:
s = input()
 
ans = ''
for w in str(s):
    if w == '1':
        ans += '9'
    elif w == '9':
        ans += '1'
        
print(int(ans))

Buggy submission (verdict: Runtime Error):
n = input()
 
ans = ''
for w in str(s):
    if w == '1':
        ans += '9'
    elif w == '9':
        ans += '1'
    else:
        ans += str(w)
        
print(int(ans))

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

ans = ''
for w in str(s):
    if w == '1':
        ans += '9'
    elif w == '9':
        ans += '1'
    else:
        ans += str(w)
        
print(int(ans))
Problem p03307 (python)

Fixed submission:
N = int(input())
if N % 2 == 1:
    print(N*2)
else:
    print(N)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 2 = 1:
    print(N*2)
else:
    print(N)
Problem p03705 (python)

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

z = (n - 2) * (b - a) + 1

if z < 0:
    print("0")
elif z == 0:
    print("1")
else:
    print(z)

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

z = 0

for i in s:
    if s[i] == "U":
        z += (len(s) - i)*1 + i * 2
    else:
        z += (len(s) - i)*2 + i * 1

print(z)

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

count = 0L

for i in range(len(s)):
    for j in range(len(s)):
        #print(i, j)
        if (i < j and s[i] == "D") or (i > j and s[i] == "U"):
            count += 2
        elif (i < j and s[i] == "U") or (i > j and s[i] == "D"):
            count += 1

print(count)