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

Fixed submission:
a, b = map(int, input().split())
print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
def cnt(x):
	return sum(1 for i in range(1, x+1) if x%i == 0)
print(sum(1 for i in range(1, n+1, 2) if cnt(i) == 8))
Problem p04013 (python)

Fixed submission:

N, A = [int(_) for _ in input().split()]
x = sorted([int(_) for _ in input().split()])

dp = [[0] * (sum(x)+1) for j in range(N+1)]

dp[0][0] = 1
for i in range(1, N+1):
    for j in list(range(1, N+1))[::-1]:
        for k in list(range(x[i-1], sum(x[:i])+1))[::-1]:
            dp[j][k] += dp[j-1][k - x[i-1]]

print(sum([dp[i][i*A] for i in range(1, N+1) if i*A <= sum(x)]))

Buggy submission (verdict: Runtime Error):

N, A = [int(_) for _ in input().split()]
x = sorted([int(_) for _ in input().split()])

dp = [[0] * (sum(x)+1) for j in range(N+1)]

dp[0][0] = 1
for i in range(1, N+1):
    for j in list(range(1, N+1))[::-1]:
        for k in list(range(x[i-1], sum(x[:i])+1))[::-1]:
            dp[j][k] += dp[j-1][k - x[i-1]]

print(sum([dp[i][i*A] for i in range(1, N+1)]))
Problem p04014 (python)

Fixed submission:

import math

n = int(input())
s = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if n == s:
    print(n+1)
    exit()

for b in range(2, int(math.sqrt(n))+1):
    if f(b, n) == s:
        print(b)
        exit()

for p in list(range(1, min(int(math.sqrt(n))+1, s+1)))[::-1]:
    q = s - p
    b = (n - q) // p
    if b >= 2 and f(b, n) == s:
        print(b)
        exit()

print(-1)

Buggy submission (verdict: Runtime Error):

import math

n = int(input())
s = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if n == s:
    print(n+1)
    exit()

for b in range(2, int(math.sqrt(n))+1):
    if f(b, n) == s:
        print(b)
        exit()

for p in list(range(1, min(int(math.sqrt(n))+1, s+1)))[::-1]:
    q = s - p
    b = (n - q) // p
    if f(b, n) == s:
        print(b)
        exit()

print(-1)

Buggy submission (verdict: Runtime Error):

n = int(input())
s = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b


for b in range(int(math.sqrt(n))):
    if f(b, n) == s:
        print(b)
        exit()

for p in range(int(math.sqrt(n))):
    q = s - p
    b = (n - q) // p
    if f(b, n) == s:
        print(b)
        exit()
        
print(-1)
Problem p02612 (python)

Fixed submission:
def main():
    N = int(input())
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - (N % 1000))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    return N % 1000


if __name__ == "__main__":
    main()
Problem p02642 (python)

Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    D = [True] * (10**6 + 1)
    ans = 0

    for i, a in enumerate(A):
        if not D[a]:
            continue
        if (i < n-1 and a != A[i+1]) or i == n-1:
            ans += 1

        j = a
        while (j < 10**6 + 1):
            D[j] = False
            j += a

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    D = [True] * (2 * 10**5)
    ans = 0

    for i, a in enumerate(A):
        if not D[a]:
            continue
        if (i < n-1 and a != A[i+1]) or i == n-1:
            ans += 1

        j = a
        while (j < 2 * 10**5):
            D[j] = False
            j += a

    print(ans)


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

Fixed submission:
N = int(input())
restourants = dict()

for i in range(N):
    S, P = map(str,input().split())
    if S not in restourants:
        restourants[S] = {}
    restourants[S][int(P)] = i+1
for k, v in sorted(restourants.items()):
    v = sorted(v.items(),reverse=True)
    for i in v:
        print(i[1])

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

for i in range(N):
    S, P = map(str,input().split())
    if S not in restourants:
        restourants[S] = {}
    restourants[S][int(P)] = i+1
