Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split(' ')]
A.sort()
B = [0]*(A[N-1]-A[0]+3)

for a in A:
    B[a] += 1
    B[a-1] += 1
    B[a+1] += 1
print(max(B))

Fixed submission:
N = int(input())
A = [int(i) for i in input().split(' ')]
A.sort()
B = [0]*(A[N-1]+3)

for a in A:
    B[a] += 1
    B[a+1] += 1
    B[a+2] += 1

print(max(B))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split(' ')]
count = 0
answer = 0

A.sort()

for i in range(A[0],A[N-1]+1):
    count = 0
    for a in A:
        if i-1 <= a <= i+1:
            count += 1
    if answer < count:
        answer = count
print(answer)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split(' ')]
A.sort()
B = [0]*(A[N-1]+3)

for a in A:
    B[a] += 1
    B[a+1] += 1
    B[a+2] += 1

print(max(B))
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
hune = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[0])

for a,b in hune:
    if a == 1:
        for c,d in hune:
            if c == b and d == N:
                print('POSSIBLE')
                return
    if a == 2:
        break
print('IMPOSSIBLE')

Fixed submission:
from collections import defaultdict


def check():
    N,M = map(int, input().split())
    B = []
    hune = defaultdict(list)
    for _ in range(M):
        a,b = map(int, input().split())
        if a == 1:
            B.append(b)
        hune[a].append(b)
    
    for b in B:
        for goal in hune[b]:
            if goal == N:
                print('POSSIBLE')
                return
    print('IMPOSSIBLE ')
    
check()

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
hune = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[0])

for a,b in hune:
    if a == 1:
        for c,d in hune:
            if c == b and d == N:
                print('Yes')
                return
    if a == 2:
        break
print('No')

Fixed submission:
from collections import defaultdict


def check():
    N,M = map(int, input().split())
    B = []
    hune = defaultdict(list)
    for _ in range(M):
        a,b = map(int, input().split())
        if a == 1:
            B.append(b)
        hune[a].append(b)
    
    for b in B:
        for goal in hune[b]:
            if goal == N:
                print('POSSIBLE')
                return
    print('IMPOSSIBLE ')
    
check()
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
a = []
for i in range(N):
	a.append(raw_input())
#print a
for i in range(N):
	a[i] = int(a[i])
cnt = 0
trn = 0
while trn != 1:
	if trn == -2:
		cnt = -1
		break
	#print a

	hako = trn
	trn = a[trn] - 1
	a[hako] = -1
	cnt += 1
	
print cnt


Fixed submission:
a = raw_input().split()
for i in range(3):
	a[i] = int(a[i])

b = a[1] - a[2]
if b >= 0:
	print "delicious"
else:
	if a[0] + a[1] < a[2]:
		print "dangerous"
	else:
		print "safe"
Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
a = []
for i in range(N):
	a.append(raw_input())
#print a
for i in range(N):
	a[i] = int(a[i])
cnt = 0
trn = 0
while trn != 1:
	if trn == -1:
		cnt = -1
		break
	#print a

	hako = trn
	trn = a[trn] - 1
	a[hako] = -1
	cnt += 1
	
print cnt

Fixed submission:
N = int(raw_input())
a = []
for i in range(N):
	a.append(raw_input())
#print a
for i in range(N):
	a[i] = int(a[i])
cnt = 0
trn = 0
while trn != 1:
	if trn == -2:
		cnt = -1
		break
	#print a

	hako = trn
	trn = a[trn] - 1
	a[hako] = -1
	cnt += 1
	
print cnt
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
a = raw_input()

b = a.split()
c = [0 for i in range(9)]
for i in range(N):
	b[i] = int(b[i])
	if 1 <= b[i] <=399:
		c[0] = 1
	elif 400 <= b[i] <= 799:
		c[1] = 1
	elif 800 <= b[i] <=1199:
		c[2] = 1
	elif 1200<= b[i] <= 1599:
		c[3] = 1
	elif 1600 <= b[i] <= 1999:
		c[4] = 1
	elif 2000 <= b[i] <= 2399:
		c[5] = 1
	elif 2400 <= b[i] <= 2799:
		c[6] = 1
	elif 2800 <= b[i] <= 3199:
		c[7] = 1
	else:
		c[8] += 1

max = 0
min = 0
for i in range(9):
	max = max + c[i]

min = max - c[8]
if min == 0:
	min = 1
print min, 
print max

Fixed submission:
a= raw_input().split()

sum = int(a[0])*100 + int(a[1])*10 + int(a[2])

if sum%4 == 0:
	print "YES"
