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

Fixed submission:
from math import factorial
n = int(input())
src = [''.join(sorted(input())) for _ in range(n)]
dic = {}
for s in src:
    # 辞書にキーが存在しなければキー追加
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
count = 0
# 辞書から値だけ取り出す
for d in dic.values():
    # dまでの値の組み合わせを合計する
    if d > 2:
        count += factorial(d) // 2 // factorial(d - 2)
    elif d == 2:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
from math import factorial
n = int(input())
src = [''.join(sorted(input())) for _ in range(n)]
dic = {}
for s in src:
    # 辞書にキーが存在しなければキー追加
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
count = 0
# 辞書から値だけ取り出す
for d in dic.values():
    # dまでの値の組み合わせを合計する
    if d > 2:
        count += int(factorial(d) / factorial(2) / factorial(d - 2))
    elif d == 2:
        count += 1
print(count)
Problem p02995 (python)

Fixed submission:
import fractions
a,b,c,d = map(int,input().split())
lcm = c * d // fractions.gcd(c, d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
warikireru = x+y - (b//lcm - (a-1)//lcm)
print(b-a+1-warikireru)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = c * d // math.gcd(c, d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
warikireru = x+y - (b//lcm - (a-1)//lcm)
print(b-a+1-warikireru)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = c * d // math.gcd(c, d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
warikireru = x+y - (b//lcm - (a-1)//lcm)
print(b-a+1-warikireru)
Problem p03076 (python)

Fixed submission:
import math
src = [input() for _ in range(5)]
k_li = []
v_li = []
sum = 0
for s in src:
    if int(s[-1]) != 0:
        k_li.append(int(s[-1]))
        v_li.append(int(s))
    else:
        sum += int(s)
flag = False
if len(k_li)>0:
    m = min(k_li)
    for k,v in zip(k_li,v_li):
        if k == m and flag == False:
            sum += v
            flag = True
        else:
            sum += math.ceil(v/10)*10
print(sum)

Buggy submission (verdict: Runtime Error):
import math
src = [input() for _ in range(5)]
k_li = []
v_li = []
sum = 0
for s in src:
    if int(s[-1]) != 0:
        k_li.append(int(s[-1]))
        v_li.append(int(s))
    else:
        sum += int(s)
m = min(k_li)
flag = False
if len(k_li)>0:
    for k,v in zip(k_li,v_li):
        if k == m and flag == False:
            sum += v
            flag = True
        else:
            sum += math.ceil(v/10)*10
print(sum)

Buggy submission (verdict: Runtime Error):
import math
src = [input() for _ in range(5)]
k_li = []
v_li = []
sum = 0
for s in src:
    if int(s[-1]) != 0:
        k_li.append(int(s[-1]))
        v_li.append(int(s))
    else:
        sum += int(s)
m = min(k_li)
flag = False
for k,v in zip(k_li,v_li):
    if k == m and flag == False:
        sum += v
        flag = True
    else:
        sum += math.ceil(v/10)*10
print(sum)
Problem p03243 (python)

Fixed submission:
n = input()
li = list(n)
same = li[0]*len(li)
if int(n) <= int(same):
    print(same)
else:
    print(str(int(li[0])+1)*len(li))

Buggy submission (verdict: Runtime Error):
n = input()
li = list(n)
same = li[0]*len(li)
if int(n) <= int(same):
    print(same)
else:
    print(str(int(li[0]+1))*len(li))
Problem p03361 (python)

Fixed submission:
import sys
h,w = map(int,input().split())
matrix = [[0]*(w+2) for _ in range(h+2)]
for hi in range(h):
    all_inp = input()
    for i,a in enumerate(all_inp):
        matrix[hi+1][i+1]= 1 if a == '#' else 0
#print(matrix)
for ri,row in enumerate(matrix):
    for ci,column in enumerate(row):
        if column == 1:
            if row[ci-1] == 0 and row[ci+1] == 0 and matrix[ri-1][ci] == 0 and matrix[ri+1][ci] == 0:
                print('No')
                sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w = map(int,input().split())
matrix = [[0]*(h+2) for _ in range(w+2)]
for hi in range(h):
    all_inp = input()
    for i,a in enumerate(all_inp):
        matrix[hi+1][i+1]= 0 if a == '.' else 1
#print(matrix)
for ri,row in enumerate(matrix):
    for ci,column in enumerate(row):
        if column == 1:
            if row[ci-1] == 0 and row[ci+1] == 0 and matrix[ri-1][ci] == 0 and matrix[ri+1][ci] == 0:
                print('No')
                sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
h,w = map(int,input().split())
matrix = [[0]*(h+2) for _ in range(w+2)]
for hi in range(h):
    all_inp = input()
    for i,a in enumerate(all_inp):
        matrix[hi+1][i+1]= 0 if a == '.' else 1
print(matrix)
for ri,row in enumerate(matrix):
    for ci,column in enumerate(row):
        if column == 1:
            if row[ci-1] == 0 and row[ci+1] == 0 and matrix[ri-1][ci] == 0 and matrix[ri+1][ci] == 0:
                print('No')
                sys.exit()
print('Yes')
Problem p03481 (python)

Fixed submission:
import math
x,y = map(int,input().split())
tmp = 1
while x*(2**tmp) <= y:
    tmp += 1
print(tmp)

Buggy submission (verdict: Runtime Error):
import math
x,y = map(int,input().split())
print(int(math.log2(y/x))+1)
Problem p03486 (python)

Fixed submission:
s = input()
t = input()
s_sorted = ''.join(sorted(s))
t_sorted = ''.join(sorted(t, reverse=True))
if s_sorted < t_sorted:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
s_li = []
for si in s:
    s_li.append(alp.find(si))
t_li = []
for ti in t:
    t_li.append(alp.find(ti))
if max(s_li) < max(t_li):
    print('Yes')
elif max(set(s_li)-set(t_li)) < max(set(t_li)-set(s_li)):
    print('Yes')
elif set(s_li) == set(t_li) and len(s_li) < len(t_li):
    print('Yes')
else:
    print('No')
Problem p03645 (python)

Fixed submission:
n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
ll = len(set(one_li) & set(to_n_li))
if ll == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Buggy submission (verdict: Runtime Error):
import bisect
n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
#print(one_li,to_n_li)
if len(one_li) == 0 or len(to_n_li) == 0:
    print('IMPOSSIBLE')
    exit()
for o in list(set(one_li)):
    index = bisect.bisect_left(to_n_li, o)
    #print(to_n_li,o,index)
    if to_n_li[index] == o:
        print('POSSIBLE')
        exit()
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
import bisect
n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
#print(one_li,to_n_li)
if len(one_li) == 0 or len(to_n_li) == 0:
    print('IMPOSSIBLE')
    exit()
for o in list(set(one_li)):
    index = bisect.bisect_left(to_n_li, o)
    print(to_n_li,o,index)
    if to_n_li[index] == o:
        print('POSSIBLE')
        exit()
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
import bisect
n,m = map(int,input().split())
one_li = []
to_n_li = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        one_li.append(b)
    if b == n:
        to_n_li.append(a)
#print(one_li,to_n_li)
for o in list(set(one_li)):
    index = bisect.bisect_left(to_n_li, o)
    if to_n_li[index] == o:
        print('POSSIBLE')
        exit()
else:
    print('IMPOSSIBLE')
Problem p03680 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
n = int(input())
a_list = [int(input()) for _ in range(n)]
def calc_ans(start_num, count, max_count, all_list):
    ans = all_list[start_num-1]
    if ans == 2:
        print(count)
    elif count == max_count:
        print('-1')
    else:
        calc_ans(ans, count+1, max_count, all_list)
calc_ans(1, 1, n, a_list)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
n = int(input())
a_list = [int(input()) for _ in range(n)]
def calc_ans(start_num, count, max_count, all_list):
    ans = all_list[start_num-1]
    if ans == 2:
        print(count)
    elif count == max_count:
        print('-1')
    else:
        calc_ans(ans, count+1, max_count, all_list)
calc_ans(1, 1, n, a_list)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_list = [int(input()) for _ in range(n)]
def calc(start_num, count, max_count, all_list):
    ans = all_list[start_num-1]
    if ans == 2:
        print(count)
    elif count == max_count:
        print('-1')
    else:
        calc(ans, count+1, max_count, all_list)
calc(1, 1, n, a_list)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_list = [int(input()) for _ in range(n)]
def calc(start_num, count, max_count, all_list):
    ans = all_list[start_num-1]
    if ans == 2:
        print(count)
    elif count == max_count:
        print('-1')
    else:
        calc(ans, count+1, max_count, all_list)
calc(1, 1, n, a_list)
Problem p03854 (python)

Fixed submission:
import sys #追加
sys.setrecursionlimit(500*500)

s = input()
check_flag = True
def check_and_cut(string):
    tmp = '123'
    flag = True
    if len(string) <= 4:
        pass
    else:
        if len(string) >4:
            if string[-5:] == 'dream':
                tmp = string[:-5]
                flag = False
            elif string[-5:] == 'erase':
                tmp = string[:-5]
                flag = False
        if len(string) >5 and flag:
            if string[-6:] == 'eraser':
                tmp = string[:-6]
                flag = False
        if len(string) >6 and flag:
            if string[-7:] == 'dreamer':
                tmp = string[:-7]
                flag = False
    #print(string,len(string),string[-6:],tmp,string[-6:] == 'eraser')
    return tmp
while check_flag:
    t = check_and_cut(s)
    if t == '123':
        print('NO')
        exit()
    if len(t) == 0:
        print('YES')
        exit()
    s = t

Buggy submission (verdict: Runtime Error):
s = input()
def check_and_cut(string):
    tmp = '123'
    flag = True
    if len(string) <= 4:
        pass
    else:
        if len(string) >4:
            if string[-5:] == 'dream':
                tmp = string[:-5]
                flag = False
            elif string[-5:] == 'erase':
                tmp = string[:-5]
                flag = False
        if len(string) >5 and flag:
            if string[-6:] == 'eraser':
                tmp = string[:-6]
                flag = False
        if len(string) >6 and flag:
            if string[-7:] == 'dreamer':
                tmp = string[:-7]
                flag = False
    #print(string,len(string),string[-6:],tmp,string[-6:] == 'eraser')
    if tmp == '':
        print('YES')
    else:
        if tmp == '123':
            print('NO')
        else:
            check_and_cut(tmp)
check_and_cut(s)

Buggy submission (verdict: Runtime Error):
s = input()
def check_and_cut(string):
    tmp = '123'
    if len(string) <= 4:
        pass
    else:
        if len(string) >4:
            if string[-5:] == 'dream':
                tmp = string[:-5]
            elif string[-5:] == 'erase':
                tmp = string[:-5]
        if len(string) >5:
            if string[-6:] == 'eraser':
                tmp = string[:-6]
        if len(string) >6:
            if string[-7:] == 'dreamer':
                tmp = string[:-7]
    #print(string,len(string),string[-6:],tmp,string[-6:] == 'eraser')
    if tmp == '':
        print('YES')
    else:
        if tmp == '123':
            print('NO')
        else:
            check_and_cut(tmp)
check_and_cut(s)
Problem p04020 (python)

Fixed submission:
n = int(input())
ans = 0
li = []
tmp = 0
for i in range(n):
    t = int(input())
    if t == 0:
        li.append(tmp)
        tmp = 0
    else:
        tmp += t
li.append(tmp)
for l in li:
    ans += l//2
#print(li)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
li = []
tmp = []
for i in range(n):
    num = i+1
    t = int(input())
    if t == 0:
        li.append(tmp)
        tmp = []
    else:
        tmp += [num]*t
li.append(tmp)
for l in li:
    ans += len(l)//2
#print(li)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
li = []
tmp = []
for i in range(n):
    num = i+1
    t = int(input())
    if t == 0:
        li.append(tmp)
        tmp = []
    else:
        tmp += [num]*t
li.append(tmp)
for l in li:
    ans += len(l)//2
#print(li)
print(ans)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()

if len(s) != len(t) - 1:
  print("No")
elif s != t[:-1]:
  print("No")
else:
  print("Yes")

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

if A >= K:
  print(A)
elif A + B >= K:
  print(A)
else:
  print(A - (K - (A + B)))
Problem p03262 (python)

Fixed submission:
import fractions
N, X = map(int, input().split())
Y = list(map(int, input().split()))
ans = abs(Y[0]-X)
for i in range(1,N):
    ans = fractions.gcd(ans, abs(Y[i]-X))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

import math
N, X = map(int, input().split())
Y = list(map(int, input().split()))
ans = abs(Y[0]-X)
for i in range(1,N):
    ans = math.gcd(ans, abs(Y[i]-X))

print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
Y = list(map(int, input().split()))
ans = abs(Y[0]-X)
for i in range(1,N):
    ans = math.gcd(ans, abs(Y[i]-X))

print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(x[0]-X)
for i in range(1,N):
    ans = math.gcd(ans, abs(x[i]-X))

print(ans)
Problem p03828 (python)

Fixed submission:
import math
from collections import defaultdict


def make_prime_list(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num+1, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]


num = int(input())
div_sum = defaultdict(int)

p = make_prime_list(num)
for j in range(2, num+1):

    div_num = defaultdict(int)

    for i in p:
        n = j
        while n % i == 0:
            div_num[i] += 1
            n //= i

    for k, v in div_num.items():
        div_sum[k] += v

ans = 1
for k, v in div_sum.items():
    ans *= (v + 1)
print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
num = int(input())
div_sum = defaultdict(int)

p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

for j in range(1, num + 1):

    div_num = defaultdict(int)

    for i in p:
        n = j
        while n % i == 0:
            div_num[i] += 1
            n //= i

    for k, v in div_num.items():
        div_sum[k] += v

ans = 1
for k, v in div_sum.items():
    ans *= (v + 1)
print(ans % (10**9 + 7))
Problem p03844 (python)

Fixed submission:
# -*- coding: utf-8

a, op, b = input().split()
if op == '+':
    print(int(a) + int(b))
else:
    print(int(a) - int(b))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8

a, op, b = input().split()
if op == '+':
    print(a + b)
else:
    print(a - b)
Problem p03845 (python)

Fixed submission:
# -*- coding: utf-8

n = int(input())
t = list(map(int, input().split()))

for i in range(int(input())):
    p, x = map(int, input().split())
    print(sum(t) - t[p- 1] + x)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8

n = int(input())
t = list(map(int, input().split()))

for i in range(int(input())):
    p, x = map(int, input().split())
    print(sum(t) - t[p] + x)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8

n = int(input())
t = list(map(int, input().split()))

for i in range(int(input())):
    p, x = map(int, input().split())
    print(sum(t) - t[p] + x)
Problem p03945 (python)

Fixed submission:
# -*- coding: utf-8

s = list(input())
count = 0

if s.count('W') == len(s) or s.count('B') == len(s):
    print('0')
else:
    turn = s[len(s) - 1]
    s.pop()
    while s:
        if s[len(s) - 1] == turn:
            s.pop()
        else:
            count += 1
            if turn == 'B':
                turn = 'W'
            else:
                turn = 'B'
    print(count)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8

import sys


def leftside_reverse(s, turn):
    for num in range(len(s)):
        if s[num] == turn:
            break
        else:
            s[num] = turn

    return s


def rightside_reverse(s, turn):
    for num in range(len(s) - 1, -1):
        if s[num] == turn:
            break
        else:
            s[num] = turn

    return s


def function(s, first):
    count = 0
    turn = first

    while True:

        if s.count(first) == len(s):
            break

        if s[0] == turn:
            s = rightside_reverse(s, turn)
            count += 1
        else:
            s = leftside_reverse(s, turn)
            count += 1

        if turn == 'B':
            turn = 'W'
        else:
            turn = 'B'

    return count


if __name__ == '__main__':

    s = list(input())
    b = 'B'
    w = 'W'

    if s.count(b) == len(s) or s.count(w) == len(s):
        print('0')
        sys.exit(1)

    b_count = function(s, b)
    w_count = function(s, w)

    print(min(b_count, w_count))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8

import sys


def leftside_reverse(s, turn):
    for num in len(s):
        if s[num] == turn:
            return s
        else:
            s[num] = turn

    return s


def rightside_reverse(s, turn):
    for num in range(len(s), 0, -1):
        if s[num] == turn:
            return s
        else:
            s[num] = turn

    return s


def function(s, turn):
    count = 0

    while True:
        if s.count(turn) == len(s):
            return count

        if s[0] == turn:
            s = leftside_reverse(s, turn)
            count += 1
        else:
            s = rightside_reverse(s, turn)
            count += 1

        if turn == b:
            turn = w
        else:
            turn = b


if __name__ == '__main__':

    s = list(input())
    b = 'B'
    w = 'W'

    if s.count(b) == len(s) or s.count(w) == len(s):
        print('0')
        sys.exit(1)

    b_count = function(s, b)
    w_count = function(s, w)

    print(min(b_count, w_count))
Problem p04029 (python)

Fixed submission:
n = int(input())
print(int((n+1)*n/2))

Buggy submission (verdict: Runtime Error):
n = int(input))
print((n + 1)*n/2)
Problem p04030 (python)

Fixed submission:
# -*- coding: utf-8 -*-

s = list(input())
line = []
for w in s:
    if w == '0':
        line.append(w)
    elif w == '1':
        line.append(w)
    elif w == 'B' and line:
        line.pop()

for n in line:
    print('{0}'.format(n), end='')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

s = list(input())
line = []
for w in s:
    if w == '0':
        line.append(w)
    elif w == '1':
        line.append(w)
    elif w == 'B':
        line.pop()

for n in line:
    print('{0}'.format(n), end='')

Buggy submission (verdict: Runtime Error):
s = list(input())
line = []
for w in s:
  if w == '0':
    line.append(w)
  elif w == '1':
    line.append(w)
  elif w == 'B':
    line.pop()
    
for n in line:
  print('{0}'.format(n), end='')
Problem p02641 (python)

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

lp.sort()

distance = 0
try:
    idx = lp.index(x)
    while True:
        distance += 1
        dmin = x-distance
        dmax = x+distance
        if (idx-distance) < 0 or dmin != lp[idx-distance]:
            print(dmin)
            exit()
        if (idx+distance) >= len(lp) or  dmax != lp[idx+distance]:
            print(dmax)
            exit()
except ValueError:
    print(x)
    exit()

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

lp.sort()

distance = 0
try:
    idx = lp.index(x)
    while True:
        distance += 1
        dmin = x-distance
        dmax = x+distance
        if dmin != lp[idx-distance]:
            print(dmin)
            exit()
        if dmax != lp[idx+distance]:
            print(dmax)
            exit()
except ValueError:
    print(x)
    exit()
Problem p02646 (python)

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


if (a*b) < 0:
    child = max(a,b) - min(a,b)
else:
    child = abs(b-a)

mother = v-w
if mother <= 0:
    print('NO')
    exit()

n = child/mother
if n>0 and n<=t:
    print('YES')
else:
    print('NO')

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

if (a*b) >= 1:
    child = abs(b-a)
else:
    child = abs(a) + abs(b)

try:
    n = child/(v-w)
except ZeroDivisionError:
    n = -1
if n.is_integer() and n>=0 and n <= t:
    print("YES")
else:
    print("NO")
Problem p02678 (python)

Fixed submission:

roomNum, aisleNum = map(int, input().split())
aisles = [ list(map(int, input().split())) for _ in range(aisleNum) ]

aisleTree = [ [] for _ in range(roomNum+1) ]

for roomA, roomB in aisles:
    aisleTree[roomA].append(roomB)
    aisleTree[roomB].append(roomA)

from collections import deque
que = deque()
distanceFromRoom1 = [-1] * (roomNum+1)
distanceFromRoom1[0] = 0
distanceFromRoom1[1] = 0
for room in aisleTree[1]:
    que.append(room)
    distanceFromRoom1[room] = 1

while que:
    room = que.popleft()
    dist = distanceFromRoom1[room]
    for nextRoom in aisleTree[room]:
        if distanceFromRoom1[nextRoom] == -1:
            que.append(nextRoom)
            distanceFromRoom1[nextRoom] = room

if min(distanceFromRoom1) == -1:
    print('No')
else:
    print('Yes')
    for ans in distanceFromRoom1[2:]:
        print(ans)

Buggy submission (verdict: Runtime Error):

roomNum, aisleNum = map(int, input().split())
aisles = [ list(map(int, input().split())) for _ in range(aisleNum) ]

aisleTree = [ [] for _ in range(aisleNum+1) ]

for roomA, roomB in aisles:
    aisleTree[roomA].append(roomB)
    aisleTree[roomB].append(roomA)

from collections import deque
que = deque()
distanceFromRoom1 = [-1] * (roomNum+1)
distanceFromRoom1[0] = 0
distanceFromRoom1[1] = 0
for room in aisleTree[1]:
    que.append(room)
    distanceFromRoom1[room] = 1

while que:
    room = que.popleft()
    dist = distanceFromRoom1[room]
    for nextRoom in aisleTree[room]:
        if distanceFromRoom1[nextRoom] == -1:
            que.append(nextRoom)
            distanceFromRoom1[nextRoom] = room

if min(distanceFromRoom1) == -1:
    print('No')
else:
    print('Yes')
    for ans in distanceFromRoom1[2:]:
        print(ans)
Problem p02719 (python)

Fixed submission:
import math

n, k = map(int, input().split())

ansa = n % k
ansb = abs(ansa - k)

ans = min(ansa, ansb)

print(ans)

Buggy submission (verdict: Runtime Error):


n, k = map(int, input().split())

ans = n % abs(n-k)

ans = min(ans, n, k)

if ans == 1 and k == 1:
    print(0)
else:
    print(ans)