for k, v in sorted(restourants.items()):
    if len(v)>1:
        v = sorted(v.items(),reverse=True)
  
    
    for i in v:
        print(i[1])

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

for i in range(N):
    S, P = map(str,input().split())
    if S not in restourants:
        restourants[S] = {}
    restourants[S][int(P)] = i+1
for k, v in sorted(restourants.items()):
    if len(v)>1:
        v = sorted(v.items(),reverse=True)
    
    for i in v:
        print(i[1])
Problem p03035 (python)

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

if 13 <= A:
    print(B)
elif 6 <= A:
    print(B//2)
else:
    print(0)

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

for _ in range(M):
    B, C = map(int,input().split())
    A += [C]*B
    A.sort(reverse=True)
    A = A[:N]
print(sum(A))
Problem p03079 (python)

Fixed submission:
A,B,C = map(int,input().split())
if (A==B)and(B==C):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if (A==B)and(B==C):
  print"Yes"
else:
  print"No"
Problem p03085 (python)

Fixed submission:
i = input()
if i == 'A':
  print('T')
elif i == 'T':
  print('A')
elif i == 'C':
  print('G')
elif i == 'G':
  print('C')

Buggy submission (verdict: Runtime Error):
i = input()
if i == 'A':
  print('T')
else if i == 'T':
  print('A')
else if i == 'C':
  print('G')
else if i == 'G':
  print('C')

Buggy submission (verdict: Runtime Error):
def func():
	i = input()
	if i == 'A':
    	return 'T'
    else if i == 'T':
    	return 'A'
    else if i == 'C':
    	return 'G'
    else if i == 'G':
    	return 'C'

print(func())
Problem p03246 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a1 = {'emp':0}
a2 = {'emp':0}

for i in range(0,n,2):
    # print(i)
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1
# print(a1,a2)

a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])

# print(a1,a2)
if a1[0][0] == a2[0][0]:
    print(n-max(a1[0][1]+a2[1][1],a1[1][1]+a2[0][1]))
else :
    print(n-a1[0][1]-a2[0][1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a1 = {}
a2 = {}

for i in range(0,n//2+1,2):
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1

a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])

if a1[0][0] == a2[0][0]:
    print(n-max(a1[0][1]+a2[1][1],a1[1][1]+a2[0][1]))
else :
    print(n-a1[0][1]-a2[0][1])
Problem p02772 (python)

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

a = list(filter(lambda i: i%3 != 0 and i%5 != 0, filter(lambda i: i % 2 == 0, A)))
print("APPROVED" if len(a) == 0 else "DENIED")

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

a = list(filter(lambda i: i%3 != 0 and i%5 != 0 and i % 2 == 0, A)))
print("APPROVED" if len(a) == 0 else "DENIED")
Problem p02784 (python)

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

print("Yes" if sum(a) >= h else "No")

Buggy submission (verdict: Runtime Error):
C:\Users\Y\PycharmProjects\testProject\venv\Scripts\python.exe C:/Users/Y/PycharmProjects/testProject/main.py
210 5
31 41 59 26 53
Yes

Process finished with exit code 0
Problem p02802 (python)

Fixed submission:
n, m = map(int, input().split())
d = {}
for i in range(m):
    p, s = input().split()
    d.setdefault(p, [])
    d[p].append(s)

cnt = 0; correct = 0
for v in d.values():
    if "AC" not in v:
        continue
    correct += 1
    cnt += v.index("AC") 

print(correct, cnt)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
d = {}
for i in range(m):
    p, s = input().split()
    d.setdefault(p, [])
    d[p].append(s)

correct = 0
cnt = 0
for v in d.values():
    tmp = len(v[:v.index("AC")])
    if tmp > 0: correct += 1
    cnt += len(v[:v.index("AC")])

print(correct, cnt)
Problem p02945 (python)

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

print(max(a+b, a-b, a*b))

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

print(map(a+b, a-b, a*b))
Problem p02958 (python)

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

