Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

#c = collections.Counter(A)
#print(c)

for i in range(Q):
  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(sum(A))

Fixed submission:
import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

D = collections.Counter(A)
s=sum(A)
for i in range(Q):
  s=s-B[i]*D[B[i]]
  D[C[i]]+=D[B[i]]
  s=s+C[i]*D[B[i]]
  D[B[i]]=0
#  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

#c = collections.Counter(A)
#print(c)

for i in range(Q):
  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(sum(A))
#l_replace = [100 if i > 0 else i for i in l]  
#
#  print(C[i]-1,B[i]-1)
##  D[B[i]-1]=0
#  print(int(np.average(D, weights=W)))
  

Fixed submission:
import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

D = collections.Counter(A)
s=sum(A)
for i in range(Q):
  s=s-B[i]*D[B[i]]
  D[C[i]]+=D[B[i]]
  s=s+C[i]*D[B[i]]
  D[B[i]]=0
#  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())
#print(A)

S=[[0 for i in range(N)] for j in range(Q+1)]


for i in range(Q):
  for j in range(N):
    S[i][j]=A[j]
    if B[i]==A[j]:
      A[j]=C[i]
S[Q]=A
for i in range(1,Q+1):
  print(sum(S[i]))

Fixed submission:
import collections
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())

D = collections.Counter(A)
s=sum(A)
for i in range(Q):
  s=s-B[i]*D[B[i]]
  D[C[i]]+=D[B[i]]
  s=s+C[i]*D[B[i]]
  D[B[i]]=0
#  A = [C[i] if B[i]==A[j] else A[j] for j in range(N)]
#  print(A)
  print(s)
Buggy python submission (verdict: Runtime Error):
7
nikoandsolstice

Fixed submission:
K=int(input())
S=input()
if len(S)<=K:print(S)
else:print(S[0:K]+'...')
Buggy python submission (verdict: Runtime Error):
4 3
1 2 3 4
1 3
2 3
2 4

Fixed submission:
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[0]*M;B=[0]*M
C=[0]*N
for i in range(M):
  A[i],B[i]=map(int,input().split())

for i in range(M):
  if H[A[i]-1]<H[B[i]-1]:C[A[i]-1]+=1
  elif H[A[i]-1]>H[B[i]-1]:C[B[i]-1]+=1
  else:C[A[i]-1]+=1;C[B[i]-1]+=1
print(C.count(0))
Buggy python submission (verdict: Time Limit Exceeded):
X=int(input())

for a in range(10**5):
  for b in range(10**5):
    if a**5-b**5==X:print(a,b);exit()
    elif a**5+b**5==X:print(a,-b);exit()

Fixed submission:
X=int(input())

for a in range(10**4):
  for b in range(10**4):
    if a**5-b**5==X:print(a,b);exit()
    elif a**5+b**5==X:print(a,-b);exit()
Buggy python submission (verdict: Runtime Error):
A,B,N=map(int,input().split())
#print(math.floor(A/B))
c=[0]*N
for i in range(1,N+1):
  c[i-1]=(A*i)//B-A*(i//B)

print(max(c))

Fixed submission:
A,B,N=map(int,input().split())
if B==1:print(0);exit()
if N<=B:
  print(max((A*(N-1))//B-A*((N-1)//B),(A*N)//B-A*(N//B)))
else:print(A-1)
Buggy python submission (verdict: Runtime Error):
100 2

Fixed submission:
S,W=map(int,input().split())
if S<=W:print('unsafe')
else:print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
s=int(S)

c=[0]*(len(S)+1)
c[0]=0
for i in range(len(S)):
  c[i+1]=(c[i]+int(S[-1-i])*10**i)%2019

#print(c)  
d=[0]*2019
m=0
for i in range(2019):
  d[i]=c.count(i)
  m+=d[i]*(d[i]-1)//2
#print(d)
print(m)

Fixed submission:
S=input()
s=int(S)
mod=2019
c=[0]*(len(S)+1)
d=[0]*2019


c[0]=0
d[0]=1
for i in range(len(S)):
  c[i+1]=(c[i]+int(S[-i-1])*pow(10,i,mod))%mod
  d[c[i+1]]+=1
  
m=0
for i in range(2019):
  m+=d[i]*(d[i]-1)//2

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
s=int(S)
c=0
for i in range(1,s//2019+1):
  C=str(2019*i)
  if '0' in C:
    continue
  if C in S:
    c+=1
print(c)


exit()




c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))


Fixed submission:
S=input()
s=int(S)
mod=2019
c=[0]*(len(S)+1)
d=[0]*2019


c[0]=0
d[0]=1
for i in range(len(S)):
  c[i+1]=(c[i]+int(S[-i-1])*pow(10,i,mod))%mod
  d[c[i+1]]+=1
  
m=0
for i in range(2019):
  m+=d[i]*(d[i]-1)//2

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))


