Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
p, q, r = cnt[1], cnt[2], cnt[3]

dp = []
for _ in range(n + 1):
    dp.append([[0] * (r + 1) for _ in range(r + q + 1)])
dp[0][0][0] = 0

for k in range(r + 1):
    for j in range(r + q + 1):
        for i in range(n + 1):
            if i != 0:
                dp[i][j][k] += dp[i - 1][j][k] * i
            if (j != 0) and (i != n):
                dp[i][j][k] += dp[i + 1][j - 1][k] * j
            if (k != 0) and (j != r + q):
                dp[i][j][k] += dp[i][j + 1][k - 1] * k
            if (i + j + k) != 0:
                dp[i][j][k] += n
                dp[i][j][k] /= (i + j + k)

print(dp[p][q][r])


### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
a = [0,0,0]
for x in LI():
    a[x-1] += 1
dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

for k in range(a[2]+1):
    for j in range(a[1]+a[2]+1):
        for i in range(N+1):
            if not (0 < i+j+k <= N): continue
            x = 0.0
            if i > 0: x += dp[i-1][j][k] * (i/N)
            if j > 0: x += dp[i+1][j-1][k] * (j/N)
            if k > 0: x += dp[i][j+1][k-1] * (k/N)
            x += 1.0
            x *= N / (i+j+k)
            dp[i][j][k] = x
print(dp[a[0]][a[1]][a[2]])
### BUGGY CODE ###

# ヒント　dp[i]=(石の個数がi個の時直後の手番の人が勝てるか？)
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
for i in range(1,k+1):
    for j in range(n):
        if i-a[j]>=0 and dp[i-a[j]]==0:
            dp[i]=1
print("First" if dp[k] else "Second")

### FIXED CODE ###

# ヒント　dp[i]=(石の個数がi個の時直後の手番の人が勝てるか？)
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
for i in range(1,k+1):
    for j in range(n):
        if i-a[j]>=0 and dp[i-a[j]]==0:
            dp[i]=1
print("First" if dp[k] else "Second")
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    import numpy as np

    def expected_val(limit):
        return sum(range(1 + limit)) / limit

    N, K = map(int, input().split())
    P = [int(x) for x in input().split()]

    lst = np.zeros(N + 1)
    res = 0
    for i in range(N):
        res += expected_val(P[i])
        lst[i + 1] = res
    print(np.max(lst[K:] - lst[:N - K + 1]))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    def expected_val(limit):
        return (1 + limit) / 2

    N, K = map(int, input().split())
    P = [int(x) for x in input().split()]

    lst = [0]
    res = 0
    for p in P:
        res += p + 1
        lst.append(res)
    ans = 0
    for i in range(N - K + 1):
        res = lst[i + K] - lst[i]
        ans = res if res > ans else ans
    print(ans / 2)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
import copy

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

def main():
    N,K = LI()[:]
    A = LI()
    #print(N,K)
    #print(A)

    for k in range(K):
        B = [0]*N
        for i, a in enumerate(A):
            #print(i, a)
            if a == 0:
                B[i] += 1
            else:
                # i-(a+0.5) ~ i+(a+0.5)
                # i: 整数、a: ＋整数　なので +0.5 は切り捨てられる。
                #　影響範囲は、 i-a ~ i+a
                for p in range(i-a,i+a+1):
                    #print("p:",p)
                    if p >=0 and p < N:
                        B[p] += 1
                #print(B)
        if k < K-1:
            A = B

    for a in B:
        print(a,end=" ")
    

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import numpy as np
from numba import njit
 
readline = sys.stdin.readline
 
@njit('i8,i8,i8[::1]',cache=True)
def loop(n,k,a):
    for j in range(k):
        b = np.zeros(n+1, dtype=np.int64)
        for i in range(n):
            b[max(i-a[i], 0)] += 1
            b[min(i+a[i]+1, n)] -= 1
        a = np.cumsum(b)[:-1]
        if np.all(a==n):
            return(a)
            break
    else:
        return(a)
 
 
n, k = map(int, readline().split())
a = np.array(readline().split(), dtype=np.int64)
 
ans = loop(n,k,a)
print(*ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
aa=[]
ans=0
for i in range(0,1000):
    chka,chkb,chkc=True,True,True
    i=str(i).zfill(3)
    for a in range(len(s)-2):
        if i[0]==s[a]:
            for b in range(a+1,len(s)-1):
                if i[1]==s[b]:
                    for c in range(b+1,len(s)):
                        if i[2]==s[c]:
                            ans+=1
                            aa.append(i)
                            chka,chkb,chkc=False,False,False
                            break
                        if chkc==False:
                            break
                        if c==len(s)-1 and i[2]!=s[c]:
                            break
                if chkb==False or chkc==False:
                    break
                if b==len(s)-2 and i[1]!=s[b]:
                    break
        if chka==False or chkb==False or chkc==False:
            break
        if a==len(s)-3 and i[0]!=s[a]:
            break


print(ans)

### FIXED CODE ###

n=int(input())
S = input()
 
ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)
### BUGGY CODE ###

