Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
li = list(map(int,input().split()))

L = [0] * 10**6

import math
from functools import reduce

if reduce(math.gcd,li)!=1:
    print('not coprime')
    exit()

if 1 in li:
    print('setwise coprime')
    exit()

for i in li:
    L[i] = 1

for k in range(2,10**6//2+1):
    t = 0
    for j in range(0,10**6,k):
        t += L[j]
    if t > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')

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

S = max(li)
L = [0] * (S+1)

import math
from functools import reduce

if reduce(math.gcd,li) != 1:
    print('not coprime')
    exit()

for i in li:
    L[i] = 1

for k in range(2,S+1):
    t = 0
    for j in range(0,S+1,k):
        t += L[j]
    if t > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')

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

L = [0] * 10**6

import math
from functools import reduce

if reduce(math.gcd,li)!=1:
    print('not coprime')
    exit()

for i in li:
    L[i] = 1
#print(L)

for k in range(2,10**6//2+1):
    t = 0
    for j in range(0,10**6,k):
        t += L[j]
    if t > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')

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

S = max(li)
L = [0] * (S+1)

import math
from functools import reduce

if reduce(math.gcd,li) != 1:
    print('not coprime')
    exit()

for i in li:
    L[i] = 1

for k in range(2,S+1):
    t = 0
    for j in range(0,S+1,k):
        t += L[j]
    if t > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')
Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'RRR':print(3)
if S = 'RRS':print(2)
if S = 'RSR':print(1)
if S = 'RSS':print(1)
if S = 'SRR':print(2)
if S = 'SRS':print(1)
if S = 'SSR':print(1)
if S = 'SSS':print(0)

Fixed submission:
S = input()
if S == 'SSS':print(0)
if S == 'SSR':print(1)
if S == 'SRS':print(1)
if S == 'RSS':print(1)
if S == 'SRR':print(2)
if S == 'RRS':print(2)
if S == 'RSR':print(1)
if S == 'RRR':print(3)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = -1*float('inf')

for i in range(N):
    k = i
    Cc = []
    Ct = 0
    while 1:
        k = P[k]-1
        Cc.append(C[k])
        if i == k:
            break
    l = len(Cc)
    Ct = sum(Cc)
    t = 0
    for j in range(l):
        t += Cc[j]
        if j >= K:break
        now = t
        if Ct > 0:
            e = (K-j-1)//l
            now +=  Ct*e
        ans = max(ans,now)
print(ans)

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

ans = -1*float('inf')

for i in range(N):
    k = i
    Cc = []
    Ct = 0
    while 1:
        k = P[k]-1
        Cc.append(C[k])
        if i == k:
            break
    l = len(Cc)
    Ct = sum(Cc)
    t = 0
    for j in range(l):
        t += Cc[j]
        if j >= K:break
        now = t
        if Ct > 0:
            e = (K-j-1)//l
            now +=  Ct*e
        ans = max(ans,now)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

K = int(input())

for i in [2,5]:
    if K%i==0:
        print(-1)
        exit()

def f(i,t,K):
    t2 = (t*10+7)%K
    if t2==0:
        print(i)
        exit()
    else:f(i+1,t2,K)
f(1,0,K)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)

K = int(input())

for i in [2,5]:
    if K%i==0:
        print(-1)
        exit()
t = 0
for i in range(K):
    t = (t*10+7)%K
    if t == 0:
        print(i+1)
        exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N%1000 != 0:
	maisu = N//1000 + 1
else:
  maisu = N//1000
print(maisu*1000-k)

Fixed submission:
N = int(input())
if N%1000 != 0:
	maisu = N//1000 + 1
else:
  maisu = N//1000
print(maisu*1000-N)
Buggy python submission (verdict: Runtime Error):
import copy
H,W,K = list(map(int,input().rstrip().split(' ')))
MASU = [list(input()) for _ in range(H)]
H2_li = []
W2_li = []
C_black = 0
for i in range(2**H):
    H2 = []
    for j in range(H):
        if ((i>>j)&1):H2.append(1)
        else:H2.append(0)
    H2_li.append(H2)
for i in range(2**W):
    W2 = []
    for j in range(W):
        if ((i>>j)&1):W2.append(1)
        else:W2.append(0)
    W2_li.append(W2)

for h2 in H2_li:
    for w2 in W2_li:
        masu = copy.deepcopy(MASU)
        for i,h in enumerate(h2):
            if h == 1:
                masu[i] = ['r']*H
        for i,w in enumerate(w2):
            if w == 1:
                for k in range(H):
                    masu[k][i] = 'r'
        count = 0
        for h in range(H):
            for w in range(W):
                if masu[h][w]=='#':count+=1
        if count == K:C_black+=1

print(C_black)

Fixed submission:
import copy
H,W,K = list(map(int,input().rstrip().split(' ')))
MASU = [list(input()) for _ in range(H)]
H2_li = []
W2_li = []
C_black = 0
for i in range(2**H):
    H2 = []
    for j in range(H):
        if ((i>>j)&1):H2.append(1)
        else:H2.append(0)
    H2_li.append(H2)
for i in range(2**W):
    W2 = []
    for j in range(W):
        if ((i>>j)&1):W2.append(1)
        else:W2.append(0)
    W2_li.append(W2)

for h2 in H2_li:
    for w2 in W2_li:
        masu = copy.deepcopy(MASU)
        for i,h in enumerate(h2):
            if h == 1:
                masu[i] = ['r']*W
        for i,w in enumerate(w2):
            if w == 1:
                for k in range(H):
                    masu[k][i] = 'r'
        count = 0
        for h in range(H):
            for w in range(W):
                if masu[h][w]=='#':count+=1
        if count == K:C_black+=1

print(C_black)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]
g = [[] for _ in range(n)]
l = [0 for _ in range(n)]
seen = [0 for _ in range(n)]