else:
	print "NO"

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
a = raw_input()

b = a.split()
c = [0 for i in range(9)]
for i in range(N):
	b[i] = int(b[i])
	if 1 <= b[i] <=399:
		c[0] = 1
	elif 400 <= b[i] <= 799:
		c[1] = 1
	elif 800 <= b[i] <=1199:
		c[2] = 1
	elif 1200<= b[i] <= 1599:
		c[3] = 1
	elif 1600 <= b[i] <= 1999:
		c[4] = 1
	elif 2000 <= b[i] <= 2399:
		c[5] = 1
	elif 2400 <= b[i] <= 2799:
		c[6] = 1
	elif 2800 <= b[i] <= 3199:
		c[7] = 1
	else:
		c[8] += 1

max = 0
min = 0
for i in range(9):
	max = max + c[i]

min = max - c[8]

print (min,max)

Fixed submission:
a= raw_input().split()

sum = int(a[0])*100 + int(a[1])*10 + int(a[2])

if sum%4 == 0:
	print "YES"
else:
	print "NO"

Buggy python submission (verdict: Runtime Error):
r = int(raw_input('red:'))
g = int(raw_input('green:'))
b = int(raw_input('blue:'))

sum = r*100 + g*10 + b

if sum%4 == 0:
	print "YES"
else:
	print "NO"

Fixed submission:
a= raw_input().split()

sum = int(a[0])*100 + int(a[1])*10 + int(a[2])

if sum%4 == 0:
	print "YES"
else:
	print "NO"
Buggy python submission (verdict: Runtime Error):
from collections import deque

H,W = map(int, input().split())
A = [input()+'.' for _ in range(H)]
A.append('.'*(W+1))

total = sum([1 for a in A for s in a  if s=='#'])

que = deque([[0,0,1]])
while que:
    for x,y in [(1,0), (0,1)]:
        x_,y_,cnt = que.popleft()
        next_x, next_y = x_+x, y_+y
        if A[next_y][next_x] == '#':
            que.append([next_x,next_y,cnt+1])

print('Possible' if total == cnt else 'Impossible')

Fixed submission:
H,W = map(int, input().split())
A = [input() for _ in range(H)]

total = sum([1 for a in A for s in a  if s=='#'])   
print('Possible' if total == W+H-1 else 'Impossible')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])


def score(D, c, s, t):
    score = 0

    last_date = np.zeros(26)

    for di in range(1, D + 1):
        score += s[di - 1][t[di - 1]]

        last_date[t[di - 1]] = di

        for i in range(26):
            score -= c[i - 1] * (di - last_date[i - 1])

    return int(score)


def f5(D, c, s):
    t = np.zeros(D, dtype=int)
    for di in range(1, D + 1):
        current_score = score(D, c, s, t)

        random_values = np.arange(26)
        np.random.shuffle(random_values)
        limit = 5

        for i in random_values[:limit]:
            tmp = np.copy(t)
            tmp[di - 1] = i
            tmp_score = score(D, c, s, tmp)
            if current_score < tmp_score:
                t = tmp
                break
    return t


for ti in f5(D, c, s):
    print(ti + 1)

Fixed submission:
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])

for si in s:
    print(np.where(si==max(si))[0][0].tolist() + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])


def score(D, c, s, t):
    score = 0

    last_date = np.zeros(26)

    for di in range(1, D + 1):
        score += s[di - 1][t[di - 1]]

        last_date[t[di - 1]] = di

        for i in range(26):
            score -= c[i - 1] * (di - last_date[i - 1])

    return int(score)


def f4(D, c, s):
    t = np.zeros(D, dtype=int)
    for di in range(1, D + 1):
        current_score = score(D, c, s, t)
        for i in range(26):
            tmp = np.copy(t)
            tmp[di - 1] = i
            tmp_score = score(D, c, s, tmp)
            if current_score < tmp_score:
                current_score = tmp_score
                t = tmp
    return t


for ti in f4(D, c, s):
    print(ti + 1)

Fixed submission:
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])

for si in s:
    print(np.where(si==max(si))[0][0].tolist() + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
import operator

input()
ans = reduce(operator.mul, map(int, input().split()), 1)
ans = ans if ans <= 10 ** 18 else -1
print(ans)

Fixed submission:
from functools import reduce
import operator

def f():
    input()
    s = input().split()

    if "0" in s:
        return 0

    ans = 1
    for num in map(int,s):
        ans *= num
        if ans > 10 ** 18:
            return -1
    return ans

print(f())
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))[::-1]

