Harryxun/stf_run huggingface dataset:
import random
import sys

sys.setrecursionlimit(10000)

n, m = map(int, input().split())
# n, m = 200000, 200000
group = {i: 0 for i in range(1, n+1)}
edge = {}
g_mem = {}
g_num = 0
g_con = set()

for i in range(m):
    a, b = map(int, input().split())
    # a, b = random.sample(range(1,n+1), 2)
    if group[a]==0 and group[b] == 0:
        g_num += 1
        group[a] = g_num
        group[b] = g_num
        g_mem[g_num] = 2
    elif group[a] == 0:
        group[a] = group[b]
        g_mem[group[b]] += 1
    elif group[b] == 0:
        group[b] = group[a]
        g_mem[group[a]] += 1
    elif group[a] != group[b]:
        if edge.get(group[a]):
            edge[group[a]].add(group[b])
        else:
            edge[group[a]] = {group[b]}
        if edge.get(group[b]):
            edge[group[b]].add(group[a])
        else:
            edge[group[b]] = {group[a]}

# print(g_mem)
# print(sum(g_mem.values()))
# print(edge)

g_reached = {i: 0 for i in range(1, g_num+1)}

def dps(g_mem, edge, now):
    count = g_mem[now]
    if edge.get(now):
        for e in edge[now]:
            if g_reached[e] == 0:
                g_reached[e] = 1
                count += dps(g_mem, edge, e)
    return count


ans = []
for now in range(1, g_num+1):
    if g_reached[now] == 0:
        g_reached[now] = 1
        ans.append(dps(g_mem, edge, now))

# print(ans)
print(max(ans))


### FIXED CODE ###

import random
import sys

n, m = map(int, input().split())
# n, m = 200000, 200000
group = {i: 0 for i in range(1, n+1)}
edge = {}
g_mem = {}
g_num = 0
g_con = set()

for i in range(m):
    a, b = map(int, input().split())
    # a, b = random.sample(range(1,n+1), 2)
    if group[a]==0 and group[b] == 0:
        g_num += 1
        group[a] = g_num
        group[b] = g_num
        g_mem[g_num] = 2
    elif group[a] == 0:
        group[a] = group[b]
        g_mem[group[b]] += 1
    elif group[b] == 0:
        group[b] = group[a]
        g_mem[group[a]] += 1
    elif group[a] != group[b]:
        if edge.get(group[a]):
            edge[group[a]].add(group[b])
        else:
            edge[group[a]] = {group[b]}
        if edge.get(group[b]):
            edge[group[b]].add(group[a])
        else:
            edge[group[b]] = {group[a]}

# print(g_mem)
# print(sum(g_mem.values()))
# print(edge)

g_reached = {i: 0 for i in range(1, g_num+1)}
ans = list(g_mem.values())
for now in range(1, g_num+1):
    if g_reached[now] == 0:
        g_reached[now] = 1
        if edge.get(now):
            count = g_mem[now]
            queue = set(edge[now])
            while len(queue) > 0:
                next_now = queue.pop()
                if g_reached[next_now] == 0:
                    g_reached[next_now] = 1
                    count += g_mem[next_now]
                    queue |= edge[next_now]
                queue -= {now}
                now = next_now
            ans.append(count)


# print(ans)
if len(ans) > 0:
    print(max(ans))
else:
    print(1)
a,b,k=map(int,input().split())
A=a
B=b
K=k

if a>=k:
    A=a-k
    print(A,B)
if a<k:
    B=b-(k-a)
    A=0
    if k-a>=b:
        B=0
    print(A,B)
else:
    A,B=0
    print(A,B)

### FIXED CODE ###

a,b,k=map(int,input().split())
#食べられた後のa
A=a
#食べられた後のb
B=b
K=k

if a>=k:
    A=a-k
    print(A,B)
elif a<k:
    B=b-(k-a)
    A=0
    if k-a>=b:
        B=0
    print(A,B)
else:
    A=0
    B=0
    print(A,B)
a, b = int(input())
for c in range(1, 4):
    if (a * b * c) % 2 == 1:
        print('Yes')
        exit()
print('No')

### FIXED CODE ###

a, b = map(int, input().split())
for c in range(1, 4):
    if (a * b * c) % 2 == 1:
        print('Yes')
        exit()