for x,y in li:
    x -= 1
    y -= 1
    g[x].append(y)
    g[y].append(x)

def bfs():
    que = deque([])
    l[0] = 0
    seen[0] = 1
    for i in g[0]: 
        que.append((i,0))
    while que:
        a,b = que.popleft()
        seen[a] = 1
        if not l[a]:l[a] = b+1
        for i in g[a]:
            if i != b and not l[i]:
                
                que.append((i,a))

bfs()
if all(seen):
    print('Yes')
    for i in l[1:]:
        print(i)
else:
    print('No')

Fixed submission:
from collections import deque
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]
g = [[] for _ in range(n)]
l = [float('inf')] * n

for x,y in li:
    x -= 1
    y -= 1
    g[x].append(y)
    g[y].append(x)

def bfs():
    que = deque()
    l[0] = 0
    que.append(0)
    while que:
        a = que.popleft()
        for i in g[a]:
            if l[i] != float('inf'):continue
            l[i] = a
            que.append(i)
bfs()
for i in l:
    if i == float('inf'):
        print('No')
        exit()
print('Yes')
for i in l[1:]:
    print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
li = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

li.sort()
bc.sort(key=lambda x:x[1],reverse=True)
l = []
l_len = 0
for b,c in bc:
    l += [c]*b
    l_len += b
    
ans = 0
for i in range(n):
    if i>=l_len:ans += li[i]
    else:ans += max(li[i],l[i])
print(ans)

Fixed submission:
n,m = map(int,input().split())
li = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

bc.sort(key=lambda x:x[1],reverse=True)
l = []
ans = 0

for b,c in bc:
    l += [c]*b
    if len(l) > n:
        break
    
li += l
li.sort(reverse=True)
print(sum(li[:n]))
Buggy python submission (verdict: Time Limit Exceeded):
n,W = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(n)]

dp = [[0]*(W+1) for _ in range(n+1)]

for i in range(n):
    w = li[i][0]
    v = li[i][1]
    for k in range(W+1):
        if  w>k:
            dp[i+1][k] = dp[i][k]
            continue
        dp[i+1][k] = max(dp[i][k-w]+v,dp[i][k])
