Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
h=list(map(int,input().split()))
c=[list(map(int,input().split()))for i in [0]*m]
k=0
for i in range(1,n+1):
    l=1
    for j in c:
        if i in j:
            a=j.index(i)
            if h[i-1]<=h[j[-a-1]-1]:
                l=0
                break
    k+=l
print(k)

Fixed submission:
n,m=map(int,input().split())
h=list(map(int,input().split()))
k=[]
for i in [0]*m:
    a,b=map(int,input().split())
    a-=1
    b-=1
    if h[a]==h[b]:
        k+=[a]+[b]
    if h[a]>h[b]:
        k+=[b]
    if h[a]<h[b]:
        k+=[a]
print(n-len(set(k)))
Buggy python submission (verdict: Time Limit Exceeded):
x=int(input())
a=0
while True:
    b=a**5-x
    if b<0:
        b=-((-b)**(1/5))
    else:
        b=b**(1/5)
    try:
        c=int(b)
    except:
        a+=1
    else:
        if b==c and a**5-c**5==x:
            print(str(a)+" "+str(c))
            break
        else:
            a+=1

Fixed submission:
x=int(input())
a=0
while True:
    b=a**5-x
    if b<0:
        b=-((-b)**(1/5))
    else:
        b=b**(1/5)
    c=int(b)
    if (a**5-c**5)==x:
        print(str(a)+" "+str(c))
        break
    a+=1