print('No')
s=input()
x=1e9
for i in range(len(s)):
 if i=='A':x=min(x,i)
 if i=='Z':y=i
print(y-x+1)

### FIXED CODE ###

x=1e9
for j,i in enumerate(input()):
 if i=='A':x=min(x,j)
 if i=='Z':y=j
print(y-x+1)
N=int(input())
print(f"ABC{N:03}" if N<=999 else f"ABD{N-999:03}")

### FIXED CODE ###

N=int(input())
print('ABC' if N<=999 else 'ABD')
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ

N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

# 深さ優先探索
def dfs(g,v,c):
    if color[v]==-1:
        color[v] = c
        for nv, w in g[v]:
            if color[nv]==-1:
                nc = c
                if w!=0:
                    nc = 1-c
                dfs(g,nv,nc)

def main():
    dfs(graph, 0, 1)
    for i in color:
        print(i)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)
A, B = map(int, input().split())

if A > b:
  print('Alice')
elif A < B:
  print('Bob')
else:
  print('Draw')

### FIXED CODE ###

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

if A == 1:
  A = 14
if B == 1:
  B = 14
 
if A > B:
  print('Alice')
elif A < B:
  print('Bob')
else:
  print('Draw')
N = int(input())
num = (N-2)**(0.5)
if N == 3:
  print("Yes")
  A = [2, 1, 2]; print(*A)
  A = [2, 2, 3]; print(*A)
  A = [2, 3, 1]; print(*A); exit()
if num%1 != 0:
  print("No");exit()
num = int(num)
ans = []
for i in range(num):
  temp = [1] + [2+j+num*i for j in range(num)]
  ans.append(temp)
for i in range(num):
  temp = [2+i+num*j for j in range(num)] + [N]
  ans.append(temp)
print("Yes")
for x in ans:
  ret = [num+1] + x
  print(*ret)

### FIXED CODE ###

N = int(input())
MAX = 450
A = [[1],[1]] #size = 2
#A = [[1,2],[2,3],[3.1]]
size = 0
for i in range(1,MAX):
  if i*(i+1)//2 == N:
    size = i+1
    break
if size == 0:
  print("No")
  exit()
now = 2
while now < size:
  start = now*(now-1)//2+1
  last = [start+i for i in range(now)]
  for j in range(len(A)):
    A[j].append(last[j])
  A.append(last)
  now += 1
print("Yes")
print(len(A))
#ini = [len(A)-1]
for x in A:
  x.insert(0,len(A)-1)
  print(*x)
n=int(input('enter number'))
def doublefactorial(n): 
    if (n == 0 or n == 1): 
        return 1; 
    return n * doublefactorial(n - 2);

def trailing_zeros(longint):
    manipulandum = str(longint)
    return len(manipulandum)-len(manipulandum.rstrip('0'))
  

print(trailing_zeros(doublefactorial(n)))

### FIXED CODE ###

def findTrailingZeros(n): 
      
    if (n%2!=0): 
        return 0

    else: 
        ans = 0
        n //= 2
        while (n): 
            ans += n // 5
            n //= 5
  
        return ans 
  
n = int(input())
  
print(findTrailingZeros(n))
import math

s = input().split()
a, b = int(s[0]), int(s[1])


def lcm(x, y):
    return int((x * y) / math.gcd(x, y))


print(lcm(a, b))


### FIXED CODE ###

import fractions
a,b=map(int, input().split())
f=fractions.gcd(a,b)
f2=a*b//f
print(f2)
# C - Welcome to AtCoder
# https://atcoder.jp/contests/abc151/tasks/abc151_c

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

# 問題数分配列を作成 -> 正解判定用の関数
ac = [False] * N
wa = [0] * N

# まずはテーブルを作成する
for i in range(m):
    p, s = input().split()
    p = int(p)

    if p == "AC":
        # 正解したことのある問題か確認
        ac[i] = True
    else:
        if ac[i] == False:
            wa[i] += 1

ac_cnt = 0
wa_cnt = 0

for i in range(n):
    if ac[i] == True:
        ac_cnt += 1
        wa_cnt += wa[i]

print(ac_cnt,wa_cnt)






### FIXED CODE ###

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

ac = [False] * N
wa = [0] * N
for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == 'AC':
        ac[p] = True
    else:
        if not ac[p]:
            wa[p] += 1