print(dp[n][W])

Fixed submission:
n,W = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(n)]

dp = [[0]*(W+1) for _ in range(n+1)]

for i in range(n):
    w = li[i][0]
    v = li[i][1]
    for k in range(W+1):
        if  w>k:
            dp[i+1][k] = dp[i][k]
            continue
        dp[i+1][k] = max(dp[i][k-w]+v,dp[i][k])
print(dp[n][W])
Buggy python submission (verdict: Runtime Error):
s,t = input(),input()

S = len(s)
T = len(t)

dp = [[0]*(T+1) for _ in range(S+1)]

for i in range(S):
    for j in range(T):
        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+(s[i]==t[j]))
    

ans = ''

while S > 0 and T > 0:
    if dp[S][T] == dp[S-1][T]: S -= 1
    elif dp[S][T] == dp[S][T-1]: T -= 1
    else: 
        S -= 1
        T -= 1
        ans = s[S] + ans
print(ans)

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

S = len(s)
T = len(t)

dp = [[0]*(T+1) for _ in range(S+1)]

for i in range(S):
    for j in range(T):
        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+(s[i]==t[j]))
    

ans = ''

while S > 0 and T > 0:
    if dp[S][T] == dp[S-1][T]: S -= 1
    elif dp[S][T] == dp[S][T-1]: T -= 1
    else: 
        S -= 1
        T -= 1
        ans = s[S] + ans
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s,t = input(),input()

S = len(s)
T = len(t)

dp = [[0]*(T+1) for _ in range(S+1)]

for i in range(S):
    for j in range(T):
        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+(s[i]==t[j]))
    

ans = ''

while S > 0 and T > 0:
    if dp[S][T] == dp[S-1][T]: S -= 1
    elif dp[S][T] == dp[S][T-1]: T -= 1
    else: 
        S -= 1
        T -= 1
        ans = s[S] + ans
print(ans)

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

S = len(s)
T = len(t)

dp = [[0]*(T+1) for _ in range(S+1)]

for i in range(S):
    for j in range(T):
        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+(s[i]==t[j]))
    

ans = ''

while S > 0 and T > 0:
    if dp[S][T] == dp[S-1][T]: S -= 1
    elif dp[S][T] == dp[S][T-1]: T -= 1
    else: 
        S -= 1
        T -= 1
        ans = s[S] + ans
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

mi = 10000000
for i in range(N):
    f1 = S[0:i]
    f2 = S[i+1:]
    K = f1.count('W')+f2.count('E')
    if K <= mi:mi=K
print(mi)

Fixed submission:
N = int(input())
S = list(input())
E = S[1:].count('E')
W = 0
mi = E+W
for i in range(1,N):
    if S[i] == 'E':E -= 1
    if S[i-1] == 'W':W+=1
    if E+W <= mi:mi = E+W
print(mi)
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
l = []
bo = 0
for a in range(N+1):
    for b in range(N-a+1):
        if a*10000 + b*5000 + (N-a-b)*1000 == X:
            T = [a,b,N-a-b]
            bo+=1
            break

print(*T,sep=' ')
if bo==0:
    print('-1 -1 -1')


Fixed submission:
N,X = map(int,input().split())
l = []
bo = 0
for a in range(N+1):
    for b in range(N-a+1):
        if a*10000 + b*5000 + (N-a-b)*1000 == X:
            T = [a,b,N-a-b]
            bo+=1
            break


if bo==0:
    print('-1 -1 -1')
else:print(*T,sep=' ')
Buggy python submission (verdict: Runtime Error):
N = int(input())
def amari(n):
    if n==1:return 1
    return (n*amari(n-1)) % 1000000007
print(amari(N))

Fixed submission:
mod = 10**9+7

N = int(input())
a = 1
for n in range(N):
    a = a*(n+1)%mod
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
 
import re
 
