Harryxun/testdata huggingface dataset:
Buggy python 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])

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 python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
    exit()
          
n = 1
for i in range(N):
    n *= A[i]
    if n > 10**18:
        print(-1)
        exit()

print(n)


Fixed submission:
A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(A - (K - A - B))
Buggy python submission (verdict: Runtime Error):

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

for i in range(A, B+1):
    if i % K == 0:
        print('OK')
        exit()

print('NG')

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

for i in range(A, B+1):
    if i % K == 0:
        print('OK')
        exit()

print('NG')
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from itertools import product


K = int(input())
l = product(range(1, K+1), repeat=3)

ans = 0
for a, b, c in l:
    ans += gcd(gcd(a, b), c)

print(ans)



Fixed submission:
from math import gcd

K = int(input())

ans = 0
r = range(1, K+1)
for i in r:
    for j in r:
        for k in r:
            ans += gcd(gcd(i, j), k)

print(ans)
Buggy python 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")

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 python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]

c = Counter(S)

l = list(filter(lambda v: v[1] == c.most_common()[0][1], c.most_common()))
l.sort()

for s in l:
    print(s[0])

Fixed submission:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]

c = Counter(S).most_common()

l = list(filter(lambda v: v[1] == c[0][1], c))
l.sort()

a = l[0][1]
for s in l:
    if s[1] != a: break
    print(s[0])
Buggy python 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


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

print("Yes" if sum(a) >= h else "No")
Buggy python 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)

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 python submission (verdict: Runtime Error):
a, b = map(int, input())

print(a*b if 1 <= a <= 9 and 1 <= b <= 9 else '-1')

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

print(a*b if (1 <= a <= 9 and 1 <= b <= 9) else '-1')
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

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

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

print(max(a+b, a-b, a*b))
Buggy python 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')

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 python 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)]))


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 python 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")

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 python 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))


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 python 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))


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 python 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)

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 python 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)

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 python 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)

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 python 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)

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 python 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)

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 python 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)

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 python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
L, R = [], []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l), R.append(r)

ans = 0    
for i in range(N):
    if max(L) <= i+1 <= min(R):
        ans += 1
        
print(ans)

Fixed submission:
N, M = map(int, input().split())
L, R = [], []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l), R.append(r)

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

l, r = map(int, input().split())
a = set([i for i in range(l, r+1)])
for i in range(M-1):
    l, r = map(int, input().split())
    a = set(a) & set([i for i in range(l, r+1)])

ans = 0
for i in range(N+1):
    if i in a:
        ans += 1

print(ans)

Fixed submission:
N, M = map(int, input().split())
L, R = [], []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l), R.append(r)

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
L, R = [], []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l), R.append(r)

s = []
for i in range(M):
    s.append([i for i in range(L[i], R[i]+1)])

a = s[0]
for i in s:
    a = set(a) & set(i)

ans = 0
for i in range(N+1):
    if i in a:
        ans += 1

print(ans)

Fixed submission:
N, M = map(int, input().split())
L, R = [], []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l), R.append(r)

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
cnt = 0

for i in range(n+1):
    for j in range(n+1):
        a = n - r*i - g*j
        if a >= 0 and a % b == 0:
            cnt += 1

print(cnt)

Fixed submission:
r, g, b, n = map(int, input().split())
cnt = 0
 
for i in range(n+1):
    for j in range(n-i+1):
        a = n - r*i - g*j
        if a >= 0 and a % b == 0:
            cnt += 1
 
print(cnt)
Buggy python submission (verdict: Runtime Error):
raw = input()
s = bin(int(raw, 2))
n = len(raw)
m1 = bin(int("1010101010101"[:n],2))
m2 = bin(int("0101010101010"[:n],2))

if s == m1 or s == m2:
    print("0")
    exit(1)

a = bin((int(s,2))^int(m1,2)).count("1")
b = bin((int(s,2))^int(m2,2)).count("1")

print(a if a < b else b)

Fixed submission:
raw = input()
s = bin(int(raw, 2))
n = len(raw)
m = bin(int(''.join([str(i%2) for i in range(n)]),2))
 
a = bin((int(s,2))^int(m,2)).count("1")
b = n-a
 
print(a if a < b else b)
Buggy python 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]))

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 python submission (verdict: Runtime Error):
l = [abs(a-(t-i*0.006)) for i in h]
print(l.index(min(l))+1)

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 python submission (verdict: Runtime Error):
s = input()
k = int(input())

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

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 python submission (verdict: Runtime Error):
11 5 5

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 python 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))

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 python submission (verdict: Time Limit Exceeded):
n = int(input())
x = [int(i) for i in input().split()]