import sys
import fractions
from functools import reduce
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = ni()
a = nl()
maxx = gcd_list(a)
for i in range(n):
    maxx = max(maxx, gcd_list(a[:i] + a[i + 1:]))
print(maxx)


### FIXED CODE ###

import sys
from functools import reduce
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def gcd_list(numbers):
    return reduce(gcd, numbers)
n = ni()
a = nl()
if len(a) == 2:
    print(max(a))
    exit()
minn = 10 ** 9 + 1
idx = -1
for i in range(n - 2):
    if minn >= gcd_list([a[i], a[i + 1], a[i + 2]]):
        minn = gcd_list([a[i], a[i + 1], a[i + 2]])
        idx = i
gcd1 = 0
gcd2 = 0
gcd3 = 0
for i in range(n):
    if i != idx:
        gcd1 = gcd(gcd1, a[i])
    if i != idx + 1:
        gcd2 = gcd(gcd2, a[i])
    if i != idx + 2:
        gcd3 = gcd(gcd3, a[i])
print(max(gcd1, gcd2, gcd3))
### BUGGY CODE ###

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

water = A[:]
#print(water)

ans = []
for x in range(0, water[0]*2+1, 2):
    #print(x)
    ans = [x]
    for i, a in enumerate(water):
        y = 2*a - ans[i]
        if y % 2 == 1:
            break
        ans.append(y)
    if len(ans) == N+1 and ans[0] == ans[-1]:
        #print(len(ans), N)
        break
print(' '.join(list(map(str, ans[:-1]))))

### FIXED CODE ###

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

water = A[:]
#print(water)

ans = []
x = 0
#print(x)
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    #print(y)
    ans.append(y)
    x = y
#print(ans, sum(ans))

x = (ans[0] + ans[-1]) // 2
ans = [x]
for i, a in enumerate(water):
    y = 2*a - x
    #print(y)
    ans.append(y)
    x = y
#print(ans, sum(ans))





print(' '.join(list(map(str, ans[:-1]))))
### BUGGY CODE ###

def combination(n,r):
    n_=1
    r_=1
    n_r=1
    for i in range(1,n+1):
        n_*=i
    for i in range(1,n-r+1):
        n_r*=i
    for i in range(1,r+1):
        r_*=i

    return n_//(n_r*r_)

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

    ball_dic={}

    for a in A:
        if a in ball_dic.keys():
            ball_dic[a]+=1
        else:
            ball_dic[a]=1


    all_patern=0

    for key in ball_dic.keys():
        if ball_dic[key]>=2:
            all_patern+=combination(ball_dic[key],2)

    for a in A:
        if ball_dic[a]-1<2:
            res=all_patern-combination(ball_dic[a],2)
        else:
            res=all_patern-combination(ball_dic[a],2)+combination(ball_dic[a]-1,2)

        print(res)

if __name__=="__main__":
    main()

### FIXED CODE ###