Fixed submission:
S=input()
s=int(S)
mod=2019
c=[0]*(len(S)+1)
d=[0]*2019


c[0]=0
d[0]=1
for i in range(len(S)):
  c[i+1]=(c[i]+int(S[-i-1])*pow(10,i,mod))%mod
  d[c[i+1]]+=1
  
m=0
for i in range(2019):
  m+=d[i]*(d[i]-1)//2

print(m)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))

D = collections.Counter(A)
for i in range(N):
  D[A[i]]-=1
  s=0
  for j in D:
    s+=D[j]*(D[j]-1)//2
  print(s)
  D[A[i]]+=1


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

D = collections.Counter(A)
s=0
for i in D:
  s+=D[i]*(D[i]-1)//2
  
for i in range(N):
  print(s-(D[A[i]]-1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for c in range(1, N):
    X = N - c

    for a in range(1, int(X**0.5)+1):
        if X%a == 0:
            ans += 1
            if X/a != a:
                ans += 1

print(ans)

Fixed submission:
N = int(input())

ans = 0
for a in range(1, N):
    ans += (N-1)//a

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

DP = [0]*(N+1)
DP[1] = 1

S = set()
for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r+1):
      S.add(j)

S = sorted(list(S))

for i in range(1, N+1):
    for d in S:
        if i + d <= N:
            DP[i+d] += DP[i]%998244353

print(DP[N]%998244353)

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

DP = [0]*(N+1)
DP[1] = 1

S = []
for i in range(K):
    S.append(list(map(int, input().split())))

for i in range(2, N+1):
    for l, r in S:
            DP[i] += (DP[max(i-l, 0)] - DP[max(i-r-1, 0)])
    DP[i] += DP[i-1]
    DP[i] %= 998244353

print((DP[N] - DP[N-1])%998244353)
Buggy python submission (verdict: Runtime Error):
N = int(input())

a=pow(10,n,10**9+7)
b=pow(9,n,10**9+7)
c=pow(8,n,10**9+7)
print((a-2*b+c)%(10**9+7))

Fixed submission:
n = int(input())

a=pow(10,n,10**9+7)
b=pow(9,n,10**9+7)
c=pow(8,n,10**9+7)
print((a-2*b+c)%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

mod = 10**9 + 7
N = int(input())

A = [int(i)%mod for i in input().split()]

ans = 0
for i, j in itertools.combinations(A, 2):
    ans += (i*j)

print(ans%mod)

Fixed submission:
N = int(input())

mod = 10**9 + 7

A = [int(i)%mod for i in input().split()]

S = [0]*N

ans = 0
for i in range(N-1):
    if i == 0:
        S[i] = sum(A) - A[i]
    else:
        S[i] = (S[i-1] - A[i])
    ans +=  (A[i]*S[i])%mod

print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

mod = 10**9 + 7

N = int(input())

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

ans = 0
for i, j in itertools.combinations(A, 2):
    ans += ((i%mod)*(j%mod))

print(ans%mod)

Fixed submission:
N = int(input())

mod = 10**9 + 7

A = [int(i)%mod for i in input().split()]

S = [0]*N

ans = 0
for i in range(N-1):
    if i == 0:
        S[i] = sum(A) - A[i]
    else:
        S[i] = (S[i-1] - A[i])
    ans +=  (A[i]*S[i])%mod

print(ans%mod)
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent = [-1] * N

    def root(self, A):
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])
        return self.parent[A]

    def size(self, A):
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        A = self.root(A)
        B = self.root(B)

        if (A == B):
            return False

        if (self.size(A) < self.size(B)):
            A, B = B, A

        self.parent[A] += self.parent[B]
        self.parent[B] = A

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


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

for i in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)

print(max(uf.size(i)) for i in range(1, N+1))


Fixed submission:
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent = [-1] * N

    def root(self, A):
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])
        return self.parent[A]

    def size(self, A):
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        A = self.root(A)
        B = self.root(B)

        if (A == B):
            return False

        if (self.size(A) < self.size(B)):
            A, B = B, A

        self.parent[A] += self.parent[B]
        self.parent[B] = A

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


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

