Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int, input().split()))
if max(L) > (sum(L)-max(L)):
    print("Yes")
else:
    print("No")

Fixed submission:
T, X = map(int, input().split())
print(T/X)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int, inpout().split()))
if max(L) > (sum(L)-max(L)):
    print("Yes")
else:
    print("No")

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int, input().split()))
if max(L) < (sum(L)-max(L)):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import exit
n, y  = map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        for k in range(n+1-j):
            if 10000*i+5000*j+1000*k == y and i+j+k == n:
                print(i, j, k)
                exit()
print(-1, -1, -1)

Fixed submission:
# -*- coding: utf-8 -*-
from sys import exit
n, y  = map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i, j, n-i-j)
            exit()
print(-1, -1, -1)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, Y = map(int, input().split())
cnt = 0
for x in range(N+1):
    for y in range(N+1):
        for z in range(N+1):
            if N == x+y+z:
                if Y == 10000*x+5000*y+1000*z:
                    cnt = 1
                    li = [x, y, z]          
if cnt == 1:
    print(li[0], li[1], li[2])
else:
    print(-1, -1, -1)
                

Fixed submission:
# -*- coding: utf-8 -*-
from sys import exit
n, y  = map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i, j, n-i-j)
            exit()
print(-1, -1, -1)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, Y = map(int, input().split())
cnt = 0
for x in range(N+1):
    for y in range(N+1):
        for z in range(N+1):
            if Y == 10000*x+5000*y+1000*z:
                if N == x+y+z:
                    cnt = 1
                    li = [x, y, z]          
if cnt == 1:
    print(li[0], li[1], li[2])
else:
    print(-1, -1, -1)
                

Fixed submission:
# -*- coding: utf-8 -*-
from sys import exit
n, y  = map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i, j, n-i-j)
            exit()
print(-1, -1, -1)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
                   
K, S = map(int, input().split())
cnt = 0

for X in range(0, K+1):
     for Y in range(0, K+1):
         for Z in range(0, K+1):
             SUM = X + Y + Z
             if SUM == S:
                 cnt += 1
print(cnt)

Fixed submission:
# -*- coding: utf-8 -*-
                   
K, S = map(int, input().split())
cnt = 0

for X in range(0, K+1):
     for Y in range(0, K+1):
         if 0<=S-X-Y and S-X-Y<=K:
             cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
ss=0
n=int(input())
while n>0:
	ss+=n%10
	n=n//10
	ss%=9 
if ss==0:
	print("Yes")
else:
	print("No")

Fixed submission:
ss=0
n=input().strip()
for i in range(len(n)):
	ss+=int(n[i])
	ss%=9 
if ss==0:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
arr=list(map(int,input().split()))
freq=[0]*(max(arr)+10)
for i in range(len(arr)):
	freq[arr[i]]+=1
for i in range(1,n+1):
	print(freq[i])

Fixed submission:
import math
n=int(input())
arr=list(map(int,input().split()))
freq=[0]*(200020)
for i in range(len(arr)):
	freq[arr[i]]+=1
for i in range(1,n+1):
	print(freq[i])
Buggy python submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
arr=[None]*n
flag=True
ar=[]
for i in range(m):
	s,c=map(int,input().split())
	ar.append([s,c])
for  i in range(len(arr)):
	s=ar[i][0]
	c=ar[i][1]
	s-=1
	if s==0 and c==0 and n!=1:
		flag=False
		break
	if arr[s]==None:
		arr[s]=c 
	else:
		if arr[s]!=c:
			flag=False
			break
		else:
			continue 
if not flag:
	print(-1)
	exit()
# if arr[0]==0 and n!=1:
# 	print(-1)
# 	exit()
if arr[0]==None:
	arr[0]=1
if flag:
	for i in arr:
		if i==None:
			print(0,end="")
		else:
			print(i,end="")
	print()
else:
	print(-1)

Fixed submission:
import math
n,m=map(int,input().split())
arr=[None]*n
flag=True
ar=[]
for i in range(m):
	s,c=map(int,input().split())
	ar.append([s,c])