def combination(n,r):
    n_=1
    r_=1
    for i in range(n,n-r,-1):
        n_*=i
    for i in range(1,r+1):
        r_*=i

    return n_//r_

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

    ball_dic={}

    for a in A:
        if a in ball_dic.keys():
            ball_dic[a]+=1
        else:
            ball_dic[a]=1


    all_patern=0

    combination_dic={}

    for key in ball_dic.keys():
        if ball_dic[key]>=2:
            if (ball_dic[key] in combination_dic.keys()) is False:
                combination_dic[ball_dic[key]] = combination(ball_dic[key], 2)
            all_patern += combination_dic[ball_dic[key]]

    for a in A:
        if ball_dic[a]-1<2:
            if ball_dic[a] in combination_dic.keys():
                res=all_patern-combination_dic[ball_dic[a]]
            else:
                res=all_patern
        else:
            com=combination_dic[ball_dic[a]]
            res=all_patern-com+(com*(ball_dic[a]-2)//ball_dic[a])

        print(res)

if __name__=="__main__":
    main()
### BUGGY CODE ###

from collections import* #defaultdict Counter deque appendleft
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！
 
d=defaultdict(list)
n,m,p=map(int,input().split())
 
for s in range(m):
    a,b,c=map(int,input().split())
    d[a].append([b,c])
 
def BELLMANFORD(point,d,p):
    cost       = {node:-float("inf") for node in range(1,n+1)}
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p
 
    negative=[0]*n                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定 negativeの1は閉路に入っている部分を表す
        for now,lis in d.items():
            for nex,c in lis:
                if negative[now-1]==1:
                    negative[nex-1]=1
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p
                    negative[now-1]=1
 
    return cost,negative
 
def main():
    x,y=(BELLMANFORD(1,d,p))
#    print(x,y)
    if y[n-1]==1:
        print(-1)
    else:
        print(max(x[n],0))
 
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input=sys.stdin.readline  #危険！基本オフにしろ！


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

d={}
for s in range(m):
    a,b,c=map(int,input().split())
    if a in d:
        d[a].append((b,c))
    else:
        d[a]=[(b,c)]

#print(d)


def BELLMANFORD(point,d,p):
    cost       = [-float("inf") for node in range(n+1)]  #infじゃないと閉路検出がうまくいかない
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p

    negative=[0]*n                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定 negativeの1は閉路に入っている部分を表す
        for now,lis in d.items():
            for nex,c in lis:
                if negative[now-1]==1:
                    negative[nex-1]=1
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p
                    negative[now-1]=1
 
    return cost,negative

def main():
    x,y=(BELLMANFORD(1,d,p))
    
    if y[n-1]==1:
        print(-1)
    else:
        print(max(x[n],0))

    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
B=['0']*N
ret1=0
ret2=''
for i in range(N, 0, -1):
  Bit='0'*i+('0'*(i-1)+'1')*(N//i)
  Bit=int(Bit[:N], 2)
  BBit=int(''.join(B), 2)
  if bin(BBit & Bit).count('1')%2 ^ A[i-1]:
    ret1+=1
    B[i-1]='1'
    ret2=str(i)+' '+ret2
print(ret1)
print(ret2)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]*N
ret = []
for i in range(N, 0, -1):
  if (sum(B[i-1::i])%2) != A[i-1]:
    B[i-1]= 1
    ret.append(i)
print(sum(B))
print(*ret)
### BUGGY CODE ###

def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1
        elif(a<A[i]):
            break
    return R

def result(R,a):
    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
R+=result(compare(a[0],a),a[0])
T=compare(a[0],a)

for i in range(1, N):
    if(a[i] != a[i-1]):
        C=compare(a[i],a[T:])
        R+=result(C,a[i])
        T+=C


print(R)


### FIXED CODE ###

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

a.sort()
a.append(0)

T=[]
j=0
t=0
s=0
for i in range(N):
    j+=1
    if a[i] != a[i+1]:
        if j-s > a[i]:
            t+=(j-s)-a[i]
        elif j-s < a[i]:
            t += j-s
        s=j

print(t)
### BUGGY CODE ###

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()
    ans = 0
    for i in range(n-1):
        ans += a[i]*(sum(a[i+1:]))
    print(ans%(10**9+7))



if __name__=="__main__":
    main()


### FIXED CODE ###

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()
    ans = 0
    k = 0
    for i in range(n-2,-1,-1):
        k +=a[i+1]
        ans += a[i]*k
    print(ans%(10**9+7))

if __name__=="__main__":
    main()
### BUGGY CODE ###

S = input()

r_list = [0] * 2019
r_list[0 % 2019] += 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)


### FIXED CODE ###

S = input()
s_rev = S[::-1]

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(2019):
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
G = defaultdict(list)
A = list(map(int, input().split()))
A = sorted(A)
pow2 = [2 ** i for i in range(31)]
for i in range(N):
    for k in pow2:
        indexes = [j for j, x in enumerate(A) if x == k - A[i]]
        for j in indexes:
            G[i].append(N + j)
            G[j].append(N + i)

used = [False] * 2 * N
match = [-1] * 2 * N


