Harryxun/stf_run huggingface dataset:
N, K = list(map(int, input().split()))


def check(k, hs, s):
    if k == 0:
        return max(s) - min(s)
    r = []
    for i, h in enumerate(hs):
        s.append(h)
        hs.remove(h)
        r.append(check(k - 1, hs, s[::]))
        s.pop(-1)
        hs.insert(i, h)
    return min(r)


def main():
    hs = [int(input()) for i in range(N)]
    print(check(K, hs, []))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, K = list(map(int, input().split()))
    hs = [int(input()) for i in range(N)]
    hs.sort()
    i = 0
    r = 10 ** 9
    while True:
        if i + K > N:
            break
        r = min(r, hs[i + K - 1] - hs[i])
        i += 1
    print(r)


if __name__ == '__main__':
    main()
D = int(input())
date_dict = {25: "Christmas", 
24: "Christmas Eve",
23: "Christmas Eve Eve", 
22: "Christmas Eve Eve Eve"}

print(date_dict(D))


### FIXED CODE ###

D = int(input())
if D == 25:
    print("Christmas")
elif D == 24:
    print("Christmas Eve")
elif D == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")
A,B,X=map(int,input().split())
X=min(10**9,(X-B)//A+1)
for  i in range(X):
  d=len(str(X-i))
  if A*(X-i)+B*d<=X:
    ans=X-i
    break
  if i==X-1:
    ans=0
print(ans)

### FIXED CODE ###

S=str(input())
list=["SUN","MON","TUE","WED","THU","FRI","SAT"]
for i in range(7):
  if S==list[i]:
    print(7-i)
N = int(input())
H = list(map(int, input().split()))
ans = 0
for i in range(N-1) :
    for k in range(i+1, N):
        if s[i] - s[k] > 1 :
            print('No')
            ans = 1
            exit()
if ans == 0:
    print('Yes')


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
for i in range(N - 1):
    if H[i] < H[i+1] :
        H[i+1] -= 1

    elif H[i] > H[i+1]:
        print('No')
        exit()

print('Yes')
N, K  = (map(int, input().split()))
S = list(map(int, input()))
length = len(S)
lst = []

# 前処理
for i in range(length):
	if i == 0:
		lst.append(1)
		start = S[0]
	else:
		if S[i - 1] == S[i]:
			lst[-1] += 1
		else:
			lst.append(1)
				
# print(lst)
if (len(lst) + 1) / 2 < K:
	# print(sum(lst))
else:
	# 探索
	# 始点
	maximum = 0
	score = 0
	for i in range(start, length, 2):
		if len(lst) >= i + 2 * (K - 1) + 2:
			if i == start:
				score = sum(lst[max(0, i - 1) : min(len(lst), i + 2 * (K - 1) + 2)])
			else:
				# print(score)
				score -= sum(lst[i - 3 : i - 1])
				# print(sum(lst[i - 3 : i - 1]))
				score += sum(lst[i + 2 * (K - 1) : i + 2 * (K - 1) + 2])
				# print(sum(lst[i + 2 * (K - 1) : i + 2 * (K - 1) + 2]))
			# print(max(0, i - 1), min(len(lst), i + 2 * (K - 1) + 2))
			# print("score={}".format(score))
			if score > maximum:
				maximum = score
	print(maximum)

### FIXED CODE ###

N, K = map(int, input().split())
S = list(map(int, input()))
lst = []
cnt = 0
now = 1

for i in range(N):
	if S[i] == now:
		cnt += 1
	else:
		lst.append(cnt)
		cnt = 1
		now = 1 - now
		
lst.append(cnt)

#1 0 1 0 1の形にしたい
if len(lst) % 2 == 0:
	lst.append(0)

ret = 0
add = 2 * K + 1
left = 0
right = 0
total = 0

for i in range(0, len(lst), 2):
	nextleft = i
	nextright = min(i + add, len(lst))
	while nextleft > left:
		total -= lst[left]
		left += 1
	while nextright > right:
		total += lst[right]
		right += 1
	ret = max(ret, total)
	
print(ret)
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

#リストをソート
a=sorted(a)
b=sorted(b)
c=sorted(c)

#二分探索(x以上の最小値index) !同じ値の時はindex+1をする
def lower_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid+1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x>arr[-1]:
        return -1
    else:
        return r+1

#二分探索(x以下の最大値) !同じ値の時はindex-1をする
def upper_bound(arr,x):
    l=0
    r=len(arr)-1#数列arrの最後尾のインデックス
    while l<=r:
        mid=(l+r)//2#中央値検索
        if x==arr[mid]:#ちょうど中央値に存在したとき
            return mid-1
        elif x<arr[mid]:#xが左側の配列に存在するとき
            r=mid-1
        else:#xが右側の配列に存在するとき
            l=mid+1
        #print(mid,r,l)
    if x<arr[0]:
        return -1
    else:
        return r

#個数をカウント
count=0
for i in range(n):
    a_count=upper_bound(a,b[i])+1#b要素固定でのa要素の個数
    c_count=lower_bound(c,b[i])+1#b要素固定でのc要素の個数
    if a_count=-1 or c_count=-1:
        count=0
    else:
        count+=a_count*(len(c)-c_count+1)
        #print(upper_bound(a,b[i]),lower_bound(c,b[i]))
        #print(a_count,len(c),c_count,len(c)-c_count+1)
        #print(count)

print(count)


### FIXED CODE ###

# 二分探索
import bisect

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

#リストをソート
a=sorted(a)
b=sorted(b)
c=sorted(c)

count=0
#a[i]の個数
for i in range(n):
    a_count = bisect.bisect_left(a, b[i])
    c_count = bisect.bisect_right(c, b[i])
    count+=a_count*(len(c)-c_count)

print(count)
nums =input().split()
a = int(nume[0])
b = int(nums[1])
if a < b:
 print('a > b')
elif a > b:
 print('a < b')
eles:
 print('a == b')

### FIXED CODE ###

nums = input().split()
a = int(nums[0])
b = int(nums[1])
if a < b:
     print('a < b')
elif a > b:
     print('a > b')
else:
     print('a == b')
n=int(input())
l=[int(i) for i in input().split()]
s=0
for i in range(n-1):
	f=l[i]
    for j in range(n):
      if i!=j:
        f+=l[j]
        f=f/2
    if s<f:
      s=f
      
      

print(s)

### FIXED CODE ###

t=int(input())
l=sorted(map(int, input().split()))
s=l[0]
for i in range(1,t):
  
  s+=l[i]
  s/=2
print(s)
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
H,W=map(int, input().split())
S = []

S.append(['.']*(W+2))
for _ in range(H):
    S.append(['.']+list(input())+['.'])
S.append(['.']*(W+2))

for i in range(1,W):
    for j in range(1,H):
        if S[i][j] == "#" and S[i-1][j] == "." and S[i+1][j] == "." and  S[i][j-1] == "." and  S[i][j+1]== ".":
            print("No")
            sys.exit()

print("Yes")

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
H,W=map(int, input().split())
S = []

S.append(['.']*(W+2))
for _ in range(H):
    S.append(['.']+list(input())+['.'])
S.append(['.']*(W+2))

for i in range(1,H-1):
    for j in range(1,W-1):
        if S[i][j] == "#" and S[i-1][j] == "." and S[i+1][j] == "." and  S[i][j-1] == "." and  S[i][j+1]== ".":
            print("No")
            sys.exit()

print("Yes")
N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
counter=[0]*N
for i in range(len(S)-1):
  if S[i]=="A":
    counter[i]+=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j-1]]-counter[l[j-1]])

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
counter=[0]*N
for i in range(N-1):
  if S[i]=="A":
    counter[i]=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j]-2]-counter[l[j]-2])
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(30):
        if B[i]%2 == 0:
            B[i] //= 2
            C[i] += 1
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(1,t)
    m = t*q
    if m > M:
        print(0)
        return
    print((M-m)//(q*t)+1)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)

def lcm(a, b):
    return a*b//gcd(a,b)
#import sys
#input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    B = [a for a in A]
    T = 1
    L = 1
    C = [0]*N
    for i in range(N):
        for _ in range(30):
            if B[i]%2 == 0:
                B[i] //= 2
                C[i] += 1
            else:
                break
    p = C[0]
    for i in range(N-1):
        if p != C[i+1]:
            print(0)
            return
    q = pow(2,p)
    t = 1
    for i in range(N):
        t = lcm(t,A[i]//2)
    if t > M:
        print(0)
        return

    print((M-t)//(t*2) + 1)

if __name__ == '__main__':
    main()
X, N = map(int, input().split())
A = [map(int, input().split())]
a = 0
while True:
  if X-a in A:
    if X+a in A:
    a +=1
    else:
      print(X+a)
      exit()
  else:
    print(X-a)
    exit()

### FIXED CODE ###

X, N = map(int, input().split())
A = list(map(int, input().split()))
a = 0
while True:
  if X-a not in A:
      print(X-a)
      break
  if X+a not in A:
      print(X+a)
      break
  a += 1
import math
N = input()
N = int(N)
x = N / 3
p = 10 **9 + 7
if x == 0:
  print(0)
sum = 0
else:
  for k in range(x):
  y = N - 3 * k
  l = k - 1
  M = y + l
  a = math.factorial(l)
  b = math.factorial(M) 
  c = math.factorial(y)
  z = b / a / c
  z = z % p
  sum += z

print(z)

  

  

### FIXED CODE ###

import math
N = input()
N = int(N)
x = N // 3
x = int(x)
p = 10 ** 9 + 7
sum = 0
if x == 0:
  print(0)
else:
  for k in range(x):
    y =  N - 3*k - 3
    l = k 
    M = y + l
    a = math.factorial(l)
    b = math.factorial(M) 
    c = math.factorial(y)
    d = a * c
    z = b // d
    z = z % p
    sum += z
    sum = sum %p

  sum = int(sum)
  print(sum)
X=int(input())
A=0
for a in range(X):
  if (a+1)**5-a**5 <= X <= (a+1)**5+a**5:
    A = a
    break

for b in range(-A,A+1):
  if (A+1)**5-b**5 == X:
    B=b
    break   
    
print(A+1,B)

### FIXED CODE ###

X=int(input())
I=J=0
for i in range(-300,300):
  for j in range(-300,300):
    if i**5-j**5==X:
      I=i
      J=j
      break
print(I,J)
S = input()
T = input()
ans = float("INF")
for i in range(len(S)):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt += 1
    ans = min(ans,cnt)
print(cnt)

### FIXED CODE ###

S = input()
T = input()
ans = float("INF")
for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt += 1
    ans = min(ans,cnt)
print(ans)
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    A = list(map(int,input().split()))
    for j in range(m):
        ans = A_i[j]*b[j] + c
    if ans > 0:
        tmp += 1
print(tmp)

### FIXED CODE ###

n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    A = list(map(int,input().split()))
    ans = 0
    for j in range(m):
        ans += A[j]*b[j]
    ans = ans + c
    if ans > 0:
        count+= 1
print(count)
n, k = map(int, input().split())
 
M = [0]*n
 
for i in range(k):
    d = int(input())
    a = [int(x) for x in input().split()]
    for j in range(d):
        M[a[j]-1] += 1
 
print(M.count(0))

### FIXED CODE ###

S = input()

if S =='ABC':
  print('ARC')
else:
  print('ABC')
a,b,c=sorted(map(int,input().split()))
co=(b-a)//2
if (b-a)%2==1:counter+=1;c+=1
co+=c-b
print(co)

### FIXED CODE ###

a,b,c=sorted(map(int,input().split()))
co=(b-a)//2
if (b-a)%2==1:co+=1;c+=1
co+=c-b
print(co)
if a >=0 and b>=0 :
    if a+v*t >= b+ w*t:
        print("YES")
    else:
        print("NO")
elif a < 0 and b >= 0 :
    if -a+v*t >= b + w*t:
        print("YES")
    else :
        print("NO")
else :
    if v*t - w*t >= -(a-b):
        print("YES")
    else :
        print("NO")

### FIXED CODE ###

a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if a >=0 and b>=0 :
    if a+v*t >= b+ w*t:
        print("YES")
    else:
        print("NO")
elif a <0 and b >=0:
    if a+v*t >= b + w*t:
        print("YES")
    else :
        print("NO")
else :
    if -a+v*t >= -b + w*t:
        print("YES")
    else:
        print("NO")
import sys
def line():return sys.stdin.readline().strip()

ops = {"+":lambda a,b:b + a,
     "-":lambda a,b:b - a,
     "*":lambda a,b:b * a,
     "/":lambda a,b:b / a}
while True:
    stack = []
    for s in line().split():
        if s in ops:
            stack.append(ops[s](stack.pop(),stack.pop()))
        else:
            stack.append(int(s))
    print(stack[0])

### FIXED CODE ###

import sys
def line():return sys.stdin.readline().strip()

ops = {"+":lambda a,b:b + a,
     "-":lambda a,b:b - a,
     "*":lambda a,b:b * a,
     "/":lambda a,b:b / a}
while True:
    try:
        stack = []
        for s in line().split():
            if s in ops:
                stack.append(ops[s](stack.pop(),stack.pop()))
            else:
                stack.append(int(s))
        print(stack[0])
    except:
        break
n,m=map(int,input().split())
a=['.']
a*=n
ans=0
for i in range(m):
    si,ci=input().split()
    si=int(si)
    ci=str(ci)
    if a[si-1]=='.':
        a[si-1]=ci
    else:
        if a[si-1]==ci:
            continue
        else:
            ans=-1
            break

if ans==-1:
    print(-1)
else:
    if a[0]=='.':
        a[0]=1
    for i in range(1,n):
        if a[i]=='.':
            a[i]='0'
    a=''.join(a)
    print(a)

### FIXED CODE ###

n,m=map(int,input().split())
a=['.']
a*=n
ans=0
for i in range(m):
    si,ci=input().split()
    si=int(si)
    ci=str(ci)
    if a[si-1]=='.':
        a[si-1]=ci
    else:
        if a[si-1]==ci:
            continue
        else:
            ans=-1
            break

if ans==-1 or (n>=2 and a[0]=='0'):
    print(-1)
else:
    if n==1 and a[0]=='.':
        a[0]='0'
    elif a[0]=='.':
        a[0]='1'
    for i in range(1,n):
        if a[i]=='.':
            a[i]='0'
    a=''.join(a)
    print(a)
from collections import defaultdict

d = defaultdict(int)

for n in range(N):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(1, 10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)



### FIXED CODE ###

from collections import defaultdict

d = defaultdict(int)
N = int(input())

for n in range(1, N + 1):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)
def xx(a,b,c):
    ans=0
    if c%a == 0:
        ans += 1
    while c>0:
        if c%b == 0:
            ans+=1
        c -= a
    return ans


r,g,b,n = map(int,input().split())
if n%r==0:
    ans += 1
while n>0:
    ans += xx(g,b,n)
    n -= r
print(ans)

### FIXED CODE ###

def xx(a,b,c):
    ans=0
    if c%a == 0:
        ans += 1
    while c>0:
        if c%b == 0:
            ans+=1
        c -= a
    return ans


r,g,b,n = map(int,input().split())
ans = 0
if n%r==0:
    ans += 1
while n>0:
    ans += xx(g,b,n)
    n -= r
print(ans)
import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])