if m==0 and n==1:
	print(0)
	exit()
for  i in range(len(ar)):
	s=ar[i][0]
	c=ar[i][1]
	s-=1
	if s==0 and c==0 and n!=1:
		flag=False
		break
	if arr[s]==None:
		arr[s]=c 
	else:
		if arr[s]!=c:
			flag=False
			break
		else:
			continue 
if not flag:
	print(-1)
	exit()
# if arr[0]==0 and n!=1:
# 	print(-1)
# 	exit()
if arr[0]==None:
	arr[0]=1
if flag:
	for i in arr:
		if i==None:
			print(0,end="")
		else:
			print(i,end="")
	print()
else:
	print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import math

h,n=map(int,input().split())
arr=[]
brr=[]
for i in range(n):
	a,b=map(int,input().split())
	arr.append(a)
	brr.append(b)
dp=[1000000000000000]*(h+1)
dp[0]=0
for i in range(1,h+1):
	for j in range(n):
		if ((i-arr[j])>=0):
			dp[i]=min(dp[i],dp[i-arr[j]]+brr[j])
		else:
			dp[i]=min(dp[i],brr[j])
print(dp[h])

Fixed submission:
import math

h,n=map(int,input().split())
arr=[]
brr=[]
for i in range(n):
	a,b=map(int,input().split())
	arr.append(a)
	brr.append(b)
dp=[1000000000000000]*(h+1)
dp[0]=0
for i in range(1,h+1):
	for j in range(n):
		if ((i-arr[j])>=0):
			dp[i]=min(dp[i],dp[i-arr[j]]+brr[j])
		else:
			dp[i]=min(dp[i],brr[j])
print(dp[h])
Buggy python submission (verdict: Runtime Error):
n,m,x,y=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort(reverse=True)
b.sort()
# xx=a[0]
f=0
# if xx<x:
#     xx=x 
for i in range(x+1,y+1):
    if i<=b[0] and i>a[0]:
        #print(i)
        f=1 
        break 
if f==1:
    print("No War")
else:
    print("War")