li = ['dream','dreamer','erase','eraser']
 
 
while len(list(S)) > 8: 
    if S[0] == 'd':
        if S[0:5] == 'dream':
            if S[5:10] == 'erase':
                S = S[5:]
            elif S[5:10] == 'dream':
                S = S[5:]
            elif S[5:7] == 'er':
                if S[7:12] == 'dream':
                    S = S[7:]
                elif S[7:12] == 'erase':
                    S = S[7:]
            else:break
 
    else:
        if S[0:6] == 'eraser':
            S = S[6:]
        elif S[0:5] == 'erase':
            if S[5:10] == 'erase':
                S = S[5:]
            elif S[5:10] == 'dream':
                S = S[5:]
        else:break
k = 0 
for l in li:
    if S == l:k = 1
if k == 0:print('NO')
else:print('YES')

Fixed submission:
S = input()
li = ['dream','dreamer','erase','eraser']
li_len=[5,7,5,6]

while S:
    for i,moji in enumerate(li):
        if S[-li_len[i]:] == moji:
            S = S[:-li_len[i]]
            break
    else:
        print('NO')
        break
if not S:print('YES')

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

import re

li = ['dream','dreamer','erase','eraser']


while len(list(S)) > 8: 
    if S[0] == 'd':
        if S[0:5] == 'dream':
            if S[5:10] == 'erase':
                S = S[5:]
                print(S)
            elif S[5:10] == 'dream':
                S = S[5:]
                print(S)
            elif S[5:7] == 'er':
                if S[7:12] == 'dream':
                    S = S[7:]
                    print(S)
                elif S[7:12] == 'erase':
                    S = S[7:]
                    print(S)
            else:break

    else:
        if S[0:6] == 'eraser':
            S = S[6:]
            print(S)
        elif S[0:5] == 'erase':
            if S[5:10] == 'erase':
                S = S[5:]
                print(S)
            elif S[5:10] == 'dream':
                S = S[5:]
                print(S)
        else:break
k = 0 
for l in li:
    if S == l:k = 1
if k == 0:print('No')
else:print('Yes')

Fixed submission:
S = input()
li = ['dream','dreamer','erase','eraser']
li_len=[5,7,5,6]

while S:
    for i,moji in enumerate(li):
        if S[-li_len[i]:] == moji:
            S = S[:-li_len[i]]
            break
    else:
        print('NO')
        break
if not S:print('YES')
Buggy python submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

c = [0 for _ in range(h)]
r = [0 for _ in range(w)]
bakuset = {}
for i, j in hw:
    # print(i, j)
    c[i-1] += 1
    r[j-1] += 1
    if not str(i-1) + "+" + str(j-1) in bakuset:
        bakuset[str(i-1) + "+" + str(j-1)] = 0
    # print(bakuset, i-1, j-1)
    bakuset[str(i-1) + "+" + str(j-1)] += 1

ans = max(c) + max(r)

mc = max(c)
mr = max(r)
cc = []
rr = []

for i in range(h):
    if c[i] == mc:
        cc.append(i)

for i in range(h):
    if r[i] == mr:
        rr.append(i)

flag = 10**10

for i in cc:
    for j in rr:
        if not str(i) + "+" + str(j) in bakuset:
            flag = 0
            break
        flag = min(flag, bakuset[str(i) + "+" + str(j)])
    if not flag:
        break

if flag:
    ans -= 1

print(ans)

Fixed submission:
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

c = [0 for _ in range(h)]
r = [0 for _ in range(w)]
bakuset = {}
for i, j in hw:
    # print(i, j)
    c[i-1] += 1
    r[j-1] += 1
    if not str(i-1) + "+" + str(j-1) in bakuset:
        bakuset[str(i-1) + "+" + str(j-1)] = 0
    # print(bakuset, i-1, j-1)
    bakuset[str(i-1) + "+" + str(j-1)] += 1

ans = max(c) + max(r)

mc = max(c)
mr = max(r)
cc = []
rr = []

for i in range(h):
    if c[i] == mc:
        cc.append(i)