for i in range(M):
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(N):
  ans = max(ans, uf.size(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from itertools import product

N = int(input())
L =　list(map(int, input().split()))
C = Coutner(L)

S = list(set(L))

ans = 0
for a, b, c in product(S, repeat = 3):
    if a + b > c and a + c > b and b + c > a:
        ans += (C[a]*C[b]*C[c])

print(ans)

Fixed submission:
from collections import Counter
import itertools 

N = int(input())
L = list(map(int, input().split()))
C = Counter(L)

S = list(set(L))

ans = 0
for a, b, c in itertools.combinations(S, 3):
    if a + b > c and a + c > b and b + c > a:
        ans += (C[a]*C[b]*C[c])

print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if rem == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if rem != 0:
    print(-1)

Fixed submission:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Buggy python submission (verdict: Runtime Error):
K = int(input())

X = 10
ans = 1    
while ans <= L:
    L = 9*K/7
    x = X%L
    if x == 1:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 

if x != 1:
    print(-1) 

Fixed submission:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Buggy python submission (verdict: Runtime Error):
K = int(input())

X = 10
ans = 1

if 
while ans <= 9000000:
    x = X%(9*K)
    if x == 1:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 

if x != 1:
    print(-1) 

Fixed submission:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

n = 7
i = 1
ans = -1

while i <= K:
    if n%K == 0:
        ans = i
        break
    n = n*10 + 7
    i += 1

if ans != -1:
    print(ans)    
else:
    print(-1)

Fixed submission:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Buggy python submission (verdict: Runtime Error):
K = int(input())

for i in range(1, 10):
    if str(K*i)[-1] == "7":
        S = ""
        ans = 0
        while ans <= 100000:
            S += "7"
            ans += 1
            if int(S)%K == 0:
                Flag = True
                break

if Flag == True:
    print(ans)
else:
    print(-1)

Fixed submission:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

S = ""
ans = 0
while ans <= 100000:
    S += "7"
    ans += 1
    if int(S)%K == 0:
        print(ans)
        break

else:
    print(-1)

Fixed submission:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(input())

def popcount(a):
    cnt = 0
    while True:
        y = bin(a).count("1")
        a %= y
        cnt += 1
        if a == 0:
            print(cnt)
            break

ans = 0
for i in range(len(X)):
    if X[i] == "1":
        X[i] = "0"
        Flag = True
    else:
        X[i] = "1"
        Flag = False
        
    x = "".join(X)
    n = int(x, 2)
    popcount(n)
            
    if Flag is True:
        X[i] = "1"
    else:
        X[i] = "0"

Fixed submission:
def goes_to_zero(n):
    cnt = 0
    while(n > 0):
        n %= bin(n).count('1')
        cnt += 1
    return cnt

N = int(input())
X = input()

XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0

for i in range(N):
    if X[i] == "0":
        print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
    else:
        if XCM == 0:
            print(0)
        else:
            print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(input())

def popcount(a):
    cnt = 0
    while True:
        y = bin(a).count("1")
        a %= y
        cnt += 1
        if a == 0:
            print(cnt)
            break

ans = 0
for i in range(len(X)):
    if X[i] == "1":
        X[i] = "0"
        Flag = True
    else:
        X[i] = "1"
        Flag = False
        
    x = "".join(X)
    n = int(x, 2)
    popcount(n)
            
    if Flag is True:
        X[i] = "1"
    else:
        X[i] = "0"

Fixed submission:
def goes_to_zero(n):
    cnt = 0
    while(n > 0):
        n %= bin(n).count('1')
        cnt += 1
    return cnt

N = int(input())
X = input()

XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0

for i in range(N):
    if X[i] == "0":
        print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
    else:
        if XCM == 0:
            print(0)
        else:
            print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(input())

def popcount(a):
    cnt = 0
    while True:
        y = bin(a).count("1")
        a %= y
        cnt += 1
        if n == 0:
            print(cnt)
            break

ans = 0
for i in range(len(X)):
    if X[i] == "1":
        X[i] = "0"
        Flag = True
    else:
        X[i] = "1"
        Flag = False
        
    x = "".join(X)
    n = int(x, 2)
    popcount(n)
            
    if Flag is True:
        X[i] = "1"
    else:
        X[i] = "0"

Fixed submission:
def goes_to_zero(n):
    cnt = 0
    while(n > 0):
        n %= bin(n).count('1')
        cnt += 1
    return cnt

N = int(input())
X = input()

XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0

for i in range(N):
    if X[i] == "0":
        print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
    else:
        if XCM == 0:
            print(0)
        else:
            print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1)
Buggy python submission (verdict: Runtime Error):
import bisect

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

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

a = [0]
b = [0]
for i in range(N):
    a += [a[i] + A[i]]
for i in range(M):
    b += [b[i] + B[i]]

ans = 0
for i in range(N+1):
    if A[i] <= K:
        ans = max(ans, i + bisect.bisect_right(b, K - a[i])-1)

print(ans)

Fixed submission:
import bisect

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

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

a = [0]
b = [0]
for i in range(N):
    a += [a[i] + A[i]]
for i in range(M):
    b += [b[i] + B[i]]

ans = 0
for i in range(N+1):
    if a[i] <= K:
        ans = max(ans, i + bisect.bisect_right(b, K - a[i])-1)

print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect

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

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

a = [0]
b = [0]
for i in range(N):
    a += (a[i] + A[i])
for i in range(M):
    b += (b[i] + B[i])

ans = 0
for i in range(N+1):
    ans = max(ans, i + bisect.bisect_right(b, K - a[i]))

print(ans)

Fixed submission:
import bisect

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

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

a = [0]
b = [0]
for i in range(N):
    a += [a[i] + A[i]]
for i in range(M):
    b += [b[i] + B[i]]

ans = 0
for i in range(N+1):
    if a[i] <= K:
        ans = max(ans, i + bisect.bisect_right(b, K - a[i])-1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def factorization(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
ANS = 0
for i in range(1, N+1):
    c = Counter(factorization(i))
    ans = 1
    for j in c.values():
        ans *= (j+1)
    ANS += i*ans

print(ANS)

Fixed submission:
N = int(input())

ans = 0
for i in range(1, N+1):
    x = N//i
    ans += i*x*(x+1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul

N = int(input())
List = list(map(int, input().split()))

ans = reduce(mul,List)
print(ans if ans<=10**18 else -1)

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

List.sort()
ans = 1
for i in List:
    ans *= i
    if ans > 10**18:
        print(-1)
        break
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(float, input().split())
print(int(a//(1/b)))

Fixed submission:
from decimal import Decimal

a, b = map(Decimal, input().split())
print(int(a*b))
Buggy python submission (verdict: Runtime Error):
import collections

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

G = [[] for i in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [-1]*N
visited[0] = 0
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == -1:
            visited[i] = visited[x] + 1
            queue.append(i)

print("Yes")
print(*visited[1:], sep="\n")

Fixed submission:
import collections

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

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)

print("Yes")
print(*visited[1:], sep="\n")

Buggy python submission (verdict: Runtime Error):
import collections

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

G = [[] for i in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)
print("Yes")
print(*visited[1:], sep="\n")

Fixed submission:
import collections

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

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)

print("Yes")
print(*visited[1:], sep="\n")

Buggy python submission (verdict: Runtime Error):
import collections

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

G = [[] for i in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)
print("Yes")
print(*visited[1:], sep="\n")

Fixed submission:
import collections

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

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)

print("Yes")
print(*visited[1:], sep="\n")
Buggy python submission (verdict: Runtime Error):
import itertools

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

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

saisyo = float("inf")
for i in intertools.product(range(2), N):
    a = [0]*M
    gokei = 0
    for j in range(N):
        if i[j] == 1:
            gokei += A[j][0]
            for k in range(1, M+1):
                a[k-1] += A[j][k]
    if min(a) >= X:
        saisyo = min(saisyo, gokei)

print(saisyo if saisyo != float("inf") else -1)

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

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

saisyo = float("inf")
for i in range(2**N):
    a = [0]*M
    gokei = 0
    for j in range(N):
        if (i>>j)&1:
            gokei += A[j][0]
            for k in range(1, M+1):
                a[k-1] += A[j][k]
    if all(a[l] >= X for l in range(M)):
        saisyo = min(saisyo, gokei)

print(saisyo if saisyo != float("inf") else -1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [i-1 for i in A]

check = [0]*N
i = 0
c = 0
check = []
visited = [0]*N
flag = False
while c<=K:
    if visited[i] == 1:
        flag = True
        break
    else:
        check.append(i)
        visited[i] = 1
        i = A[i]
        c += 1
if flag==True:
    X = check[check.index(i):]
    print(1+X[(K-check.index(i))%(len(check)-check.index(i)))  
else: 
    print(i+1)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [i-1 for i in A]

check = [0]*N
i = 0
c = 1
check = []
visited = [0]*N
flag = False
while c<=K:
    if visited[i] == 1:
        flag = True
        break
    else:
        check.append(i)
        visited[i] = 1
        i = A[i]
        c += 1
if flag==True:
    X = check[check.index(i):]
    print(1+X[(K-check.index(i))%len(X)])  
else: 
    print(i+1)