a = 0
b = 0
for i in range(N):
    if ac[i]:
        a += 1
        b += wa[i]
print(*[a, b])
import math

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

for i in range(1, k+1):
	red_order = math.factorial(n - k + 1) / (math.factorial(n - k + 1 - i) * math.factorial(i))
	blue_order = math.factorial(k - 1) / (math.factorial(k - 1 - (i - 1)) * math.factorial(i - 1))
	print(int(red_order*blue_order%1000000007))

### FIXED CODE ###

import math

N, K = input().split()
N = int(N)
K = int(K)
m = N - K
mod = 10**9+7

def factorial_m(N: int, M: int):
	res = 1
	for i in range(2, N+1):
		res *= i
		res %= M
	return res

def nCr(n, r, mod):
	if n == r:
		return 1
	elif r > n:
		return 0
	return (factorial_m(n, mod) * pow((factorial_m(n-r, mod) * factorial_m(r, mod)), mod-2, mod)) % mod

for i in range(1, K+1):
	print(nCr(N-K+1, i, mod) * nCr(K-1, i-1, mod) % mod)
n = int(input())
a = [i for i in int(input().split())]
for  i in range(1,n+1):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1
    a[j] = v
    print(*a)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1

    a[j+1] = v
    print(*a)
def get_sieve_of_eratosthenes(n):
    prime = [2]
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
print(get_sieve_of_eratosthenes(int(input())[-1])

### FIXED CODE ###

def is_prime(n):
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
n=int(input())
while not is_prime(n):
  n+=1
print(n)
n = int(input())
x = list(map(int, input().split()))

def fact(m):
  return m * fact(m-1) if m != 1 else 1

d = [x[i+1] - x[i] for i in range(n - 1)]
fact_n_1 = fact(n-1)
print(sum(sum(fact_n_1 // (j + 1) 
              for j 
              in range(i + 1)) * d_i % 1000000007
          for i, d_i 
          in enumerate(d)) % 1000000007 ) 

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]

def pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

def fact(m):
  return m * fact(m-1) % 1000000007 if m != 1 else 1
 
fact_n_1 = fact(n-1)

e = [None] * (n-1)
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = (e[i - 1] + fact_n_1 * pow(i + 1, 1000000005)) % 1000000007

print(sum(e_i * d_i % 1000000007
          for i, (d_i, e_i) 
          in enumerate(zip(d, e))) % 1000000007 )
a,b = map(int,input().split())

men = a*b
hen = 2*(a+b)

print(men+" "+hen)


### FIXED CODE ###

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

men = a*b
hen = 2*(a+b)

print(men,hen,sep=" ")
f = [False for i in range(100001)]
c = [0 for i in range(100001)]

for i in xrange(2, 100001):
    if not f[i]:
        for j in range(2*i, 100001, i):
            f[j] = True
for i in xrange(3, 100001, 2):
    if not f[i] and not f[int((i+1)/2)]:
        c[i] += 1
for i in xrange(3, 100001):
    c[i] += c[i-1]
    
n = int(input())
while n:
    l, r = list(map(int, input().split()))
    print (c[r]-c[l-1])
    n -= 1


### FIXED CODE ###

f = [False for i in range(100001)]
c = [0 for i in range(100001)]

for i in range(2, 100001):
    if not f[i]:
        for j in range(2*i, 100001, i):
            f[j] = True
for i in range(3, 100001, 2):
    if not f[i] and not f[int((i+1)/2)]:
        c[i] += 1
for i in range(3, 100001):
    c[i] += c[i-1]
    
n = int(input())
while n:
    l, r = list(map(int, input().split()))
    print (c[r]-c[l-1])
    n -= 1
s=input()
n=len(s)
def p(s):
  return s==s[::-1]