def f(A):
    nodes=[]
    for i in list(range(len(A))):
        t = len(A)-i-1
        if i == 0:
            if 2**t < A[i]:
                return -1
            nodes.append(A[i])
        else:
            tmp = min(nodes[-1] + A[i],2**t)
            anchor = (tmp-A[i])*2
            if anchor < nodes[-1]:
                flag = True
                for j in range(len(nodes))[::-1]:
                    if anchor < nodes[j]:
                        nodes[j] = anchor
                        anchor = (nodes[j]-A[j])*2
                    else:
                        flag = False
                        break
                if flag : return -1        
            nodes.append(tmp)
    return sum(nodes)
  
print(f(A))

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

def solve(A):
    ans = 0
    leaves = sum(A)
    prev_node_capacity = 1

    for ai in A:
        if ai > prev_node_capacity:
            return -1
        ans += min(prev_node_capacity, leaves)

        leaves -= ai
        prev_node_capacity -= ai
        prev_node_capacity *= 2

    return ans
  
print(solve(A))
Buggy python submission (verdict: Runtime Error):
print("YNeos"[input()==input([:-1])::2])

Fixed submission:
print("YNeos"[input()!=input()[:-1]::2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))

d={}
for i in D:
    d[i]=d.get(i,0)+1

s = 0
for l in range(1, max(D)):
    if l == 1: s = 1
    for i in range(d[l+1]):
        s *= d[l]

print(s)

Fixed submission:
from collections import Counter

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

L = sorted(set(D))
d = Counter(D)
s = 0

if (D[0] == 0) and (list(range(max(D) + 1)) == L):
    if (d[0]==1) and (1 in d):
        s = 1
        for l in L[1:-1]:
            for i in range(d[l + 1]):
                s *= d[l]
                s %= 998244353
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

input()

ans = 0
for tup in permutations(map(int, input().split())):
    tmp = tup[0]
    for t in tup[1:]:
        tmp = (tmp + t) / 2
    ans = max(ans, tmp)

print(ans)

Fixed submission:
input()
V = sorted(map(int, input().split()))

ans = V[0]
for v in V[1:]:
    ans = (ans + v) / 2

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

L, R = map(int, input().split())
ans = set(range(L, R + 1))

for i in range(1, M):
    L, R = map(int, input().split())
    ans &= set(range(L, R + 1))