def dfs(v):
    global used
    used[v] = True
    for u in G[v]:
        w = match[u]
        if w < 0 or not used[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True


ma = 0
for i in range(N):
    if match[i] < 0:
        used = [False] * 2 * N
        if dfs(i):
            ma += 1

print(ma // 2)

### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
pow2 = [1]
for i in range(31):
    pow2.append(pow2[-1] * 2)
a = sorted(a, reverse=True)
d = defaultdict(int)
for i in a:
    d[i] += 1


num = 0
for i in range(N):
    if d[a[i]] == 0:
        continue
    for k in range(30, -1, -1):
        inv = pow2[k] - a[i]
        if inv < 0 or inv > a[i]:
            continue
        if inv != a[i]:
            if d[inv] > 0 and d[a[i]] > 0:
                p = min(d[inv], d[a[i]])
                num += p
                d[inv] -= p
                d[a[i]] -= p
                break
        else:
            if d[a[i]] >= 2:
                num += d[a[i]] // 2
                d[a[i]] %= 2
                break
print(num)
### BUGGY CODE ###

root=[]
n,k = map(int,input().split())
for i in range(k):
    x,y = map(int,input().split())
    root.append([x,y])

toori=[0]*(2*10**5)+[0]*n+[0]*(2*10**5)
toori[2*10**5]=1
cum=[0]*k
for a,i in enumerate (root):
    s=0
    for j in range (i[0],i[1]+1):
        s+=toori[2*10**5+1-j]
    cum[a]=s
aaa=sum(cum)
toori[2*10**5+1]+=aaa


for now in range(2,n):#nowが今の場所
    hueru=0
    for a,i in enumerate (root):
        hueru+=(toori[2*10**5+now-i[0]] - toori[2*10**5+now-1-i[1]])
    aaa+=hueru
    toori[2*10**5+now]+=aaa
    toori[2*10**5+n-1]%=998244353
    


print(toori[2*10**5+n-1]%998244353)


### FIXED CODE ###

root=[]
n,k = map(int,input().split())
for i in range(k):
    x,y = map(int,input().split())
    root.append([x,y])

toori=[0]*(2*10**5)+[0]*n+[0]*(2*10**5)
toori[2*10**5]=1
cum=[0]*k
for a,i in enumerate (root):
    s=0
    for j in range (i[0],i[1]+1):
        s+=toori[2*10**5+1-j]
    cum[a]=s
aaa=sum(cum)%998244353
toori[2*10**5+1]+=aaa


for now in range(2,n):#nowが今の場所
    hueru=0
    for a,i in enumerate (root):
        hueru+=(toori[2*10**5+now-i[0]] - toori[2*10**5+now-1-i[1]])
    aaa+=hueru
    aaa%=998244353
    toori[2*10**5+now]+=aaa
    toori[2*10**5+now]%=998244353
    


print(toori[2*10**5+n-1]%998244353)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
print(0)
s = readline().rstrip().decode()
if s == 'Vacant':
    exit()
check = s
print(n - 1)
s = readline().rstrip().decode()
if s == 'Vacant':
    exit()
low = 0
high = n - 1
while low + 1 < high:
    mid = (low + high) // 2
    print(mid)
    s = readline().rstrip().decode()
    if s == 'Vacant':
        exit()
    if mid % 2 == 0:
        if check == s:
            low = mid
        else:
            check = s
            high = mid
    else:
        if check != s:
            low = mid
        else:
            check = s
            high = mid


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())


def q(i):
    print(i)
    r = input()[0]
    if r == 'V':
        exit()
    return r


z = q(0)


def is_ok(k):
    s = q(k)
    if k % 2:
        return z != s
    else:
        return z == s


ok = 0
ng = n
while ng - ok > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m
### BUGGY CODE ###

def gcd(a,b):
    c = 0
    if b > a:
        a,b = b,a
    while a % b != 0:
        c = b
        b = a % b
        a = c
    return b
def gcd3(a,b,c):
    return gcd(gcd(a,b),c)
K = int(input())
count = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            count += gcd3(i,j,k)
print(count)

### FIXED CODE ###

import math
K = int(input())
count = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(1,K+1):
            if i != j:
                count += 2 * math.gcd(math.gcd(i,j),k)
            else:
                count += math.gcd(math.gcd(i,j),k)
print(count)
### BUGGY CODE ###

from collections import defaultdict as d

def bfs(adj, start, n):
	visited = [False] * (n + 1)
	tab = [0] * n
	queue = []
	queue.append(start)
	visited[start] = True
	while queue:
		s = queue.pop(0)
		for i in adj[s]:
			if visited[i] == False:
				queue.append(i)
				visited[i] = True
				tab[i - 1] = tab[s - 1] + 1
	return tab

n, u, v = map(int, input().split())
adj = d(list)
for i in range(n - 1):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)

takahashi = bfs(adj, u, n)
aoki = bfs(adj, v, n)
res = -1
for i in range(n):
	if takahashi[i] <= aoki[i]:
		res = max(res, aoki[i] - 1)

print(res)


### FIXED CODE ###

from collections import defaultdict as d
from collections import deque

def bfs(adj, start, n):
	visited = [0] * (n + 1)
	tab = [0] * n
	q = deque([start])
	visited[start] = 1
	while q:
		s = q.popleft()
		for i in adj[s]:
			if visited[i] == 0:
				q.append(i)
				visited[i] = 1
				tab[i - 1] = tab[s - 1] + 1
	return tab

n, u, v = map(int, input().split())
adj = d(list)
for i in range(n - 1):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)

takahashi = bfs(adj, u, n)
aoki = bfs(adj, v, n)
res = -1
for i in range(n):
	if takahashi[i] <= aoki[i]:
		res = max(res, aoki[i] - 1)

print(res)