Fixed submission:
l=list(map(int,input().split()))
l=sorted(l)
l=l[::-1]
s=str(l[0])
s+=str(l[1])
xx=int(s)
print(xx+l[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
string = []
count = 0
s = []
for i in range(0, N):
    s = input()
    if not s in string:
        string.append(s)
    
print(len(string))

Fixed submission:
N = int(input())
dic = {}
s = []
for i in range(0,N):
    s = input()
    if not s in dic:
        dic[s] = 1

print(len(dic))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

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

    N = 2* 10 ** 5
    K = N
    A = [0]*N
    arr = [0]*(N+1)

    for _ in range(K):
        arr = [0]*(N+1)
        for i, a in enumerate(A):
            left = max(0, i-a)
            right = min(N, i+a+1)
            arr[left] += 1
            arr[right] -= 1
        
        A = list(accumulate(arr[:-1]))
        if all(a == N for a in A):
           break

    print(*A[:-1], sep=" ")



if __name__ == "__main__":
    main()

Fixed submission:
from itertools import accumulate

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

    for _ in range(K):
        arr = [0]*(N+1)
        for i, a in enumerate(A):
            left = max(0, i-a)
            right = min(N, i+a+1)
            arr[left] += 1
            arr[right] -= 1
        
        A = list(accumulate(arr[:-1]))
        if all(a == N for a in A):
           break

    print(*A, sep=" ")



if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, S = map(int, input().split())
    A = tuple(map(int, input().split()))

    MOD = 998244353

    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    # morau
    for i, a in enumerate(A):
        dp[i][0] = pow(2, i, MOD)
            
        for j in range(S+1):
            if j >= a:
                dp[i+1][j] = 2 * dp[i][j]
                dp[i+1][j] %= MOD
                dp[i+1][j] += dp[i][j-a]
                dp[i+1][j] %= MOD
            else:
                dp[i+1][j] = 2 * dp[i][j]
                dp[i+1][j] %= MOD
                

    print(dp[N][S])
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N, S = map(int, input().split())
    A = tuple(map(int, input().split()))

    MOD = 998244353

    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    # morau
    for i, a in enumerate(A):
        dp[i][0] = pow(2, i, MOD)
            
        for j in range(S+1):
            if j >= a:
                dp[i+1][j] = 2 * dp[i][j]
                dp[i+1][j] %= MOD
                dp[i+1][j] += dp[i][j-a]
                dp[i+1][j] %= MOD
            else:
                dp[i+1][j] = 2 * dp[i][j]
                dp[i+1][j] %= MOD
                

    print(dp[N][S])
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect_left
def input():return sys.stdin.readline().strip()

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

    to = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    
    ans = [0] * N
    dp = []
    def dfs(now, pre):
        a = A[now]
        idx = bisect_left(dp, a)

        if idx == len(dp):
            old = -1
            dp.append(a)
        else:
            old = dp[idx]
            dp[idx] = a
        
        ans[now] = len(dp)

        
        for nv in to[now]:
            if nv != pre:
                dfs(nv, now)
        

        if old == -1:
            dp.pop()
        else:
            dp[idx] = old

    
    dfs(0, -1)

    print(*ans, sep="\n")
        

if __name__ == "__main__":
    main()

Fixed submission:
import sys
from bisect import bisect_left
sys.setrecursionlimit(10**7)
def input():return sys.stdin.readline().strip()

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

    to = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    
    ans = [0] * N
    dp = []
    def dfs(now, pre):
        a = A[now]
        idx = bisect_left(dp, a)

        if idx == len(dp):
            old = -1
            dp.append(a)
        else:
            old = dp[idx]
            dp[idx] = a
        
        ans[now] = len(dp)

        
        for nv in to[now]:
            if nv != pre:
                dfs(nv, now)
        

        if old == -1:
            dp.pop()
        else:
            dp[idx] = old

    
    dfs(0, -1)

    print(*ans, sep="\n")
        

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, deque

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    edge = [[i-1, i+1] for i in range(N)]
    edge[0] = [1]
    edge[N-1] = [N-2]
    edge[X].append(Y)
    edge[Y].append(X)

    def bfs(i):
        q = deque()
        q.append(i)
        while len(q):
            now = q.popleft()
            for j in edge[now]:
                if j == i:
                    continue

                if not cost[j]:
                    cost[j] = cost[now] + 1
                    q.append(j)
        
    ct = Counter()
    for i in range(N):
        cost = [0] * N
        bfs(i)
        ct += Counter(cost)

    for i in range(1, N):
        print(ct[i]//2)

if __name__ == "__main__":
    main()

Fixed submission:
from collections import Counter, deque

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    edge = [[i-1, i+1] for i in range(N)]
    edge[0] = [1]
    edge[N-1] = [N-2]
    edge[X].append(Y)
    edge[Y].append(X)

    def bfs(i):
        q = deque()
        q.append(i)
        while len(q):
            now = q.popleft()
            for j in edge[now]:
                if j == i:
                    continue

                if not cost[j]:
                    cost[j] = cost[now] + 1
                    q.append(j)
        
    ct = Counter()
    for i in range(N):
        cost = [0] * N
        bfs(i)
        ct += Counter(cost)

    for i in range(1, N):
        print(ct[i]//2)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    red = deque(sorted(map(int, input().split()), reverse=True))
    green = deque(sorted(map(int, input().split()), reverse=True))
    nocolor = deque(sorted(map(int, input().split()), reverse=True))

    INF = 10 ** 9 + 1
    times = A + B + C - (X + Y)
    for _ in range(times):
        red_num = len(red)
        green_num = len(green)
        nocolor_num = len(nocolor)

        if red_num and red_num + nocolor_num > X:
            r = red[-1]
        else:
            r = INF
        
        if green_num and green_num + nocolor_num > Y:
            g = green[-1]
        else:
            g = INF
        
        if nocolor_num:
            no = nocolor[-1]
        else:
            no = INF
        
        l = [no, r, g]
        idx = l.index(min(l))
        if idx == 0:
            red.pop()
        if idx == 1:
            green.pop()
        if idx == 2:
            nocolor.pop()

    print(sum(red) + sum(green) + sum(nocolor))
        
        

if __name__ == "__main__":
    main()

Fixed submission:
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    apple = []
    red = sorted(map(int, input().split()), reverse=True)[:X]
    green = sorted(map(int, input().split()), reverse=True)[:Y]
    nocolor = list(map(int, input().split()))
    apple.extend(red)
    apple.extend(green)
    apple.extend(nocolor)
    
    print(sum(sorted(apple, reverse=True)[:X+Y]))      
        

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W, K = map(int, input().split())
    chocolate = [list(map(int,list(input()))) for _ in range(H)]
    choco = [[0]*W for _ in range(H)]
    ids = [0] * H
    ans = 10 ** 9
    for bit in range(1<<(H-1)):
        group_id = 0
        for i in range(H):
            ids[i] = group_id
            if (bit>>i)&1:
                group_id += 1
        group_id += 1
        
        for i in range(group_id):
            for j in range(W):
                choco[i][j] = 0

        for i in range(H):
            for j in range(W):
                choco[ids[i]][j] += chocolate[i][j]
        
        if any(choco[i][j] > K for i in range(group_id) for j in range(W)):
            continue
        
        num = group_id - 1
        now = [0] * group_id
        def add(j):
            for i in range(group_id):
                now[i] += choco[i][j]
            if any(now[i] > K for i in range(group_id)):
                return False
            else:
                return True

        for j in range(W):
            if not add(j):
                num += 1
                now = [0] * group_id
                add(j)
        ans = min(ans, num)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    H, W, K = map(int, input().split())
    chocolate = [list(map(int,list(input()))) for _ in range(H)]
    choco = [[0]*W for _ in range(H)]
    ids = [0] * H
    ans = 10 ** 9
    for bit in range(1<<(H-1)):
        group_id = 0
        for i in range(H):
            ids[i] = group_id
            if (bit>>i)&1:
                group_id += 1
        group_id += 1
        
        for i in range(group_id):
            for j in range(W):
                choco[i][j] = 0

        for i in range(H):
            for j in range(W):
                choco[ids[i]][j] += chocolate[i][j]
        
        if any(choco[i][j] > K for i in range(group_id) for j in range(W)):
            continue
        
        num = group_id - 1
        now = [0] * group_id
        def add(j):
            for i in range(group_id):
                now[i] += choco[i][j]
            if any(now[i] > K for i in range(group_id)):
                return False
            else:
                return True

        for j in range(W):
            if not add(j):
                num += 1
                now = [0] * group_id
                add(j)
        ans = min(ans, num)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
MAX_VAL = 10**9
cost = [[MAX_VAL]*(W+1) for _ in range(H+1)]
field = ["#" * (H+1)]
for i in range(H):
    line = input()
    field.append("#" + line)

if field[1][1] == "#":
    cost[1][1] = 1
else:
    cost[1][1] = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if i * j == 1:
            continue

        if field[i][j] == ".":
            cost[i][j] = min(cost[i-1][j], cost[i][j-1])
        else:
            top_cost = cost[i-1][j]
            left_cost = cost[i][j-1]
            
            if field[i-1][j] == ".":
                top_cost += 1
            if field[i][j-1] == ".":
                left_cost += 1
            
            cost[i][j] = min(top_cost, left_cost)

print(cost[H][W])

Fixed submission:
H, W = map(int, input().split())
MAX_VAL = 10**9
cost = [[MAX_VAL]*(W+1) for _ in range(H+1)]

field = ["#" * (W+1)]
for i in range(H):
    line = input()
    field.append("#" + line)

if field[1][1] == "#":
    cost[1][1] = 1
else:
    cost[1][1] = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if i * j == 1:
            continue

        if field[i][j] == ".":
            cost[i][j] = min(cost[i-1][j], cost[i][j-1])
        else:
            top_cost = cost[i-1][j]
            left_cost = cost[i][j-1]
            
            if field[i-1][j] == ".":
                top_cost += 1
            if field[i][j-1] == ".":
                left_cost += 1
            
            cost[i][j] = min(top_cost, left_cost)

print(cost[H][W])
Buggy python submission (verdict: Runtime Error):
A = []
for i in range(3):
    line = list(map(int, input().split()))
    A.extend(line)
N = int(input())

bingo = [False] * 9

def num_check(num):
    for i in range(9):
        if A[i] == num:
            bingo[i] = True


for _ in range(N):
    num = int(input())
    num_check(num)

bingo_flag = False
# row check
if any([bingo[i] and bingo[i+1] and bingo[i+2] for i in range(0, 9, 3)]):
    bingo_flag = True

# col check
if any([bingo[i] and bingo[i+3] and bingo[i+6] for i in range(3)]):
    bingo_flag = True

# cross check
if (bingo[0] and bingo[4] and bingo[8]) or (bingo[2] and bing[4] and bingo[6]):
    bingo_flag = True

print("Yes") if bingo_flag else print("No")

Fixed submission:
A = []
for i in range(3):
    line = list(map(int, input().split()))
    A.extend(line)
N = int(input())

bingo = [False] * 9

def num_check(num):
    for i in range(9):
        if A[i] == num:
            bingo[i] = True


for _ in range(N):
    num = int(input())
    num_check(num)

bingo_flag = False
# row check
if any([bingo[i] and bingo[i+1] and bingo[i+2] for i in range(0, 9, 3)]):
    bingo_flag = True

# col check
if any([bingo[i] and bingo[i+3] and bingo[i+6] for i in range(3)]):
    bingo_flag = True

# cross check
if (bingo[0] and bingo[4] and bingo[8]) or (bingo[2] and bingo[4] and bingo[6]):
    bingo_flag = True

print("Yes") if bingo_flag else print("No")
Buggy python submission (verdict: Runtime Error):
import math
import bisect

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

    
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


if __name__ == '__main__':
    target = int(input())
    ps = primes(10**5+1)
    ans_idx = bisect.bisect_left(ps, target)
    print(ps[ans_idx])



Fixed submission:
import math
import bisect

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

    
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


if __name__ == '__main__':
    target = int(input())
    ps = primes(2 * 10**5)
    ans_idx = bisect.bisect_left(ps, target)
    print(ps[ans_idx])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)


def dfs4t(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4t[child] = cost4t[a] + 1
            dfs4t(child, a)
    return

def dfs4a(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4a[child] = cost4a[a] + 1
            dfs4a(child, a)
    return


N, u, v = map(int, input().split())
edge = [[] for _ in range(N)]
cost4t = [10**5 for i in range(N)]
cost4a = [10**5 for i in range(N)]

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

u -= 1
v -= 1
cost4t[u] = 0
cost4a[v] = 0
dfs4t(u, 10**5)
dfs4a(v, 10**5)

ans = 0
for t, a, in zip(cost4t, cost4a):
    if a  >= t:
        ans = max(ans, t + a - (t + 1))
print(ans)





Fixed submission:
import sys
sys.setrecursionlimit(10**9)


def dfs4t(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4t[child] = cost4t[a] + 1
            dfs4t(child, a)
    return

def dfs4a(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4a[child] = cost4a[a] + 1
            dfs4a(child, a)
    return


N, u, v = map(int, input().split())
edge = [[] for _ in range(N)]
cost4t = [10**5 for i in range(N)]
cost4a = [10**5 for i in range(N)]

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

u -= 1
v -= 1
cost4t[u] = 0
cost4a[v] = 0
dfs4t(u, 10**5)
dfs4a(v, 10**5)

ans = 0
for t, a, in zip(cost4t, cost4a):
    if a  >= t:
        ans = max(ans, t + a - (t + 1))
print(ans)