print(len(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)

print(max(min(R) - max(L) + 1, 0))
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
input()
print(len(bin(reduce(gcd,list(map(int,input().split())))))-3)

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

c=0
while True:
    if not all([1-ai%2 for ai in a]):break
    a=[ai//2 for ai in a]
    c+=1    
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
A=[]
for _ in range(int(input())):
    i = int(input())
    if i in A:
        A.remove(i)
    else:
        A.append(i)
        
print(len(A))

Fixed submission:
n=int(input())
d={}
for _ in [0]*n:
    v=int(input())
    d[v]=(d.get(v,0)+1)%2
    
print(sum(d.values()))

Buggy python submission (verdict: Runtime Error):
for _ in range(int(input())):
    i = int(input())
    if i in A:
        A.remove(i)
    else:
        A.append(i)
        
print(len(A))

Fixed submission:
n=int(input())
d={}
for _ in [0]*n:
    v=int(input())
    d[v]=(d.get(v,0)+1)%2
    
print(sum(d.values()))

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

N = int(input())
A = np.zeros(1000000000,dtype=bool)

for _ in range(N):
    i = int(input())
    A[i] = not A[i]
    
print(np.count_nonzero(A))

Fixed submission:
n=int(input())
d={}
for _ in [0]*n:
    v=int(input())
    d[v]=(d.get(v,0)+1)%2
    
print(sum(d.values()))
Buggy python submission (verdict: Runtime Error):
print('YES' if int(input())%500<=int(input()) else 'NO')

Fixed submission:
print('NO'if int(input().replace(' ',''))%4 else 'YES')
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

n=int(input())
s=[int(input()) for _ in [0]*n]

m=0
for t in product([0,1],repeat=len(s)):
    v=sum([i*j for i,j in zip(s,t)])
    if m<v and v%10!=0:
        m=v
print(m)

Fixed submission:
n=int(input())
s=sorted([int(input()) for _ in [0]*n])

if sum(s)%10==0:
    f=False
    for i in s:
        if i%10!=0:
            f=True
            break
    if f:
        s.remove(i)
        print(sum(s))
    else:
        print(0)
else:
    print(sum(s))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[int(input()) for _ in [0]*n]

from itertools import chain,combinations
def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

m=0
for i in powerset(s):
    v=sum(i)
    if m<v and v%10!=0:
        m=v
print(m)

Fixed submission:
n=int(input())
s=sorted([int(input()) for _ in [0]*n])

if sum(s)%10==0:
    f=False
    for i in s:
        if i%10!=0:
            f=True
            break
    if f:
        s.remove(i)
        print(sum(s))
    else:
        print(0)
else:
    print(sum(s))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input())
s=open(0).read().split()
for i in range(n):print(s.count(str(i)))

Fixed submission:
N,M=list(map(int,input().split()))
a=list()
for i in [1]*M:
    for j in input().split():
        a.append(j)
for i in range(1,N+1):
    print(str(a.count(str(i))))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n=int(input());S=list(map(sorted,[input() for _ in [1]*n]))
re=[]
for s in S:
    tmp=[]
    for i in range(len(s)):
        li=list(itertools.combinations(s,i))
        for lii in li:tmp.append(lii)
    re.append(tmp)
re2=re[0]
for i in range(1,len(re)):
    re2=list(set(re2)&set(re[i]))
l=max([len(r) for r in re2])
for i in range(len(re2)):
    if len(re2[i])==l:
        print(''.join(re2[i]))
        break

Fixed submission:
n=int(input());S=list(map(sorted,[input() for _ in [1]*n]))
dicList=[]
for s in S:
    dic={}
    for c in list(s):
        dic[c]=dic.get(c,0)+1 
    dicList.append(dic)
result=''
c=[chr(i) for i in range(97, 97+26)]
count=0
while count<26:
    m = min([dic.get(c[count],0) for dic in dicList])
    if m==0:count+=1
    else:
        for dic in dicList:
            dic[c[count]]-=1
        result+=c[count]
print(result)

Buggy python submission (verdict: Runtime Error):
import itertools
n=int(input());S=list(map(sorted,[input() for _ in [1]*n]))
re=[]
for s in S:
    tmp=[]
    for i in range(l):
        li=list(itertools.combinations(s,i))
        for lii in li:tmp.append(lii)
    re.append(tmp)
re2=re[0]
for i in range(1,len(re)):
    re2=list(set(re2)&set(re[i]))
l=max([len(r) for r in re2])
for i in range(len(re2)):
    if len(re2[i])==l:
        print(''.join(re2[i]))
        break

Fixed submission:
n=int(input());S=list(map(sorted,[input() for _ in [1]*n]))
dicList=[]
for s in S:
    dic={}
    for c in list(s):
        dic[c]=dic.get(c,0)+1 
    dicList.append(dic)
result=''
c=[chr(i) for i in range(97, 97+26)]
count=0
while count<26:
    m = min([dic.get(c[count],0) for dic in dicList])
    if m==0:count+=1
    else:
        for dic in dicList:
            dic[c[count]]-=1
        result+=c[count]
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
r=range;k,s=map(int,input().split())
print(len([0 for x in r(k+1) for y in r(k+1) for z in r(k+1) if x+y+z==s]))

Fixed submission:
r=range;k,s=map(int,input().split())
print(len([0 for x in r(k+1) for y in r(k+1) if 0<=s-x-y<=k]))
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
*a,=map(int,input().split())

v=[i if i<x else x for i in a]
b=[v[i]+v[i+1]<=x for i in range(n-1)]     

while not all(b):
    f=True
    for i in range(n-2):
        if not b[i] and not b[i+1]:
            v[i+1]=x-v[i]
            f=False
            break
    if f:
        for i in range(n-1):
            if not b[i]:
                v[i]=min(x-v[i-1],x-v[i+1])
                break
    b=[v[i]+v[i+1]<=x for i in range(n-1)]     
    
print(sum(a)-sum(v))

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

v=[i if i<x else x for i in a]

for i in range(n-1):
    if v[i]+v[i+1]>x:
        v[i+1]=x-v[i]

print(sum(a)-sum(v))

Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
*a,=map(int,input().split())

v=[i if i<x else x for i in a]
b=[v[i]+v[i+1]<=x for i in range(n-1)]     

while not all(b):
    for i in range(n-2):
        if not b[i] and not b[i+1]:
            v[i+1]-=1
            break
        if not b[i]:
            v[i]-=1
            break
    b=[v[i]+v[i+1]<=x for i in range(n-1)]     
    
print(sum(a)-sum(v))

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

v=[i if i<x else x for i in a]

for i in range(n-1):
    if v[i]+v[i+1]>x:
        v[i+1]=x-v[i]

print(sum(a)-sum(v))
Buggy python submission (verdict: Runtime Error):
mod = 1000000007

def mul(x, y):
    return x * y % mod

def f(n, arr):
    answer = 1
    count = [0 for _ in range(n)]
    count[0] = 3
    for e in range(n):
        answer = mul(answer, count[arr[e] - 1] - count[arr[e]])
        count[arr[e]] = count[arr[e]] + 1
        # print("answer ", answer)
    return answer

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    for i in range(n):
        arr[i] = arr[i] + 1 
    print(f(n, arr))

Fixed submission:
mod = 1000000007

def mul(x, y):
    return x * y % mod

def f(n, arr):
    answer = 1
    count = [0 for _ in range(n + 1)]
    count[0] = 3
    for e in range(n):
        answer = mul(answer, count[arr[e] - 1] - count[arr[e]])
        count[arr[e]] = count[arr[e]] + 1
        # print("answer ", answer)
    return answer

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    for i in range(n):
        arr[i] = arr[i] + 1 
    print(f(n, arr))
Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


A, B, C = map(int, input().split())
ans = 0
a, b, c = A, B, C
while True:
    dump(a, b, c)
    if odd(a) or odd(b) or odd(c):
        print(ans)
        exit()
    if ans > 0 and a == A and b == B and c == C:
        print(-1)
        exit()
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    ans += 1

Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


A, B, C = map(int, input().split())
ans = 0
a, b, c = A, B, C
while True:
    dump(a, b, c)
    if odd(a) or odd(b) or odd(c):
        print(ans)
        exit()
    if ans > 0 and a == A and b == B and c == C:
        print(-1)
        exit()
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    ans += 1
Buggy python submission (verdict: Runtime Error):
#include<iostream>
#include<string>

using namespace std;
int main(){
    int ans;
    float a,b ;
    cin>>a ;
    cin>>b;
    ans = a*b;
    cout<<ans;
    return 0 ;
}

Fixed submission:
from decimal import Decimal

a, b = map(Decimal, input().split())
print(int(a * b))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from sys import maxsize
from copy import deepcopy


class Graph:
    def __init__(self, No_of_nodes):
        self.n = No_of_nodes
        self.adj = [[] for i in range(self.n)]

    def addEdge(self, a, b, w):
        self.adj[a].append([b, w])

    def dijkstra(self, start):
        nxtpoint = [None for i in range(self.n)]
        distance = [maxsize for i in range(self.n)]
        distance[start] = 0
        q = deque()
        q.append(start)
        while len(q) != 0:
            a = q.pop()
            for u in self.adj[a]:
                b, w = u
                if distance[a] + w < distance[b]:
                    distance[b] = distance[a] + w
                    nxtpoint[b] = a
                    q.append(b)
        return nxtpoint


n, m = map(int, input().split())
ls = []
g = Graph(n)
ans = 'Yes\n'
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g.addEdge(a, b, 1)
    g.addEdge(b, a, 1)
point = g.dijkstra(0)
for i in range(1,n):
    if point[i] is None:
        ans = 'No'
        break
    else:
        ans += str(point[i] + 1) +'\n'
print(ans)


Fixed submission:
from collections import deque
from sys import maxsize
from copy import deepcopy


class Graph:
    def __init__(self, No_of_nodes):
        self.n = No_of_nodes
        self.adj = [[] for i in range(self.n)]

    def addEdge(self, a, b, w):
        self.adj[a].append([b, w])

    def BFS(self, start):
        visited = [False] * self.n
        depth = [0 for i in range(self.n)]
        que = deque()
        q = [start]
        que.append(start)
        visited[start] = True
        ans = ''
        f = 0
        while que:
            s = que.popleft()
            ans += str(s) + ' '
            for i in self.adj[s]:
                if not visited[i[0]]:
                    depth[i[0]] = s
                    que.append(i[0])
                    visited[i[0]] = True
        return depth

    def dijkstra(self, start):
        nxtpoint = [None for i in range(self.n)]
        distance = [maxsize for i in range(self.n)]
        distance[start] = 0
        q = deque()
        q.append(start)
        while len(q) != 0:
            a = q.pop()
            for u in self.adj[a]:
                b, w = u
                if distance[a] + w < distance[b]:
                    distance[b] = distance[a] + w
                    nxtpoint[b] = a
                    q.append(b)
        return nxtpoint


n, m = map(int, input().split())
ls = []
g = Graph(n)
ans = 'Yes\n'
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g.addEdge(a, b, 1)
    g.addEdge(b, a, 1)
point = g.BFS(0)
for i in range(1, n):
    if point[i] is None:
        ans = 'No'
        break
    else:
        ans += str(point[i] + 1) + '\n'
print(ans)