def calc(p, w):
    c_x, c_y = p
    x, y, h = w
    if h > 0:
        return h + abs(x-c_x) + abs(y-c_y)


def check(H, p, w):
    c_x, c_y = p
    x, y, h = w
    if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
        return True
    else:
        return False


for i in range(101):
    for j in range(101):
        p = [i, j]
        H = calc(p, information[-1])
        judge = 1
        for w in information[:-1]:
            if check(H, p, w):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(*p, H)
            sys.exit()
        else:
            continue



### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
information = [list(map(int, input().split())) for _ in range(n)]
information.sort(key=lambda x: x[2])

for c_x in range(101):
    for c_y in range(101):
        x, y, h = information[-1]
        H = h + abs(x - c_x) + abs(y - c_y)
        judge = 1
        for w in information[:-1]:
            x, y, h = w
            if h == max(0, H - abs(x - c_x) - abs(y - c_y)):
                continue
            else:
                judge -= 1
                break
        if judge:
            print(c_x, c_y, H)
            sys.exit()
        else:
            continue
N=int(input())
K=int(input())
import math
ans=0
a=int(math.log10(N))
if a<K-1:
    ans=0
else:
    if a>=K:
        ans+=(math.factorial(a)//(math.factorial(a-K)*math.factorial(K)))*(9**K)
    n=str(N)
    if K==1:
        ans+=int(n[0])
    elif K==2:ans+=(int(n[0])-1)*9+int(n[0])*(len(n)-2)*9+int(n[1])
    else:ans+=(int(n[0])-1)*81+(int(n[1])-1)*9+int(n[2])+int(n[0])*((math.factorial(len(n)-2)//(math.factorial(K-1)*math.factorial(len(n)-K-1)))-1)*81

print(ans)

### FIXED CODE ###

N=int(input())
K=int(input())
import math
ans=0
n=str(N)
a=len(n)
def combi(p,q):
    if p<q : return 0
    else: return math.factorial(p)//(math.factorial(q)*math.factorial(p-q))
def mi(i):
    if i==0:
        return 0
    else:
        return i-1
def zero(i):
    if int(n[i])==0:
        return 0
    else:
        return 1
if a<K:
    ans=0
else:
    if a>K:
        ans+=combi(a-1,K)*(9**K)
    if K==1:ans+=int(n[0])
    elif K==2:
        x=0
        i=1
        b=0
        bs=0
        while True:
            if (int(n[i])!=0) and (x==0):
                b=int(n[i])
                bs=a-i
                x+=1
            if (x==1) or (i==len(n)-1):
                break
            i+=1
        ans+=mi(int(n[0]))*(a-1)*9+mi(bs)*9+b
    elif a==3 : ans+=mi(int(n[0]))*81*(combi(a-1,2))+9*mi(int(n[1]))+int(n[2])
    else:
        x=0
        i=1
        b=0
        bs=0
        c=0
        cs=0
        while True:
            if (int(n[i])!=0) and (x==0):
                b=int(n[i])
                bs=a-i
                x+=1
            elif (int(n[i])!=0) and (x==1):
                c=int(n[i])
                cs=a-i
                x+=1
            if (x==2) or (i==len(n)-1):
                break
            i+=1
        ans+=mi(int(n[0]))*81*(combi(a-1,2))+combi(bs-1,2)*81+9*(a-2)*mi(b)+c+mi(cs)*9

print(ans)
import sys
a=1
for b in sys.stdin:b=b.strip()
 if b=='0':break
 print(f'Case {a}: {b}')
 a+=1

### FIXED CODE ###

x=int(input())
i=1
while x!=0:
    print("Case %d: %s" %(i,x))
    x=int(input())
    i+=1
import sys
sys.setrecursionlimit(10**9)

N = int(input())
S = input()

num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            num.append(f"{i}{j}{k}")

ans = 0
for n in num:
    i = 0
    j = 0
    while j < N:
        # print(i, j)
        if n[i] == S[j]:
            i += 1
            j += 1
        else:
            j += 1
        if i == 3:
            ans += 1
            break
print(ans)


### FIXED CODE ###


N = int(input())
S = input()

num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            num.append("{}{}{}".format(i, j, k))

ans = 0
for n in num:
    i = 0
    j = 0
    while j < N:
        # print(i, j)
        if n[i] == S[j]:
            i += 1
            j += 1
        else:
            j += 1
        if i == 3:
            ans += 1
            break
print(ans)
#!/usr/bin/python3

def search(n, total, dic):
    if dic[n] >= 0:
        return
    else:
        dic[n] = total
    for i in br[n]:
        search(i, total + 1, dic)

n, u, v = map(int, input().split())
br = {}
disu = {}
disv = {}
for i in range(n):
    br[i + 1] = []
    disu[i + 1] = -1
    disv[i + 1] = -1
for i in range(n - 1):
    a, b = map(int, input().split())
    br[a].append(b)
    br[b].append(a)

search(u, 0, disu)
search(v, 0, disv)
far = 0
for i in range(1, n + 1):
    if disv[i] < disu[i]:
        continue
    else:
        far = max(far, disv[i])

print(far - 1)


### FIXED CODE ###

#!/usr/bin/python3
import sys

sys.setrecursionlimit(10 ** 5)

def search(n, total, dic):
    if dic[n] >= 0:
        return
    else:
        dic[n] = total
    for i in br[n]:
        search(i, total + 1, dic)

n, u, v = map(int, input().split())
br = {}
disu = {}
disv = {}
for i in range(n):
    br[i + 1] = []
    disu[i + 1] = -1
    disv[i + 1] = -1
for i in range(n - 1):
    a, b = map(int, input().split())
    br[a].append(b)
    br[b].append(a)

search(u, 0, disu)
search(v, 0, disv)
far = 0
for i in range(1, n + 1):
    if disv[i] < disu[i]:
        continue
    else:
        far = max(far, disv[i])

print(far - 1)
import numpy as np


s = input()
t = input()
ls = len(s)
lt = len(t)

dp = np.array([[""]*(lt+2)]*(ls+2), dtype=object)
dp2 = np.zeros(((ls+2), (lt+2)))

for i in range(ls):
    flag = 0
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + s[i]
            dp2[i+1][j+1] = dp2[i][j] + 1
        else:
            if dp2[i][j+1] > dp2[i+1][j]:
                dp[i+1][j+1] = dp[i][j+1]
                dp2[i+1][j+1] = dp2[i][j+1]
            else:
                dp[i+1][j+1] = dp[i+1][j]
                dp2[i+1][j+1] = dp2[i+1][j]
print(dp[ls][lt])



### FIXED CODE ###

s = input()
t = input()
ls = len(s)
lt = len(t)


dp = [[0 for i in range(lt+1)] for j in range(ls+1)]
answer = ''

for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])


i = ls-1
j = lt-1
while (0 <= i) & (0 <= j):
    if s[i] == t[j]:
        answer += s[i]
        i -= 1
        j -= 1
    elif dp[i+1][j+1] == dp[i+1][j]:
        j -= 1
    else:
        i -= 1
if len(answer) == 0:
  print('')
else:
  print(answer[::-1])
elem = input()
single = s.count("R")
double = s.count("RR")
triple = s.count("RRR")
if triple == 1:
    print(3)
elif double == 1:
    print(2)
else:
    if single > 0:
        print(1)
    else:
        print(0)

### FIXED CODE ###

elem = input()
single = elem.count("R")
double = elem.count("RR")
triple = elem.count("RRR")
if triple == 1:
    print(3)
elif double == 1:
    print(2)
else:
    if single > 0:
        print(1)
    else:
        print(0)
n=int(input())
m=int(input())
print((n-1) * (m-1))

### FIXED CODE ###

n, m = map(int, input().split())
print((n-1)*(m-1))
import itertools
n=int(input())
A=[0 for i in range(n)]
A=input().split()
for i in range(n):
    A[i]=int(A[i])
q=int(input())
B=[0 for i in range(q)]
B=input().split()
C=[]
for i in range(q):
    B[i]=int(B[i])
l=[0,1]
p=[]
k=0
D=[]
for v in itertools.product(l,repeat=n):
    sum=0
    for i in range(n):
        if v[i]==1:
            sum=sum+A[i]
    D.append(sum)
    k+=1
for i in range(q):
    c=0
    for j in range(k):
        if B[i]==D[j] and c==0:
            C.append("yes")
            c+=1
    if c==0:
        C.append("no")
for i in range(q):
    print(C[i])



### FIXED CODE ###

import itertools
n=int(input())
A=[0 for i in range(n)]
A=input().split()
for i in range(n):
    A[i]=int(A[i])
q=int(input())
B=[0 for i in range(q)]
B=input().split()
C=[]
for i in range(q):
    B[i]=int(B[i])
l=[0,1]
p=[]
k=0
D=[]
for v in itertools.product(l,repeat=n):
    sum=0
    for i in range(n):
        if v[i]==1:
            sum=sum+A[i]
    D.append(sum)
    k+=1
for i in range(q):
    if B[i] in D:
        C.append("yes")
    else:
        C.append("no")
for i in range(q):
    print(C[i])