Buggy python submission (verdict: Runtime Error):
print(("1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(", "))[int(input())])

Fixed submission:
s="1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
n=int(input())
print((s.split(", "))[n-1])

Buggy python submission (verdict: Runtime Error):
print("1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(", ")[int(input())])

Fixed submission:
s="1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
n=int(input())
print((s.split(", "))[n-1])
Buggy python submission (verdict: Runtime Error):
b=map(int,input().split())
print((n//(a+b))*a+min([n%(a+b),a]))

Fixed submission:
n,a,b=map(int,input().split())
print(((n//(a+b))*a)+min([n%(a+b),a]))
Buggy python submission (verdict: Runtime Error):
import math
a,b=[int(i)for i in input().split()]
print(int(a*b/math.gcd(a,b)))

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
a,b=[int(i)for i in input().split()]
print(a*b//gcd(a,b))
Buggy python submission (verdict: Runtime Error):
m = input()
n = int(m.split()[0])
k = int(m.split()[1])
t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = None
for i in range(len(t)-k+1):
    w = abs(-1*t[i] + t[i+k])
    if i == 0:
        a = w
    elif a > w:
        a = w
print(a)

Fixed submission:
m = input()
n = int(m.split()[0])
k = int(m.split()[1])
t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = None
for i in range(len(t)-k+1):
    w = abs(-1*t[i] + t[i+k-1])
    if i == 0:
        a = w
    elif a > w:
        a = w
print(a)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
S = list(map(int, list(input())[: -1]))
pp = sum(S)
Xp = 0
Xm = 0
S.reverse()
for i in range(N):
  Xp += pow(2, i, pp + 1) * S[i]
  Xp %= pp + 1
  Xm += pow(2, i, pp - 1) * S[i]
  Xm %= pp - 1
#print(Xp, Xm)
rres = [0] * N
for i in range(N):
  res = 1
  if S[i]:
    X = (Xm - pow(2, i, pp - 1)) % (pp - 1)
    while X:
      c = bin(X).count("1")
      X %= c
      res += 1
  else:
    X = (Xp + pow(2, i, pp + 1)) % (pp + 1)
    while X:
      c = bin(X).count("1")
      X %= c
      res += 1
  rres[i] = res
rres.reverse()
for r in rres: print(r)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
S = list(map(int, list(input())[: -1]))
pp = sum(S)
Xp = 0
Xm = 0
S.reverse()
for i in range(N):
  Xp += pow(2, i, pp + 1) * S[i]
  Xp %= pp + 1
  Xm += pow(2, i, max(1, pp - 1)) * S[i]
  Xm %= max(1, pp - 1)
#print(Xp, Xm)
rres = [0] * N
for i in range(N):
  res = 1
  if S[i]:
    if pp == 1: res = 0
    else:
      X = (Xm - pow(2, i, max(1, pp - 1))) % max(1, pp - 1)
      while X:
        c = bin(X).count("1")
        X %= c
        res += 1
  else:
    X = (Xp + pow(2, i, pp + 1)) % (pp + 1)
    while X:
      c = bin(X).count("1")
      X %= c
      res += 1
  rres[i] = res
rres.reverse()
for r in rres: print(r)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
K = int(input())
S = list(input())[: -1]
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
###
f = Factorial(10 ** 5 * 3, mod)
res = 0
for i in range(K + 1):
  #i ko migi soto
  t = f.combi(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, mod) % mod
  t = t * pow(26, i, mod) % mod
  res += t
  res %= mod
print(res)

Fixed submission:
import sys
input = sys.stdin.readline
K = int(input())
S = list(input())[: -1]
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
###
f = Factorial(10 ** 6 * 3, mod)
res = 0
for i in range(K + 1):
  #i ko migi soto
  t = f.combi(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, mod) % mod
  t = t * pow(26, i, mod) % mod
  res += t
  res %= mod
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))

table = [0] * (max(a) + 1)
for x in a: table[x] += 1
#print(table)
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)

    #divisors.sort()
    return divisors

res = 0
for x in a:
  if table[x] > 1: continue
  for y in make_divisors(x):
    if x == y: continue
    if table[y]: break
  else: res += 1
print(res)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = max(a)
table = [0] * (mx + 1)
for x in a: table[x] += 1
#print(table)
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)

    #divisors.sort()
    return divisors

res = set(a)
#print(res)
for i in range(1, mx + 1):
  if table[i] == 0: continue
  for j in range(i, mx + 1, i):
    if i == j:
      if table[j] > 1:
        res.discard(j)
      continue
    if table[j]: res.discard(j)
print(len(res))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, S = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
a.sort()
#print(a)
dp = [0] * (S + 1)
dp[0] = 1
for i in range(N):
  for x in range(S, -1, -1):
    if dp[x] == 0: continue
    if x + a[i] <= S:
      dp[x + a[i]] += dp[x] * pow(2, mod - 2, mod)
      dp[x + a[i]] %= mod
print(dp[-1] * pow(2, N, mod) % mod)

Fixed submission:
import sys
input = sys.stdin.readline
N, S = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
#print(a)
dp = [0] * (S + 1)
dp[0] = 1
md = pow(2, mod - 2, mod)
for i in range(N):
  for x in range(S, -1, -1):
    if dp[x] == 0: continue
    if x + a[i] <= S:
      dp[x + a[i]] += dp[x] * md % mod
      dp[x + a[i]] %= mod
print(dp[-1] * pow(2, N, mod) % mod)
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
ls = [0] * N
rs = [0] * N
t = []
tt = []
for x in range(N):
  S = list(input())[: -1]
  for i in range(len(S)):
    if S[i] == "(": rs[x] += 1
    if S[i] == ")":
      if rs[x]: rs[x] -= 1
      else: ls[x] += 1
  t.append((ls[x], rs[x]))
  tt.append(ls[x])
t.sort()
tt.sort()
if sum(ls) != sum(rs):
  print("No")
  exit(0)
if sum(ls) == 0:
  print("Yes")
  exit(0)
l = 0
for i in range(N):
  if ls[i] == 0 and (rs[i] > 0): l |= 1
  if rs[i] == 0 and (ls[i] > 0): l |= 2
if l < 3:
  print("No")
  exit(0)
l = 0
c = 0
cc = 0
h = []
while cc < N:
  r = br(tt, l)
  i = c
  while i < r:
    hpush(h, t[i][0] - t[i][1])
    i += 1
  c = i
  l += -hpop(h)
  cc += 1
  if l < 0:
    print("No")
    exit(0)
print("Yes")

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
css = [0] * N
mns = [0] * N
t = [x for x in range(N)]
for x in range(N):
  S = list(input())[: -1]
  for i in range(len(S)):
    if S[i] == "(": css[x] += 1
    if S[i] == ")":
      css[x] -= 1
      mns[x] = min(mns[x], css[x])
if sum(css):
  print("No")
  exit(0)
t.sort(key = lambda x: -10 ** 7 if mns[x] == 0 else -10 ** 7 - mns[x] if css[x] >= 0 else mns[x] - css[x])
l = 0
for i in t:
  if l + mns[i] < 0:
    print("No")
    exit(0)
  l += css[i]
print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
res = []

def solve(l, r):
  global res
  if r <= l: return
  res.append((l, r))
  solve(l + 1, r - 1)


solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res: print(*r)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = map(int, input().split())
res = []

def solve(l, r):
  global res
  if r <= l: return
  res.append((l, r))
  solve(l + 1, r - 1)


solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res: print(*r)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
res = []
x = 1
vis = [0] * (N + 1)
while len(res) < M:
  if vis[x] or vis[((x + len(res)) % N) + 1]: x = (x % N) + 1
  else:
    vis[x] = 1
    vis[((x + len(res)) % N) + 1] = 1
    res.append((x, ((x + len(res)) % N) + 1))
    x = (x % N) + 1
  #print(x, res, vis)
for r in res: print(*r)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = map(int, input().split())
res = []

def solve(l, r):
  global res
  if r <= l: return
  res.append((l, r))
  solve(l + 1, r - 1)


solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res: print(*r)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort(reverse = True)
t = []
for _ in range(X): t.append(p.pop())
for _ in range(Y): t.append(q.pop())
t.sort()
for i in range(C):
  if t[i] < r[i]: t[i] = r[i]
print(sum(t))

Fixed submission:
import sys
input = sys.stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort(reverse = True)
t = []
for _ in range(X): t.append(p.pop())
for _ in range(Y): t.append(q.pop())
t.sort()
for i in range(min(C, X + Y)):
  if t[i] < r[i]: t[i] = r[i]
print(sum(t))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import combinations as combi
input = sys.stdin.readline
H, W, K = map(int, input().split())
S = [list(input())[: -1] for _ in range(H)]
cs = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
  for j in range(W): cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1")
res = H * W
#print(cs)
for t in range(H):
  for c in combi([x for x in range(H - 1)], t):
    l = 0
    tres = 0
    while l < W:
      ok = l
      ng = W + 1
      while ng - ok > 1:
        m = (ok + ng) // 2
        tt = 0
        i = 0
        ttt = 0
        while i < H:
          ttt += cs[i][m] - cs[i][l]
          if i in c:
            tt = max(tt, ttt)
            ttt = 0
          i += 1
        tt = max(tt, ttt)
        if tt <= K: ok = m
        else: ng = m
      l = ok
      tres += int(l < W)

    #print(c, tres)
    res = min(res, tres + len(c))
print(res)

Fixed submission:
import sys
from itertools import combinations as combi
input = sys.stdin.readline
H, W, K = map(int, input().split())
S = [list(input())[: -1] for _ in range(H)]
cs = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
  for j in range(W): cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1")
res = H * W
#print(cs)
for t in range(H):
  for c in combi([x for x in range(H - 1)], t):
    l = 0
    tres = 0
    while l < W:
      ok = l
      ng = W + 1
      while ng - ok > 1:
        m = (ok + ng) // 2
        tt = 0
        i = 0
        ttt = 0
        while i < H:
          ttt += cs[i][m] - cs[i][l]
          if i in c:
            tt = max(tt, ttt)
            ttt = 0
          i += 1
        tt = max(tt, ttt)
        if tt <= K: ok = m
        else: ng = m
      if l == ok:
        tres = H * W
        break
      l = ok
      tres += int(l < W)

    #print(c, tres)
    res = min(res, tres + len(c))
print(res)
Buggy python submission (verdict: Runtime Error):
-(-int(input())) // 2import sys
input = sys.stdin.readline
print(-(-int(input()) // 2))

Fixed submission:
import sys
input = sys.stdin.readline
print(-(-int(input()) // 2))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
print(-1)import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = float("inf")
for i in range(pow(2, N)):
  x = []
  l = []
  c = 0
  for j in range(N):
    if i & (1 << j):
      c += 1
      x.append((b[j], j))
    else:
      x.append((a[j], j))
  if c % 2: continue
  y = sorted(x, key = lambda x: x[0])
  z = -1
  #print(y, i)
  for j in range(N):
    t = abs(j - y[j][1])
    #print(i & (1 << y[j][1]) > 0, t)
    if i & (1 << j) > 0:
      if t % 2:
        z = max(z, t)
      else:
        z = -1
        break
    else:
      if t % 2 == 0:
        z = max(z, t)
      else:
        z = -1
        break
  if z == -1: continue
  z = 0
  for j in range(N):
    for k in range(j, len(x)):
      if x[k][0] == y[j][0]:
        x.pop(k)
        x.insert(0, (0, 0))
        z += k - j
        break
  res = min(res, z)

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

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
def check(i):
  x = []
  for j in range(N):
    if i & (1 << j):
      x.append(b[j])
    else:
      x.append(a[j])
  sx = sorted(x)
  odd = [0] * 51
  even = [0] * 51
  for j in range(N):
    odd[sx[j]] += j % 2
    even[sx[j]] += (j % 2 == 0)
  for j in range(N):
    if i & (1 << j):
      if j % 2: even[x[j]] -= 1
      else: odd[x[j]] -= 1
    else:
      if j % 2: odd[x[j]] -= 1
      else: even[x[j]] -= 1
  return min(min(odd), min(even)) >= 0
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 1)
    self.el = [0] * (n + 1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j = None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
res = float("inf")
for i in range(pow(2, N)):
  if check(i) == False: continue
  fwk = BIT(N)
  t = 0
  odd = []
  even = []
  for j in range(N):
    if i & (1 << j):
      if j % 2: even.append((b[j], j))
      else: odd.append((b[j], j))
    else:
      if j % 2: odd.append((a[j], j))
      else: even.append((a[j], j))
  #print(t, i)
  odd.sort(key = lambda x: x[0])
  even.sort(key = lambda x: x[0])
  ind = []
  #print(t, i)
  for j in range(N):
    if j % 2: ind.append(odd[j // 2][1])
    else: ind.append(even[j // 2][1])
  #print(t, i, ind)
  for x in ind:
    t += fwk.get(x, N)
    fwk.add(x + 1, 1)
  res = min(res, t)
  #print(t, i)
if res == float("inf"): print(-1)
else: print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import sqrt
input = sys.stdin.readline
N = int(input())
ps = [tuple(map(int, input().split())) for _ in range(N)]
rang = 0
for t in ps:
  rang = max(rang, abs(t[0]), abs(t[1]))
def calc(x, y):
  res = 0
  for t in ps:
    u, v = t
    res = max(res, sqrt((x - u) ** 2 + (y - v) ** 2))
  return res

x0 = -1000
x3 = 1000
x1 = (x0 * 2 + x3) / 3
x2 = (x0 + x3 * 2) / 3
res = float("inf")
xl = 0
yl = 0
for i in range(0, rang * 2 + 1, 10):
  u = i - rang
  for j in range(0, rang * 2 + 1, 10):
    v = j - rang
    if calc(xl, yl) > calc(u, v):
      xl = u
      yl = v
x0 = xl - 10
x3 = xl + 10
while x3 - x0 > 0.1 ** 12:
  x1 = (x0 * 2 + x3) / 3
  x2 = (x0 + x3 * 2) / 3

  cc1 = 0
  cc2 = 0

  y0 = yl - 10
  y3 = yl + 10
  y1 = (y0 * 2 + y3) / 3
  y2 = (y0 + y3 * 2) / 3

  while y3 - y0 > 0.1 ** 12:
    y1 = (y0 * 2 + y3) / 3
    y2 = (y0 + y3 * 2) / 3
    c1 = calc(x1, y1)
    c2 = calc(x1, y2)
    if c1 < c2: y3 = y2
    else: y0 = y1

  cy1 = y1 + 0

  y0 = yl - 10
  y3 = yl + 10
  y1 = (y0 * 2 + y3) / 3
  y2 = (y0 + y3 * 2) / 3

  while y3 - y0 > 0.1 ** 12:
    y1 = (y0 * 2 + y3) / 3
    y2 = (y0 + y3 * 2) / 3
    c1 = calc(x2, y1)
    c2 = calc(x2, y2)
    if c1 < c2: y3 = y2
    else: y0 = y1

  cy2 = y1 + 0

  cc1 = calc(x1, cy1)
  cc2 = calc(x2, cy2)
  if cc1 < cc2: x3 = x2
  else: x0 = x1
  res = min(cc1, cc2)

print(res)

Fixed submission:
import sys
from math import sqrt
input = sys.stdin.readline
N = int(input())
ps = [tuple(map(int, input().split())) for _ in range(N)]
rang = 0
for t in ps:
  rang = max(rang, abs(t[0]), abs(t[1]))
def calc(x, y):
  res = 0
  for t in ps:
    u, v = t
    res = max(res, sqrt((x - u) ** 2 + (y - v) ** 2))
  return res

x0 = -1000
x3 = 1000
x1 = (x0 * 2 + x3) / 3
x2 = (x0 + x3 * 2) / 3
res = float("inf")
xl = 0
yl = 0
for i in range(0, rang * 2 + 1, 10):
  u = i - rang
  for j in range(0, rang * 2 + 1, 10):
    v = j - rang
    if calc(xl, yl) > calc(u, v):
      xl = u
      yl = v
x0 = xl - 10
x3 = xl + 10
while x3 - x0 > 0.1 ** 12:
  x1 = (x0 * 2 + x3) / 3
  x2 = (x0 + x3 * 2) / 3

  cc1 = 0
  cc2 = 0

  y0 = yl - 10
  y3 = yl + 10
  y1 = (y0 * 2 + y3) / 3
  y2 = (y0 + y3 * 2) / 3

  while y3 - y0 > 0.1 ** 12:
    y1 = (y0 * 2 + y3) / 3
    y2 = (y0 + y3 * 2) / 3
    c1 = calc(x1, y1)
    c2 = calc(x1, y2)
    if c1 < c2: y3 = y2
    else: y0 = y1

  cy1 = y1 + 0

  y0 = yl - 10
  y3 = yl + 10
  y1 = (y0 * 2 + y3) / 3
  y2 = (y0 + y3 * 2) / 3

  while y3 - y0 > 0.1 ** 12:
    y1 = (y0 * 2 + y3) / 3
    y2 = (y0 + y3 * 2) / 3
    c1 = calc(x2, y1)
    c2 = calc(x2, y2)
    if c1 < c2: y3 = y2
    else: y0 = y1

  cy2 = y1 + 0

  cc1 = calc(x1, cy1)
  cc2 = calc(x2, cy2)
  if cc1 < cc2: x3 = x2
  else: x0 = x1
  res = min(cc1, cc2)

print(res)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
N, u, v = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  a, b = map(int, input().split())
  e[a].append((b, 1))
  e[b].append((a, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
d = dijkstra(N, e)
p = d.path(v, 0)
pp = d.path(u, 0)
#print(p)
#print(pp)
res = 0
vis = [0] * (N + 1)
def dfs(x):
  global vis
  r = 0
  if p[x] >= pp[x]: r = p[x] - ((p[x] - pp[x]) % 2)
  if p[x] <= pp[x]: return r
  for y in e[x]:
    if vis[y[0]] == 1: continue
    vis[y[0]] = 1
    r = max(r, dfs(y[0]))
  #print(r, x)
  return r
res = dfs(u)
for x in e[u]:
  if p[x[0]] > pp[x[0]]: 
    print(res)
    exit(0)
print(1)

Fixed submission:
import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
N, u, v = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  a, b = map(int, input().split())
  e[a].append((b, 1))
  e[b].append((a, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
d = dijkstra(N, e)
p = d.path(v, 0)
pp = d.path(u, 0)
#print(p)
#print(pp)
res = 0
for i in range(1, N + 1):
  if p[i] > pp[i]: res = max(p[i], res)
print(res - 1)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
for i in range(N - 1):
  u, v = map(int, input().split())
  e[u].append((v, i))
  e[v].append((u, i))
res = [0] * (N - 1)
def dfs(x):
  global res
  c = 1
  vis = set()
  for y, i in e[x]: vis.add(res[i])
  #print(x, vis)
  for y, i in e[x]:
    if res[i] > 0: continue
    while c in vis: c += 1
    #print(x, c)
    res[i] = c
    vis.add(c)
    dfs(y)
dfs(1)
print(max(res))
for r in res: print(r)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
for i in range(N - 1):
  a, b = tuple(map(int, input().split()))
  e[a].append((b, i))
  e[b].append((a, i))
res = [0] * (N - 1)
vis = set()
def dfs(x):
  global vis
  global res
  viss = set()
  svis = set()
  t = 1
  for y, i in e[x]:
    if i in vis: viss.add(res[i])
  #print(x, viss)
  for y, i in e[x]:
    #print(x, y, t)
    while t in viss:
      t += 1
    if i in vis:
      continue
    #print(x, y, t)
    svis.add(y)
    vis.add(i)
    res[i] = t
    t += 1
  for y in svis:
    dfs(y)
  #print(res)
dfs(1)
print(max(res))
for r in res: print(r)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
for i in range(N - 1):
  a, b = tuple(map(int, input().split()))
  e[a].append((b, i))
  e[b].append((a, i))
res = [0] * (N - 1)
vis = set()
def dfs(x):
  global vis
  global res
  viss = set()
  t = 1
  for y, i in e[x]:
    if i in vis: viss.add(res[i])
  for y, i in e[x]:
    if i in vis:
      while t in viss:
        t += 1
      continue
    vis.add(i)
    res[i] = t
    t += 1
    dfs(y)
dfs(1)
print(max(res))
for r in res: print(r)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
e = dd(list)
for i in range(N - 1):
  a, b = tuple(map(int, input().split()))
  e[a].append((b, i))
  e[b].append((a, i))
res = [0] * (N - 1)
vis = set()
def dfs(x):
  global vis
  global res
  viss = set()
  svis = set()
  t = 1
  for y, i in e[x]:
    if i in vis: viss.add(res[i])
  #print(x, viss)
  for y, i in e[x]:
    #print(x, y, t)
    while t in viss:
      t += 1
    if i in vis:
      continue
    #print(x, y, t)
    svis.add(y)
    vis.add(i)
    res[i] = t
    t += 1
  for y in svis:
    dfs(y)
  #print(res)
dfs(1)
print(max(res))
for r in res: print(r)