if p(s[:(n-1)//2]):
  if p(s[(n+1)//2:]):
    print('Yes')
   else:
    print('No')
print('No')

### FIXED CODE ###

s=input()
n=len(s)
def p(s):
  return s==s[::-1]
if p(s):
  if p(s[:(n-1)//2]):
    if p(s[(n+1)//2:]):
      print('Yes')
      exit()
    else:
      print('No')
      exit()
print('No')
n = int(input())

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

print(p % (10**9 + 7)

### FIXED CODE ###

import math
n = int(input())

print(math.factorial(n) % (10**9+7))
n=int(input())
from collections import deque
q=deque([])
i=0
while True:
  if i<=8:
    q.append(i+1)
    i+=1
    if i==k:break
    continue
  
  x=q.popleft()
  
  if x%10!=0:
    q.append(x*10+x%10-1)
    i+=1
    if i==k:break
    
  q.append(x*10+x%10)
  i+=1
  if i==k:break
  
  if x%10!=9:
    q.append(x*10+x%10+1)
    i+=1
    if i==k:break
      
print(q.pop())

### FIXED CODE ###

k=int(input())
from collections import deque
q=deque([])
i=0
while True:
  if i<=8:
    q.append(i+1)
    i+=1
    if i==k:break
    continue
  
  x=q.popleft()
  
  if x%10!=0:
    q.append(x*10+x%10-1)
    i+=1
    if i==k:break
    
  q.append(x*10+x%10)
  i+=1
  if i==k:break
  
  if x%10!=9:
    q.append(x*10+x%10+1)
    i+=1
    if i==k:break
      
print(q.pop())
n,m=map(int,input().split())
points=list(map(int,input().split()))
points.sort()
#print(points)

sas=[]
for i in range(0,m-1):
  sas.append(points[i+1]-points[i])
  
#print(sas)

score=0
score=max(points)-min(points)

if sas==[]:
  print(0)
  exit()

for j in range(0,n-1):
  score-=max(sas)
  sas.remove(max(sas))

print(score)

### FIXED CODE ###

n,m=map(int,input().split(" "))
points=list(map(int,input().split(" ")))
points.sort()
score=0
#score=points[-1]-points[0]
sas=[]

for i in range(0,m-1):
  sas.append(points[i+1]-points[i])
sas.sort()

#score-=sum(sas[-n+1:]) 
if n>=m:
  print(0)
  exit()
else:
  print(sum(sas[:m-n]))
import collections

#入力
H, W = map(int, input().split())

#lst = [['a']*W for _ in range(H)]
count = 0 #白色のマスの総数
lst = []
row = []
for i in range(H):
    row = list(input())
    count += row.count('.')
    lst += [row]
 
#for i in range(H):
#    for j in range(W):
#        if lst[i][j] == '.':
#            count += 1

sx, sy = 1, 1 #スタート位置
gx, gy = H, W #ゴール位置

move = [[-1, 0], [1,0], [0, -1], [0, 1]]

def bfs():
    q = collections.deque()
    INF = 10 ** 9
    d = [[INF]* W for _ in range(H)]
    q.append(0)
    q.append(0)
    d[0][0] = 0

    while True:
        if q.empty():
            break
        px = q.popleft()
        py = q.popleft()
        if px == gx-1 and py == gy-1:
            break
        else:
            for dx, dy in move:
                nx = px + dx
                ny = py + dy

                if 0 <= nx and nx < H and 0 <= ny and ny < W and lst[nx][ny] == '.' and d[nx][ny] == INF:
                    q.append(nx)
                    q.append(ny)
                    d[nx][ny] = d[px][py] + 1
    return d[gx-1][gy-1]

a = bfs()

if a == 10 **9:
    print (-1)
else:
    print (count - a - 1)

### FIXED CODE ###

from queue import Queue

#入力
H, W = map(int, input().split())

#lst = [['a']*W for _ in range(H)]
count = 0 #白色のマスの総数
lst = []
row = []
for i in range(H):
    row = list(input())
    count += row.count('.')
    lst += [row]
 
#for i in range(H):
#    for j in range(W):
#        if lst[i][j] == '.':
#            count += 1

#sx, sy = 1, 1 #スタート位置
#gx, gy = H, W #ゴール位置

move = [[-1, 0], [1,0], [0, -1], [0, 1]]

def bfs():
    q = Queue()
    INF = 10 ** 9
    d = [[INF]* W for _ in range(H)]
    q.put(0)
    q.put(0)
    d[0][0] = 0

    while True:
        if q.empty():
            break
        else:
            px = q.get()
            py = q.get()
            if px == H-1 and py == W-1:
                break
            else:
                for dx, dy in move:
                    nx = px + dx
                    ny = py + dy

                    if 0 <= nx and nx < H and 0 <= ny and ny < W and lst[nx][ny] == '.' and d[nx][ny] == INF:
                        q.put(nx)
                        q.put(ny)
                        d[nx][ny] = d[px][py] + 1
    return d[H-1][W-1]

a = bfs()

if a == 10 **9:
    print (-1)
else:
    print (count - a - 1)
N, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
  print(N)
else:
  sort(a)
  while sum(a) > x:
    a.remove(max(a))
  print(len(l))


### FIXED CODE ###

N, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
  print(N)
else:
  while sum(a) > x:
    a.remove(max(a))
  l = len(a)
  if l == N:
    print(l - 1)
  else:
    print(l)
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
l=[abs(i) for i in l]
sm=sum(l[:k])
mini=min(mini,sm)
for i in range(k,n):
    sm=sm-l[i-k]
    sm+=l[i]
    mini=min(mini,sm)
print(mini)

### FIXED CODE ###

n,k=map(int,input().split())
l=[int(i) for i in input().split()]
right=[i for i in l if i>0]
left=[i for i in l if i<=0]
if not left: 
    sm=0 
    sm+=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
if not right: 
    sm=0 
    l=[abs(i) for i in l]
    l.sort()
    sm=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
le=len(left)
ri=len(right)
rl=[0]*le 
rr=[0]*ri 
left=[abs(i) for i in left]
left=left[::-1]
rl[0]=left[0]
for i in range(1,le):
    rl[i]=rl[i-1]+(left[i]-left[i-1])
rr[0]=right[0]
mini=10**20 
for i in range(1,ri) :
    rr[i]=rr[i-1]+(right[i]-right[i-1])
if len(left)>=k:
    mini=min(mini,rl[k-1])
if len(right)>=k:
    mini=min(mini,rr[k-1])
#print(left,right,rl,rr)
for a in range(1,len(left)+1):
    b=k-a 
    #print(a,b)
    if b>len(rr):
        #print('hsef')
        continue 
    mini=min(mini,2*rl[a-1]+rr[b-1],rl[a-1]+2*rr[b-1])
print(mini)
#!/usr/bin/env python3
import sys
from collections import Counter
readline = sys.stdin.buffer.readline # 一行読み込み

n=int(input())
s=["".join(readline().rstrip()) for _ in range(n)]
print(s)

counter = Counter(s)
max_cnt = max(counter.values())
names = [name for name, cnt in counter.items() if cnt == max_cnt]
names.sort()

print(*names, sep='\n')

### FIXED CODE ###

from collections import Counter

stdin = open(0)
N = int(stdin.readline())
S = stdin.read().split()

counter = Counter(S)
max_cnt = max(counter.values())
names = [name for name, cnt in counter.items() if cnt == max_cnt]
names.sort()

print(*names, sep='\n')
N,M,K=list(map(int,input().split()))

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


def readAB(ia,ib,left_k,nbooks):
    global N,M,nmax

    # print(ia,ib,left_k,N,M,nbooks)

    if nbooks > nmax:
        nmax = nbooks

    if  ia <= N-1 and left_k >= A[ia]:
        # print("A")
        readAB(ia+1,ib,left_k-A[ia],nbooks+1)

    if ib <= M-1 and left_k >= B[ib]:
        # print("B")
        readAB(ia,ib+1,left_k-B[ib],nbooks+1)

nmax=0
readAB(0,0,K,0)
print(nmax)

### FIXED CODE ###

import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)

            break

print(nmax)
import sys

n=int(input())
aa=list(map(int,input().split()))

cnt=0
while 1:
  for i in range(n):
    if aa[i]%2>0
      print(cnt)
      sys.exit()
    aa[i]=aa[i]//2
  cnt+=1

### FIXED CODE ###

import sys

n=int(input())
aa=list(map(int,input().split()))

cnt=0
while 1:
  for i in range(n):
    if aa[i]%2>0:
      print(cnt)
      sys.exit()
    aa[i]=aa[i]//2
  cnt+=1
(L + N - 1)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

ans = 0
for i in range(N):
    ans = ans + L + i

if L > 0:
    ans = ans - L
if (L + N - 1) < 0:
    ans = ans - (L + N - 1)

print(ans)
a,b=map(int,input().split())
if a-2b>0:
  print(a-2b)
else:
  print(0)

### FIXED CODE ###

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

if a-2*b>0:
  print(a-2*b)
else:
  print(0)
n,u,v = map(int,input().split())
edge = [[] for i in range(n+1)]
distt = [0 for i in range(n+1)]
dista = [0 for i in range(n+1)]

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

def tdfs(x, last = -1):
    for to in edge[x]:
        if(to == last):continue
        distt[to] = distt[x] + 1
        tdfs(to, x)

def adfs(x, last = -1):
    for to in edge[x]:
        if(to == last):continue
        dista[to] = dista[x] + 1
        adfs(to, x)

tdfs(u)
adfs(v)
ans = 0

for i in range(1, n+1):
    if distt[i] >= dista[i]:continue
    l = distt[i]
    k = dista[i] - distt[i]
    ans = max(ans, k - 1 + l)

print(ans)

### FIXED CODE ###

import sys

sys.setrecursionlimit(200000)
n,u,v = map(int,input().split())
edge = [[] for i in range(n+1)]
distt = [0 for i in range(n+1)]
dista = [0 for i in range(n+1)]

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

def tdfs(x, last = -1):
    for to in edge[x]:
        if(to == last):continue
        distt[to] = distt[x] + 1
        tdfs(to, x)

def adfs(x, last = -1):
    for to in edge[x]:
        if(to == last):continue
        dista[to] = dista[x] + 1
        adfs(to, x)

tdfs(u)
adfs(v)
ans = 0

for i in range(1, n+1):
    if distt[i] >= dista[i]:continue
    l = distt[i]
    k = dista[i] - distt[i]
    ans = max(ans, k - 1 + l)

print(ans)
N = int(input())
minstep = 9999999999999999999999999999999
for i in range(int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, N+i-2)
print(minstep)

### FIXED CODE ###

N = int(input())
minstep = 9999999999999999999999999999999
for i in range(1, int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, i+N//i-2)
print(minstep)
lock_num = input().split()
lock_num = [int(x) for x in lock_num]
tag = 0
for i in range(len(lock_num)-1):
  if lock_num[i] == lock_num[i+1]:
    tag = 1
if tag == 0:
  print("Good")
else tag ==1:
  print("Bad")

### FIXED CODE ###

lock_num = input()
#lock_num = [int(x) for x in lock_num]
tag = 0
for i in range(3):
  if int(lock_num[i]) == int(lock_num[i+1]):
    tag = 1
    break
if tag == 0:
  print("Good")
else:
  print("Bad")
def kake(b,c):
    return b * c

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

A = 1
for i in range(n):
    kake(A,a[i])

if A>1000000000000000000:
        print(-1)
else:
    print(A)

### FIXED CODE ###

A,B = input().split()
A = int(A)
B = int(B)
print(A*B)
a = int(input())
b = int(input())
avg = (a+b) /2
if (avg*10)%10 == 0:
  print(avg)
else:
  print(avg+1)

### FIXED CODE ###

a, b = map(int, input().split())
avg = (a+b) /2
ans = avg*10 // 10
if (avg*10)%10 == 0:
  print(int(ans))
else:
  print(int(ans+1))
import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

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

p(N)
p(Y)

Amax=min(N,Y//10000)
Bmax=min(N,Y//5000)
Cmax=min(N,Y//1000)

p(Amax)
p(Bmax)
p(Cmax)

for a in range(Amax,-1,-1):
  B=min(Bmax,N-a)
  p("B="+str(B))
  for b in range(B,-1,-1):
    C=min(Cmax,N-a-b)
    p("a="+str(a)+", B="+str(B)+", C="+str(C))
    for c in range(C,-1,-1):
      n = a+b+c
      y = (a*10000)+(b*5000)+(c*1000)
      if n==N and y==Y:
        print(a,b,c,sep=" ")
        exit(1)

i=-1
print(i,i,i, sep="")


### FIXED CODE ###

import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

N,Y=map(int, input().split())
p(N,Y)

NAmax=min(N,Y//10000)
NBmax=min(N,Y//5000)
NCmax=min(N,Y//1000)
p(NAmax, NBmax, NCmax)

NA=NAmax
for a in range(NA,-1,-1):
  NB=min(NBmax,N-a)

  for b in range(NB,-1,-1):
    c = N-a-b
    y = (a*10000)+(b*5000)+(c*1000)
    if y==Y:
      print(a,b,c,sep=" ")
      exit()
      
i=-1
print(i,i,i, sep=" ")