cnt = 0
for i in range(N):
    if P[i] != i + 1:
        cnt += 1

print('YES' if cnt == 0 or cnt == 2 else 'NO')

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

cnt = 0
for i in range(1, N+1):
    if P[i] != i:
        cnt += 1
        
print('YES' if cnt == 2 else 'NO')
Problem p02983 (python)

Fixed submission:
L, R = [int(i) for i in input().split()]
if R - L < 2019:
    print(min([(i * j) % 2019 for i in range(L, R) for j in range(L + 1, R + 1)]))
else:
    print(min([(i * j) % 2019 for i in range(L, L + 2019) for j in range(L, L + 2019)]))

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
R = min(R, L+2019)
print(min([i * j % 2019 for i in range(L, R+1) for jj in range(i+1, R+1)]))
Problem p02993 (python)

Fixed submission:
S = input()

s = [int(S[i])-int(S[i+1]) for i in range(len(S)-1)]

print("Good" if 0 not in s else "Bad")

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

s = [int(S[i])-int(S[i+1]) for i in range(S)]

print("Good" if 0 in s else "Bad")
Problem p02995 (python)

Fixed submission:
from math import floor
from fractions import gcd

def lcm(x: int, y: int) -> int:
    return (x * y) // gcd(x, y)

def calc(n: int, x: int, y: int) -> int:
    return n - n//x - n//y + n//lcm(x, y)


a, b, c, d = [int(i) for i in input().split()]
print(calc(b, c, d) - calc(a - 1, c, d))

Buggy submission (verdict: Runtime Error):
from math import gcd, floor

def lcm(x: int, y: int) -> int:
    return (x * y) // gcd(x, y)

def calc(n: int, x: int, y: int) -> int:
    return n - floor(n / x) - floor(n / y) + floor(n / lcm(x, y))


a, b, c, d = [int(i) for i in input().split()]
print(calc(b, c, d) - calc(a - 1, c, d))

Buggy submission (verdict: Runtime Error):
from math import gcd, floor

def lcm(x: int, y: int) -> int:
    return (x * y) // gcd(x, y)

def calc(n: int, x: int, y: int) -> int:
    return n - floor(n / x) - floor(n / y) + floor(n / lcm(x, y))


a, b, c, d = [int(i) for i in input().split()]
print(calc(b, c, d) - calc(a - 1, c, d))
Problem p03001 (python)

Fixed submission:
W, H, x, y = [int(i) for i in input().split()]
print(W*H / 2, int(x*2 == W and y*2 == H))

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

cnt = 0
for i in range(N):
    for j in range(N-i):
        s = sum(A[i:i+j+1])
        if s >= K:
            cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
 
print(double(W*H/2), 0 if x*2 == W and y*2 == H else 1)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
if (x == 0 and y == 0) or (x == W and y == H):
	print(0, 0)
	exit()

if (x == W and y == 0) or (x == W and y == H):
	print(W*H/2, 0)
	exit()

s1 = float(min(x*H, W*H-x*H))
s2 = float(min(y*W, W*H-y*W))
s3 = float(min((y/x*W * W * 0.5), H/((-1*(H-y)/x) + H) * H * 0.5))

b = 0
if s1 != s2 and s2 != s3 and s1 != s3:
	b = 0
else:
	b = 1
    
print(max(s1, s2, s3), b)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
if (x == 0 and y == 0) or (x == W and y == H):
	print(0, 0)
	exit()

if (x == H and y == H) or (x == W and y == W):
	print(W*H/2, 0)
	exit()


s1 = float(min(x*H, W*H-x*H))
s2 = float(min(y*W, W*H-y*W))
s3 = float(min((y/x*W * W * 0.5), H/((-1*(H-y)/x) + H) * H * 0.5))

b = 0
if s1 != s2 and s2 != s3 and s1 != s3:
	b = 0
else:
	b = 1
    
print(max(s1, s2, s3), b)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
if x == 0 and y == 0:
	print(0, 1)
	exit()

