Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(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

def main():
  n = int(input())
  nums = []
  for i in range(n):
    nums.append(int(input()))
  
  min_num = min(nums)
  print(math.ceil(n/min_num)+4)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Fixed submission:
N = int(input())

A = []
for _ in range(5):
  A.append(int(input()))
  
import math
L = math.ceil(N/min(A))

print(5 + L - 1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    if ki > i:
      continue
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    if ki > i:
      continue
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    if ki > i:
      continue
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    if ki > i:
      continue
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

print(dp[-1])

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

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for ki in range(1, k+1):
    if ki > i:
      continue
    dp[i] = min(dp[i], dp[i-ki] + abs(a[i] - a[i-ki]))
    #print(i, ki, dp[i-ki] + abs(a[i] - a[ki]), dp)

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

Years = []
Ps = {}
for _ in range(M):
  P, Y = map(int, input().split())
  Years.append(Y)
  if P in Ps:
    Ps[P].append(Y)
  else:
    Ps[P] = [Y]

A = [0] * M
for i, v in Ps.items():
  for yi, y in enumerate(sorted(v)):
    index = Years.index(y)
    A[index] = str(i).zfill(6)+str(yi+1).zfill(6)
  
for a in A:
  print(a)

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

dic = {i+1:[] for i in range(N)}

for i in range(M):
  p, y = map(int, input().split())
  dic[p].append((i,y))

for i in range(N):
  dic[i+1].sort(key=lambda x:x[1])
  
ans = [0] * M
for k, vs in dic.items():
  order = 1
  for c, y in vs:
    ans[c] = (k, order)
    order += 1

for city, order in ans:
  print(str(city).zfill(6)+str(order).zfill(6))
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

slen = len(s)
bstr = '1'*slen

B = int(bstr,2)
f = '0'+str(slen)+'b'
ss = list(s)

a = []
for i in range(B):
  w = ''
  fb = str(format(i, f))
  for i,si in enumerate(list(fb)):
    if si == '1':
      w += ss[i]
      
  if w != '' and w not in a:
    a.append(w)
    
a = sorted(a)
print(a[k-1])

Fixed submission:
s = input()
k = int(input())
a = []
for i in range(len(s)):
  for j in range(1, k+1):
    jj = j+i
    a.append(s[i:jj])
a = sorted(set(a))
print(a[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(map(int, input().split()))

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

Fixed submission:
n = int(input())
s = list(map(int, input().split()))
sx = sorted(s)
a = sx[(n//2)-1]
b = sx[n//2]
for i in s:
  if i <= a:
    print(b)
  else:
    print(a)

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

C = int(N / 2)

for i in range(N):
  AS = S[:i] + S[i+1:]
  SortedA = sorted(AS, reverse=True)
  print(SortedA[C-1])

Fixed submission:
n = int(input())
s = list(map(int, input().split()))
sx = sorted(s)
a = sx[(n//2)-1]
b = sx[n//2]
for i in s:
  if i <= a:
    print(b)
  else:
    print(a)
Buggy python submission (verdict: Runtime Error):
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline

def main():
    s = input_list()
    a_num = s.count('a')
    b_num = s.count('b')
    c_num = s.count('c')
    if abs(a_num - b_num) <= 1 and abs(b_num - c_num) <= 1 and abs(a_num - c_num) <= 1:
        print('YES')
    else:
        print('NO')



def divide_list(l, args):
    result = []
    pre = 0
    for i, a in enumerate(args):
        if i != 0:
            pre = args[i-1]
        result.append(l[pre:a])
        if i == len(args) - 1:
            result.append(l[a:])
    return result

def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c

def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
  s = input()
  ac = s.count('a')
  bc = s.count('b')
  cc = s.count('c')
  if abs(ac-bc) <= 1 and abs(bc-cc) <= 1 and abs(ac-cc) <= 1:
    print('YES')
  else:
    print('NO')
  
  
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = {}
r = []
for i in range(n):
  s = int(input())
  if s in a:
    a[s] += 1
    if a[s] % 2 == 0:
      r.remove(s)
  else:
    a[s] = 1
    r.append(s)
    
print(len(r))

Fixed submission:
import collections
n = int(input())

r = []
for i in range(n):
  r.append(int(input()))

c = collections.Counter(r)
count = 0
for key, v in c.items():
  if v % 2 != 0:
    count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
a = list(map(int, input().split()))

rec_hen = 0
a_set = sorted(set(a), reverse=True)
for ai in a_set:
  ac = a.count(ai)
  if ac >= 4:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    print(ai * ai)
    exit(0)
  if ac >= 2:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    rec_hen = ai

print(0)

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

rec_hen = 0
#a_set = sorted(set(a), reverse=True)
acc = collections.Counter(a)
ssa = sorted(acc.items(), key=lambda x: x, reverse=True)
for i, c in ssa:
  if c >= 4:
    if rec_hen != 0:
      print(rec_hen * i)
      exit(0)
    print(i * i)
    exit(0)
  if c >= 2:
    if rec_hen != 0:
      print(rec_hen * i)
      exit(0)
    rec_hen = i

print(0)

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

rec_hen = 0
a_set = sorted(set(a), reverse=True)
for ai in a_set:
  ac = a.count(ai)
  if ac >= 4:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    print(ai * ai)
    exit(0)
  if ac >= 2:
    if rec_hen != 0:
      print(rec_hen * ai)
      exit(0)
    rec_hen = ai

print(0)

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

rec_hen = 0
#a_set = sorted(set(a), reverse=True)
acc = collections.Counter(a)
ssa = sorted(acc.items(), key=lambda x: x, reverse=True)
for i, c in ssa:
  if c >= 4:
    if rec_hen != 0:
      print(rec_hen * i)
      exit(0)
    print(i * i)
    exit(0)
  if c >= 2:
    if rec_hen != 0:
      print(rec_hen * i)
      exit(0)
    rec_hen = i

print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
sticks = list(map(int, input().split()))
s = sum(sticks)

a = []
sum_i = 0
for i, v in enumerate(sticks):
  sum_i += v
  if i == 0:
    continue
  if i == len(sticks) - 1:
    continue
  a.append(abs(s - 2*sum_i))

print(min(a))

  

Fixed submission:
n = int(input())
sticks = list(map(int, input().split()))
s = sum(sticks)

a = []
sum_i = 0
for i, v in enumerate(sticks):
  sum_i += v
  if i == len(sticks) - 1:
    continue
  a.append(abs(s - 2*sum_i))

print(min(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = map(int, input().split())
b = []
for ai in a:
  b.append(str(ai))
  b = list(reversed(b))
print(' '.join(b))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
#b = []
#for ai in a:
#  b.append(str(ai))
#  b = list(reversed(b))
#print(' '.join(b))
if len(a) % 2 == 0:
  even = []
  odd = []
  for i, ai in enumerate(a):
    if (i + 1) % 2 == 0:
      even.append(str(ai))
    else:
      odd.append(str(ai))

  r = list(reversed(even))
  answer = r + odd
  print(' '.join(answer))
else:
  even = []
  odd = []
  for i, ai in enumerate(a):
    if (i + 1) % 2 == 0:
      even.append(str(ai))
    else:
      odd.append(str(ai))
  r = list(reversed(odd))
  answer = r + even
  print(' '.join(answer))
Buggy python submission (verdict: Time Limit Exceeded):
import math

a, b = map(int, input().split())
fa = math.factorial(a)
fb = math.factorial(b)

if abs(a-b) >= 2:
  print(0)
elif abs(a-b) == 1:
  print(fa*fb)
elif abs(a-b) == 0:
  print(2*(fa*fb))

Fixed submission:
import math

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

diff = abs(a - b)
if diff >= 2:
  print(0)
  exit(0)
  
n = (10 ** 9) + 7
f = math.factorial(a) * math.factorial(b)
if diff == 1:
  print(f % n)
  exit(0)
  
print((2 * f) % n)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

nums = []
for _ in range(n):
  a, b = map(int, input().split())
  nums.extend([a]*b)
  
sn = sorted(nums)
print(sn[k-1])


Fixed submission:
from operator import itemgetter
n, k = map(int, input().split())

arr = []
k_sum = 0
for i in range(n):
  a, b = map(int, input().split())
  d = {}
  d['num'] = a
  d['count'] = b
  arr.append(d)
  
arr = sorted(arr, key=itemgetter('num'))

for i in range(n):
  k_sum += arr[i]['count']
  if k <= k_sum:
    print(arr[i]['num'])
    exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
power = 1

for i in range(1, n + 1):
  power = i * power

amari = (10 ** 9) + 7
print(int(power % amari))

Fixed submission:
n = int(input())
power = 1

for i in range(1, n + 1):
  power = (i * power) % ((10 ** 9) + 7)

print(power)
Buggy python submission (verdict: Runtime Error):
n = int(input())

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

kind = len(set(a))

if kind % 2 == 0:
  print(kind - 1)
else:
  print(kin)
  

Fixed submission:
n = int(input())

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

kind = len(set(a))

if kind % 2 == 0:
  print(kind - 1)
else:
  print(kind)
Buggy python submission (verdict: Runtime Error):
def count_baisuu(a, b):
  return b - (a % b)
  
def main():
  n = int(input())
  alist = []
  blist = []
  ab = []
  for i in range(n):
    a, b = input_list()
    ab.append((a, b))
    alist.append(a)
    blist.append(b)
    
  dp = [0]*n
  i = n - 1
  for a, b in reversed(ab):
    if i != n-1:
      a += sum(dp)
    if a % b == 0:
      continue
    if a < b:
      dp[i] = b - a
    else:
      dp[i] = count_baisuu(a, b)
    i -= 1
  print(sump(dp))
  
  

import math
import fractions
from functools import reduce


def input_list():
  return map(int, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
main()

Fixed submission:
def count_baisuu(a, b):
  return b - (a % b)
  
def main():
  n = int(input())
  alist = []
  blist = []
  ab = []
  for i in range(n):
    a, b = input_list()
    ab.append((a, b))
    alist.append(a)
    blist.append(b)
  
  s = 0
  res = 0
  for i in range(n-1, -1, -1):
    alist[i] += res
    
    if alist[i] % blist[i] == 0:
      continue
    res += blist[i] - (alist[i]%blist[i])
  print(res)
  exit()
  dp = [0]*n
  i = n - 1
  res = 0
  for a, b in reversed(ab):
    if i != n-1:
      res += dp[i]
    a += res
    if a % b == 0:
      continue
    if a < b:
      dp[i] = b - a
    else:
      dp[i] = count_baisuu(a, b)
    i -= 1
  print(dp)
  
  

import math
import fractions
from functools import reduce


def input_list():
  return map(int, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
main()
Buggy python submission (verdict: Runtime Error):
n = int(input())

import math

f = math.factorial(n)

def prime_factorize(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

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

d = make_divisors(f)

print(len(d))

Fixed submission:
n = int(input())

import math

def prime_factorize(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

def make_divisors(n):
  divisors = []
  mod = 10**9 + 7
  s = (n**0.5)%mod
  for i in range(1, int(s)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors

p = []
for i in range(1, n+1):
  p += prime_factorize(i)

import collections
pc = collections.Counter(p)

a = 1
for v, c in pc.items():
  a *= c+1

mod = 10**9 +7
print(a%mod)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

count = 0
for x in range(k + 1):
  if x > k:
    continue
  for y in range(k + 1):
    if y > k:
      continue
    z = s - x - y
    if z < 0:
      continue
    if z > k:
      continue
    if (x + y + z) == s:
      count += 1

print(count)

Fixed submission:
k, s = map(int, input().split())

count = 0
for x in range(k + 1):
  for y in range(k + 1):
    z = s - x - y
    if z >= 0 and z <= k:
      count += 1

print(count)

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

count = 0
for x in range(k + 1):
  for y in range(k + 1):
    z = s - x - y
    if z < 0:
      continue
    if x > k or y > k or z > k:
      continue
    if (x + y + z) == s:
      count += 1

print(count)

Fixed submission:
k, s = map(int, input().split())

count = 0
for x in range(k + 1):
  for y in range(k + 1):
    z = s - x - y
    if z >= 0 and z <= k:
      count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())

l = []

if x <= y:
  l.appen(y-x)
  
if -x <= y:
  l.append(y + x + 1)
  
if x <= -y:
  l.append(-y-x+1)
  
if -x <= -y:
  l.append(-y+x+2)
  
print(min(l))

Fixed submission:
x, y = map(int, input().split())
l = []
if x <= y:
    l.append(y - x)
if -x <= y: # 最初に1回符号反転
    l.append(y + x + 1)
if x <= -y: # 最後に1回符号反転
    l.append(-y - x + 1)
if -x <= -y: # 両方符号反転
    l.append(-y + x + 2)

ans = min(l)
print(ans)

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

l = []

if x <= y:
  l.appen(y-x)
  
if -x <= y:
  l.append(y + x + 1)
  
if x <= -y:
  l.append(-y-x+1)
  
if -x <= -y:
  l.append(-y+x+2)
  
print(min(l))

Fixed submission:
x, y = map(int, input().split())
l = []
if x <= y:
    l.append(y - x)
if -x <= y: # 最初に1回符号反転
    l.append(y + x + 1)
if x <= -y: # 最後に1回符号反転
    l.append(-y - x + 1)
if -x <= -y: # 両方符号反転
    l.append(-y + x + 2)

ans = min(l)
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
length, count = list(map(int, input().split()))

words = []
for i in range(count):
  s = input()
  if len(s) != length:
    continue
  words.append(s)

words = sorted(words)

r = ''.join(words)
print(r)

Fixed submission:
# -*- coding: utf-8 -*-
count, length = list(map(int, input().split()))

words = []
for i in range(count):
  s = input()
  if len(s) != length:
    continue
  words.append(s)

words = sorted(words)

r = ''.join(words)
print(r)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
length, count = list(map(int, input().split()))

words = []
for i in range(count):
  words.append(input())

words = sorted(words)

r = ''.join(words)
print(r)

Fixed submission:
# -*- coding: utf-8 -*-
count, length = list(map(int, input().split()))

words = []
for i in range(count):
  s = input()
  if len(s) != length:
    continue
  words.append(s)

words = sorted(words)

r = ''.join(words)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def dfs(graph, N, start=0):
    visited = [False] * N
    visited[start] = True
    stack = [start]
    res = [start]
    while stack:
        index = stack.pop()
        for node in graph[index]:
            if not visited[node]:
                stack.append(node)
                visited[node] = True
                res.append(node)
    return res

def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(lambda i: int(i)-1, input().split())
        graph[A].append(B)
        graph[B].append(A)

    ans = 0
    for i in range(N):
        res = dfs(graph, N, start=i)
        ans = max(ans, len(res))

    print(ans)

main()

Fixed submission:
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, N):
        self.N = N
        self.r = [-1] * (N+1)

    def root(self, x):
        if (self.r[x] < 0):
            return x
        else:
            self.r[x] = self.root(self.r[x])
            return self.r[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.r[x] > self.r[y]:
            x, y = y, x
        self.r[x] += self.r[y]
        self.r[y] = x
        return True

    def size(self, x):
        return -self.r[self.root(x)]

    def same(self, x, y):
        return self.root(x) == self.root(y)

def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        A, B = map(lambda i: int(i)-1, input().split())
        uf.unite(A, B)

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

    print(ans)

main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())

    graph = [[] for i in range(N)]
    for i in range(M):
        A, B = map(lambda n: int(n) - 1, input().split())
        graph[A].append(B)
        graph[B].append(A)

    visited = bfs(graph, N, 0)[1:]
    if all(visited):
        print("Yes")
        print(*visited, seq="\n")
    else:
        print("No")


main()

Fixed submission:
from collections import deque
import sys
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())

    graph = [[] for _ in range(N)]
    for i in range(M):
        A, B = map(lambda n: int(n) - 1, input().split())
        graph[A].append(B)
        graph[B].append(A)

    visited = bfs(graph, N, 0)[1:]
    if all(visited):
        print("Yes")
        print(*visited, sep="\n")
    else:
        print("No")


main()