for i in range(w):
    if r[i] == mr:
        rr.append(i)

flag = 10**10

for i in cc:
    for j in rr:
        if not str(i) + "+" + str(j) in bakuset:
            flag = 0
            break
        flag = min(flag, bakuset[str(i) + "+" + str(j)])
    if not flag:
        break

if flag:
    ans -= flag

print(ans)
Buggy python submission (verdict: Runtime Error):
def possible(x):
    global k
    cnt = 0
    for i in a:
        if i % x == 0:
            cnt += i // x - 1
        else:
            cnt += i // x

    if cnt <= k:
        return True
    return False

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

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

mini = 0
maxi = max(a)

while mini <= maxi:
    mid = (mini + maxi) // 2
    res = possible(mid)
    if res:
        maxi = mid
    else:
        mini = mid
    # print(mini, mid, maxi)

    if mini+1 == maxi:
        if possible(maxi):
            ans = maxi
        else:
            ans = mini
        break

print(ans)
# print(possible(4))



Fixed submission:
def possible(x):
    global k
    cnt = 0
    for i in a:
        if i % x == 0:
            cnt += i // x - 1
        else:
            cnt += i // x

    if cnt <= k:
        return True
    return False

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

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

mini = 1
maxi = max(a)

while mini <= maxi:
    mid = (mini + maxi) // 2
    res = possible(mid)
    if res:
        maxi = mid
    else:
        mini = mid
    # print(mini, mid, maxi)

    if mini+1 >= maxi:
        if maxi < mini:
            mini, maxi = maxi, mini
        if possible(mini):
            ans = mini
        else:
            ans = maxi
        break

print(ans)
# print(possible(4))
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
i = 0
j = 0
while k >= 0:
    if i >= len(a) and j >= len(b):
        break

    if i >= len(a):
        if k >= b[i]:
            k -= b[i]
            j += 1
            cnt += 1
        else:
            break
        continue
    if j >= len(b):
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
        continue

    if a[i] >= b[j]:
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
    else:
        if k >= b[i]:
            k -= b[i]
            j += 1
            cnt += 1
        else:
            break

print(cnt)

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

ans = 0
ia = -1
ib = -1

nowtime = 0
cnt = 0
for i in range(n):
    if nowtime + a[i] <= k:
        nowtime += a[i]
        cnt += 1
        ia = i
    else:
        break