s1 = float(min(x*H, W*H-x*H))
s2 = float(min(y*W, W*H-y*W))
s3 = float(min((y/x*W * W * 0.5), H/((-1*(H-y)/x) + H) * H * 0.5))

b = 0
if s1 != s2 and s2 != s3 and s1 != s3:
	b = 0
else:
	b = 1
    
print(max(s1, s2, s3), b)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

s1 = float(min(x*H, W*H-x*H))
s2 = float(min(y*W, W*H-y*W))
s3 = float(min((y/x*W * W * 0.5), H/((-1*(H-y)/x) + H) * H * 0.5))

print(max(s1, s2, s3), 0 if s1 != s2 != s3 else 1)
Problem p03076 (python)

Fixed submission:
import math

a = list(map(int, [input() for i in range(5)]))
b = [math.ceil(b/10)*10 for b in a]

c1 = b[0] + b[1] + b[2] + b[3] + a[4]
c2 = b[0] + b[1] + b[2] + a[3] + b[4]
c3 = b[0] + b[1] + a[2] + b[3] + b[4]
c4 = b[0] + a[1] + b[2] + b[3] + b[4]
c5 = a[0] + b[1] + b[2] + b[3] + b[4]

print(min([c1,c2,c3,c4,c5]))

Buggy submission (verdict: Runtime Error):
a = list(map(int, [input() for i in range(5)]))
b = [math.ceil(b / 10) * 10 for b in a]

c1 = b[0] + b[1] + b[2] + b[3] + a[4]
c2 = b[0] + b[1] + b[2] + a[3] + b[4]
c3 = b[0] + b[1] + a[2] + b[3] + b[4]
c4 = b[0] + a[1] + b[2] + b[3] + b[4]
c5 = a[0] + b[1] + b[2] + b[3] + b[4]

print(min([c1, c2, c3, c4, c5]))
Problem p03220 (python)

Fixed submission:
n = int(input())
t, a = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

l = [abs(a-(t-i*0.006)) for i in h]
print(l.index(min(l))+1)

Buggy submission (verdict: Runtime Error):
l = [abs(a-(t-i*0.006)) for i in h]
print(l.index(min(l))+1)
Problem p03282 (python)

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

for i in range(len(s)):
    if s[i] != '1':
        print(s[i] if i+1 <= k else 1)
        exit()

print(1)

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

print(list(filter(lambda c: c != '1', list(s)))[0])
Problem p03292 (python)

Fixed submission:
a = [int(i) for i in input().split()]
a.sort()
print(sum([a[i+1]-a[i] for i in range(len(a)-1)]))

Buggy submission (verdict: Runtime Error):
11 5 5
Problem p03331 (python)