for i in range(n):
    print(sorted((x[:i] + x[i+1:]))[(n-1)//2])

Fixed submission:
n = int(input())
x = [int(i) for i in input().split()]

sorted_x = sorted(x)
smaller = sorted_x[n//2 - 1]
bigger = sorted_x[n//2]

for i in range(n):
    print(bigger if x[i] <= smaller else smaller)

Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median

n = int(input())
x = [int(i) for i in input().split()]

for i in range(n):
    print(median(x[:i] + x[i+1:]))

Fixed submission:
n = int(input())
x = [int(i) for i in input().split()]

sorted_x = sorted(x)
smaller = sorted_x[n//2 - 1]
bigger = sorted_x[n//2]

for i in range(n):
    print(bigger if x[i] <= smaller else smaller)
Buggy python 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:]))))


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 python 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)

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 python submission (verdict: Time Limit Exceeded):
k, s = [int(i) for i in input().split()]
print([a + b + c == s for a in range(k + 1) for b in range(k + 1) for c in range(k + 1)].count(True))

Fixed submission:
k, s = [int(i) for i in input().split()]
print([0 <= s-i-j <= k for i in range(k+1) for j in range(k+1)].count(True))

Buggy python submission (verdict: Time Limit Exceeded):
k, s = [int(i) for i in input().split()]

print([a + b + c == s for a in range(k + 1) for b in range(k + 1) for c in range(k + 1)].count(True))

Fixed submission:
k, s = [int(i) for i in input().split()]
print([0 <= s-i-j <= k for i in range(k+1) for j in range(k+1)].count(True))
Buggy python submission (verdict: Runtime Error):
a, b, h = [input() for _ in range(3)]
print(int((a + b) * h / 2))


Fixed submission:
a, b, h = [int(input()) for _ in range(3)]
print(int((a + b) * h / 2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(1, N+1)
    ans += i
print(ans)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i
print(ans)
Buggy python 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)


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 python submission (verdict: Time Limit Exceeded):
n, limit = list(map(int, input().split()))
permute = list(map(int, input().split()))
score = list(map(int, input().split()))

visited = [False] * n

ans = -10 ** 16

for i in range(n):
    if visited[i]:
        continue

    score_circle = []
    now = i
    while True:
        visited[now] = True
        score_circle.append(score[now])

        next_ = permute[now] - 1
        if visited[next_]:
            # 円環のできあがり
            break
        now = next_
    
    period = len(score_circle)

    score_circle *= 2
    # 累積和
    cumsum = [0] * (2 * period + 1)
    for j in range(1, 2*period+1):
        cumsum[j] = cumsum[j-1] + score_circle[j-1]
    
    p_sum_max = [-(10**15)] * (period + 1)
    for k in range(period):
        for ll in range(period):
            p_sum_max[ll] = max(p_sum_max[ll], cumsum[k+ll] - cumsum[k])
    
    ans = max([ans] + p_sum_max[1:min(period+1, limit+1)])

    q, resi = divmod(limit, period)

    if q >= 1:
        ans = max(ans, cumsum[period] * (q-1) + max(p_sum_max[1:]))
        ans = max(ans, cumsum[period] * (q) + max(p_sum_max[:resi + 1]))

        # print(p_sum_max[:resi + 1])

print(ans)


Fixed submission:
n, limit = list(map(int, input().split()))
permute = list(map(int, input().split()))
score = list(map(int, input().split()))

visited = [False] * n

ans = -10 ** 16

for i in range(n):
    if visited[i]:
        continue

    score_circle = []
    now = i
    while True:
        visited[now] = True
        score_circle.append(score[now])

        next_ = permute[now] - 1
        if visited[next_]:
            # 円環のできあがり
            break
        now = next_
    
    period = len(score_circle)

    score_circle *= 2
    # 累積和
    cumsum = [0] * (2 * period + 1)
    for j in range(1, 2*period+1):
        cumsum[j] = cumsum[j-1] + score_circle[j-1]
    
    p_sum_max = [-(10**15)] * (period + 1)
    for k in range(period):
        for ll in range(period):
            p_sum_max[ll] = max(p_sum_max[ll], cumsum[k+ll] - cumsum[k])
    
    ans = max([ans] + p_sum_max[1:min(period+1, limit+1)])

    q, resi = divmod(limit, period)

    if q >= 1:
        ans = max(ans, cumsum[period] * (q-1) + max(p_sum_max[1:]))
        ans = max(ans, cumsum[period] * (q) + max(p_sum_max[:resi + 1]))

        # print(p_sum_max[:resi + 1])

print(ans)
Buggy python 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


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 python 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)


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 python submission (verdict: Runtime Error):
n = int(input)
lis = [input() for i in range(n)]
print(len(set(lis)))


Fixed submission:
n = int(input())
lis = [input() for i in range(n)]
print(len(set(lis)))
Buggy python submission (verdict: Runtime Error):
s, t = input().split()
a, b = list(map(int, input, split()))
u = input()
if u == s:
    print("{} {}".format(a-1, b))
else:
    print("{} {}".format(a, b-1))


Fixed submission:
s, t = input().split()
a, b = list(map(int, input().split()))
u = input()
if u == s:
    print("{} {}".format(a-1, b))
else:
    print("{} {}".format(a, b-1))