ans = cnt
# print(ans, nowtime)
for i in range(m):
    while nowtime + b[i] > k and ia >= 0:
        nowtime -= a[ia]
        cnt -= 1
        ia -= 1
    if nowtime + b[i] > k:
        break
    nowtime += b[i]
    cnt += 1
    ans = max(ans, cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

a_dic = {}
for i in a:
    if not i in a_dic:
        a_dic[i] = 0
    a_dic[i] += 1
res = 0
for i in a:
    j = 1
    flag = 1
    while j * j <= i:
        if i % j == 0:
            x = j
            if (x == i and a_dic[x] >= 2) or (x != i and x in a_dic and a_dic[x] >= 1):
                flag = 0
                break
            x = i//x
            if (x == i and a_dic[x] >= 2) or (x != i and x in a_dic and a_dic[x] >= 1):
                flag = 0
                break

        j += 1
    # print(flag)
    if flag:
        res += 1

# print(a_dic)
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
bai = [0 for _ in range(max(a)+1)]
i = 2
for i in a:
    j = i
    while j < len(bai):
        bai[j] += 1
        j += i

res = 0
if n <= 1:
    print(n)
    exit()

for i in range(n):
    if i == 0:
        if a[i] != a[i+1] and bai[a[i]] == 1:
            res += 1
    elif i == n-1:
        if a[i] != a[i-1] and bai[a[i]] == 1:
            res += 1
    else:
        if a[i] != a[i-1] and a[i] != a[i+1] and bai[a[i]] == 1:
            res += 1

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
while True:
    cnt += 1
    new = [0 for _ in range(n)]
    for i in range(n):
        # for j in range(n):
        #     if abs(i-j) < arr[j]:
        #         # print(arr[i], arr[j], i, j)
        #         new[i] += 1
        new[max(0, i-arr[i])] += 1

        tmp = i+arr[i]+1
        # print(max(0, i-arr[i]), tmp, i)
        if tmp < n:
            new[tmp] -= 1

    for i in range(1, n):
        new[i] += new[i-1]
    # print(new)
    arr = new
    # print(arr)
    if min(arr) >= n or cnt >= k:
        # print(min(arr), cnt)
        break

for i in arr:
    print(i, end=" ")

Fixed submission:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
# n = int(input())
# arr = [0 for _ in range(n)]
while True:
    cnt += 1
    new = [0 for _ in range(n)]
    for i in range(n):
        new[max(0, i-arr[i])] += 1

        tmp = i+arr[i]+1
        if tmp < n:
            new[tmp] -= 1

    flag = 1
    for i in range(1, n):
        new[i] += new[i-1]
        if new[i] < n:
            flag = 0

    arr = new
    # print(arr)
    if flag or cnt >= k:
        break
# print(cnt)
for i in arr:
    print(i, end=" ")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
graf = [[] for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    graf[a-1].append(b-1)
    graf[b-1].append(a-1)

out = [0 for _ in range(n)]
out[0] = -1
import queue
next_visit = queue.Queue()
next_visit.put(0)
while not next_visit.empty():
    i = next_visit.get()
    for j in graf[i]:
        if out[j] == 0:
            out[j] = i+1
            next_visit.put(j)
cnt = 1
for i in range(1, n):
    if out[i] == 0:
        cnt = 0
        break
if cnt:
    print("Yes")
    for i in out[1:]:
        print(i)
else:
    print("No")

Fixed submission:
n, m = map(int, input().split())
graf = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    graf[a-1].append(b-1)
    graf[b-1].append(a-1)

out = [0 for _ in range(n)]
out[0] = -1

import queue

next_visit = queue.Queue()
next_visit.put(0)

while not next_visit.empty():
    i = next_visit.get()
    for j in graf[i]:
        if out[j] == 0:
            out[j] = i+1
            next_visit.put(j)
cnt = 1

for i in range(1, n):
    if out[i] == 0:
        cnt = 0
        break
if cnt:
    print("Yes")
    for i in out[1:]:
        print(i)
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
ncm_list = [0 for _ in range(k)]
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ncm %= mod
    ncm_list[i] = ncm

powm_list = [0 for _ in range(k)]
tmp = m * pow(m-1, n-k-1, mod)
powm_list[k-1] = tmp
for i in range(k-2, -1, -1):
    tmp *= (m-1)
    tmp %= mod
    powm_list[i] = tmp

for i in range(k):
    ans += ncm_list[i] * powm_list[i]
    ans %= mod

print(ans)

Fixed submission:
n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
ncm_list = [0 for _ in range(k)]
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ncm %= mod
    ncm_list[i] = ncm

powm_list = [0 for _ in range(k)]
tmp = m * pow(m-1, n-k-1, mod)
if k != 0:
    powm_list[k-1] = tmp
    for i in range(k-2, -1, -1):
        tmp *= (m-1)
        tmp %= mod
        powm_list[i] = tmp

for i in range(k):
    ans += ncm_list[i] * powm_list[i]
    ans %= mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ans += m * pow(m-1, n-i-2, mod) * ncm
    ans %= mod
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
ncm_list = [0 for _ in range(k)]
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ncm %= mod
    ncm_list[i] = ncm

powm_list = [0 for _ in range(k)]
tmp = m * pow(m-1, n-k-1, mod)
if k != 0:
    powm_list[k-1] = tmp
    for i in range(k-2, -1, -1):
        tmp *= (m-1)
        tmp %= mod
        powm_list[i] = tmp

for i in range(k):
    ans += ncm_list[i] * powm_list[i]
    ans %= mod

print(ans)