Fixed submission:
N = int(input())
s = [(i+1, N-i-1) for i in range((N-1) // 2 + 1)]
ss = [sum(list(map(int,list(str(v[0])[::1])))) + sum(list(map(int,list(str(v[1])[::1])))) for v in s]
print(min(ss))

Buggy submission (verdict: Runtime Error):
N = int(input())
s = [(i+1, N-i-1) for i in range((N-1) // 2)]
ss = [sum(list(map(int,list(str(v[0])[::1])))) + sum(list(map(int,list(str(v[1])[::1])))) for v in s]
print(min(ss))
Problem p03386 (python)

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

for i in range(A, min(A+K, B+1)):
    print(i)
for i in range(max(A+K, B-K+1), B+1):
    print(i)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
l = list(range(A, B + 1))
print('\n'.join(map(str, sorted(l[:K] + l[-K:]))))
Problem p03494 (python)

Fixed submission:
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

ans = 0; n = 2
while (a % n == 0).all():
    n *= 2
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

ans = 0; n = 2
while (a % n == 0).all():
    n *= 2
    ans += 1

print(ans)
Problem p03997 (python)

Fixed submission:
a, b, h = [int(input()) for _ in range(3)]
print(int((a + b) * h / 2))

Buggy submission (verdict: Runtime Error):
a, b, h = [input() for _ in range(3)]
print(int((a + b) * h / 2))
Problem p04029 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(1, N+1)
    ans += i
print(ans)
Problem p02574 (python)

Fixed submission:
# https://cs.stackexchange.com/questions/93030/algorithm-for-checking-if-a-list-of-integers-is-pairwise-coprime

import math
n = int(input())
nums = list(map(int, input().split()))

gcd_ = nums[0]
for num in nums[1:]:
    gcd_ = math.gcd(gcd_, num)

if gcd_ >= 2:
    print('not coprime')
    exit()



def smallest_divisor(num, start):
    if num == 1:
        raise ValueError("error!")
    d = start
    while d * d <= num:
        if num % d == 0:
            return d
        d += 1
    return num


prime_set = set()

for num in nums:
    if num == 1:
        continue

    soinsuu = set()
    
    warareru = num
    start = 2
    while True:
        divi = smallest_divisor(warareru, start)
        soinsuu.add(divi)
        warareru = warareru // divi
        start = divi
        if warareru == 1:
            break
    # print(soinsuu)
    if soinsuu & prime_set:
        print('setwise coprime')
        exit()
    else:
        prime_set |= soinsuu

print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
# https://cs.stackexchange.com/questions/93030/algorithm-for-checking-if-a-list-of-integers-is-pairwise-coprime

import math
n = int(input())
nums = list(map(int, input().split()))

gcd_ = nums[0]
for num in nums[1:]:
    gcd_ = math.gcd(gcd_, num)

if gcd_ >= 2:
    print('not coprime')
    exit()



def smallest_divisor(num):
    if num == 1:
        raise ValueError("error!")
    d = 2
    while d * d <= num:
        if num % d == 0:
            return d
        d += 1
    return num


prime_set = set()

for num in nums:
    soinsuu = set()
    
    warareru = num
    while True:
        divi = smallest_divisor(warareru)
        soinsuu.add(divi)
        warareru = warareru // divi
        if warareru == 1:
            break
    # print(soinsuu)
    if soinsuu & prime_set:
        print('setwise coprime')
        exit()
    else:
        prime_set |= soinsuu

print('pairwise coprime')
Problem p02582 (python)

Fixed submission:
s = input()
if 'RRR' in s:
    print(3)
elif 'RR' in s:
    print(2)
elif 'R' in s:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
# dp[r][c][p] := 位置r, cに到着し、該当行で拾ったアイテムがp個の時の、最大価値
# r = 0〜R, c = 0〜C, p = 0〜3

R, C, k = list(map(int, input().split()))
items = [list(map(int, input().split())) for _ in range(k)]

dp = [[[0 for _ in range(4)] for _ in range(C+1+1)] for _ in range(R+1+1)]  # 番兵

item_values = [[0 for _ in range(C+1+1)] for _ in range(R+1+1)]

for item in items:
    item_values[item[0]][item[1]] = item[2]

for r in range(1, R+1):
    for c in range(1, C+1):
        value_here = item_values[r][c]

        if value_here == 0:
            dp[r][c][0] = max(
                dp[r][c-1][0],
                max(dp[r-1][c])
            )
            dp[r][c][1] = dp[r][c-1][1]
            dp[r][c][2] = dp[r][c-1][2]
            dp[r][c][3] = dp[r][c-1][3]
        
        else:
            dp[r][c][0] = max(
                dp[r][c-1][0],
                max(dp[r-1][c])
            )
            dp[r][c][1] = max([
                dp[r][c-1][1],
                dp[r][c-1][0] + value_here,
                max(dp[r-1][c]) + value_here
            ])

            dp[r][c][2] = max(dp[r][c-1][2], dp[r][c-1][1] + value_here)
            dp[r][c][3] = max(dp[r][c-1][3], dp[r][c-1][2] + value_here)
            
print(max(dp[R][C]))

# print(dp)
Problem p02678 (python)

Fixed submission:
# 幅優先探索, BFS

from collections import deque

n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]

neighbor = [[] for _ in range(n)]
for edge in edges:
    neighbor[edge[0]-1].append(edge[1]-1)  # 1- → 0-index
    neighbor[edge[1]-1].append(edge[0]-1)

queue = deque()
queue.append(0)

back = [-1] * n  # visitしたかどうかを兼ねる
back[0] = 0
while len(queue) > 0:
    vertex = queue.popleft()
    for nei in neighbor[vertex]:
        if back[nei] == -1:
            back[nei] = vertex
            queue.append(nei)
        
print('Yes')
for i in back[1:]:
    print(i+1)  # 0- → 1-index

Buggy submission (verdict: Runtime Error):
# 幅優先探索, BFS

from collections import deque

n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]

neighbor = [[] for _ in range(m)]
for edge in edges:
    neighbor[edge[0]-1].append(edge[1]-1)  # 1- → 0-index
    neighbor[edge[1]-1].append(edge[0]-1)

queue = deque()
queue.append(0)

back = [-1] * n  # visitしたかどうかを兼ねる
back[0] = 0
while len(queue) > 0:
    vertex = queue.popleft()
    for nei in neighbor[vertex]:
        if back[nei] == -1:
            back[nei] = vertex
            queue.append(nei)
        
print('Yes')
for i in back[1:]:
    print(i+1)  # 0- → 1-index
Problem p02684 (python)

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

visited_city = {1: 0}
visited_city_inv = {0: 1}

now = 1
num = 0
while True:
    next_city = arr[now - 1]
    num += 1
    if next_city not in visited_city:
        visited_city[next_city] = num
        visited_city_inv[num] = next_city
        now = next_city
    else:
        break

if k < num:
    ans = visited_city_inv[k]
else:
    x = visited_city[next_city]
    period = num - x
    ans = visited_city_inv[x + (k - x) % period]

print(ans)
# print(visited_city)

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

visited_city = {1: 0}
visited_city_inv = {0: 1}

now = 1
num = 0
while True:
    next_city = arr[now - 1]
    num += 1
    if next_city not in visited_city:
        visited_city[next_city] = num
        visited_city_inv[num] = next_city
        now = next_city
    else:
        break

if k < num:
    ans = visited_city[k]
else:
    x = visited_city[next_city]
    period = num - x
    ans = visited_city_inv[x + (k - x) % period]

print(ans)
# print(visited_city)
Problem p02768 (python)

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

mod = 10**9 + 7

import time
start = time.time()


# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
	if a == 0:
		return 1
	elif a == 1:
		return x
	elif a % 2 == 0:
		return power(x, a//2) **2 % mod
	else:
		return power(x, a//2) **2 * x % mod

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
	return pow(x, mod-2, mod)

modinv_table = [-1] * (b+1)
for i in range(1, b+1):
    modinv_table[i] = modinv(i)

end = time.time()
# print("time: ", end - start)

def binomial_coefficients2(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

# (2 ** n - 1) - nCa - nCb
ans = power(2, n) - 1

ans -= (binomial_coefficients2(n, a) + binomial_coefficients2(n, b))
print(ans % mod)


# print(binomial_coefficients2 (5, 2) % mod)

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

mod = 10**9 + 7

import time
start = time.time()

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
	return pow(x, mod-2, mod)

modinv_table = [-1] * (b+1)
for i in range(1, b+1):
    modinv_table[i] = modinv(i)

end = time.time()
# print("time: ", end - start)

def binomial_coefficients2(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

# (2 ** n - 1) - nCa - nCb
ans = power(2, n) - 1

ans -= (binomial_coefficients2(n, a) + binomial_coefficients2(n, b))
print(ans % mod)


# print(binomial_coefficients2 (5, 2) % mod)
Problem p02921 (python)

Fixed submission:
a = input()
b = input()
print(sum(a[i] == b[i] for i in range(3)))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
print(sum(a[i] == b[i] for i in range[3]))