Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
lis1 = []
lis2 = []
lis3 = []
count = 0
for num in input().split():
    lis1.append(int(num))
for num in input().split():
    lis2.append(int(num))
for num in input().split():
    lis3.append(int(num))
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            count = 0
            if lis1[0] - a1 == lis2[0] – a1 == lis3[0] - a1:
                count += 1
            if lis1[1] - a2 == lis2[1] - a2 == lis3[1] - a2:
                count += 1
            if lis1[2] - a3 == lis2[2] - a3 == lis3[2] - a3:
                count += 1
            if count == 3:
                print("Yes")
                break
print("No")

Fixed submission:
lis1 = []
lis2 = []
lis3 = []
count = 0
for num in input().split():
    lis1.append(int(num))
for num in input().split():
    lis2.append(int(num))
for num in input().split():
    lis3.append(int(num))
if lis1[0]-lis2[0]==lis1[1]-lis2[1]==lis1[2]-lis2[2]:
    count += 1
if lis1[0]-lis3[0]==lis1[1]-lis3[1]==lis1[2]-lis3[2]:
    count += 1
if lis1[0]-lis1[1]==lis2[0]-lis2[1]==lis3[0]-lis3[1]:
    count += 1
if lis1[0]-lis1[2]==lis2[0]-lis2[2]==lis3[0]-lis3[2]:
    count += 1
if count == 4:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        for b in range(t - pre_t + 1 - a):
            if pre_x + a - b == x:
                for c in range(t - pre_t + 1  - a - b):
                    d = t - pre_t - a - b - c
                    if pre_y + c - d == y:
                        count += 1
                        flag = True
                        break
            if flag:
                break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        b = pre_x - x + a
        if b >= 0:
            for c in range(t - pre_t + 1  - a - b):
                d = t - pre_t - a - b - c
                if pre_y + c - d == y:
                    count += 1
                    flag = True
                    break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        for b in range(t- pre_t + 1 - a):
            for c in range(t - pre_t + 1  - a - b):
                d = t - pre_t - a - b - c
                if pre_x + a - b == x and pre_y + c - d == y:
                    count += 1
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        b = pre_x - x + a
        if b >= 0:
            for c in range(t - pre_t + 1  - a - b):
                d = t - pre_t - a - b - c
                if pre_y + c - d == y:
                    count += 1
                    flag = True
                    break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
count = 0
for b in range(N+1):
    for a in range(0, b):
        total = 1000a + 5000(b-a) + 10000(N-b)
        if total == Y:
            print(a,b-a,N-b)
            break
    count += 1
if count == N+1:
    print('-1 -1 -1')

Fixed submission:
N, Y = map(int, input().split())
def otoshidama(n,y):
  No = -1
  for b in range(n+1):
    if b == 0:
      total = 10000*n
      if total == y:
        print('{} 0 0'.format(n))
        return
    for a in range(0, b+1):
      total = 1000*a + 5000*(b-a) + 10000*(n-b)
      if total == y:
        print(n-b,b-a,a)
        return
  print('-1 -1 -1')
  return
otoshidama(N,Y)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(30):
    for b in range(31):
        if not a == b == 0 and a*A*100 + b*B*100 <= F:
            for c in range(int((F - a*A*100 + b*B*100) / C) + 1):
                for d in range(int((F - a*A*100 + b*B*100 + c*C) / D) + 1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if (c*C+d*D)/(100*a*A+100*b*B+c*C+d*D) <= E/(100+E):
                            if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                                con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                                sugar = c*C+d*D
                                sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(int(F / 100 / A) + 1):
    for b in range(int((F - a * 100 * A)/ 100 / B) + 1):
        if not a == b == 0:
            for c in range(int((a*A+b*B)*E/C)+1):
                for d in range(int(((a*A+b*B)*E-c*C)/D)+1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                            con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                            sugar = c*C+d*D
                            sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)

Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar = 0
for a in range(int(F / 100 / A) + 1):
    for b in range(int((F - a * 100 * A)/ 100 / B) + 1):
        if not a == b == 0:
            for c in range(int((a*A+b*B)*E/C)+1):
                for d in range(int(((a*A+b*B)*E-c*C)/D)+1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if con < 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                            con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                            sugar = c*C+d*D
                            water = 100*a*A+100*b*B+c*C+d*D
print(water, sugar)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(int(F / 100 / A) + 1):
    for b in range(int((F - a * 100 * A)/ 100 / B) + 1):
        if not a == b == 0:
            for c in range(int((a*A+b*B)*E/C)+1):
                for d in range(int(((a*A+b*B)*E-c*C)/D)+1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                            con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                            sugar = c*C+d*D
                            sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
elements = set()
for i in input().split():
    a.append(int(i))
    elements.add(int(i))
    elements.add(int(i)-1)
    elements.add(int(i)+1)
max_count = 0
for X in elements:
    count = 0
    for num in a:
        if X-1 <= num <= X+1:
            count += 1
    max_count = max(max_count, count)
print(max_count)

Fixed submission:
def dic_counter(dic, num):
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

N = int(input())
dic = {}
for i in input().split():
    dic_counter(dic, int(i)-1)
    dic_counter(dic, int(i))
    dic_counter(dic, int(i)+1)
for _, value in sorted(dic.items(), key=lambda x: -x[1]):
    print(value)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
elements = set()
for i in input().split():
    a.append(int(i))
    elements.add(int(i))
max_count = 0
for X in elements:
    count1 = 0
    count2 = 0
    count3 = 0
    for num in a:
        if X-1 <= num <= X+1:
            count1 += 1
        if X <= num <= X+2:
            count2 += 1
        if X-2 <= num <= X:
            count3 += 1
    max_count = max(max_count, count1, count2, count3)
print(max_count)

Fixed submission:
def dic_counter(dic, num):
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

N = int(input())
dic = {}
for i in input().split():
    dic_counter(dic, int(i)-1)
    dic_counter(dic, int(i))
    dic_counter(dic, int(i)+1)
for _, value in sorted(dic.items(), key=lambda x: -x[1]):
    print(value)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
maximum = 0
minimum = 10 ** 5
for i in input().split():
    a.append(int(i))
    maximum = max(maximum, int(i))
    minimum = min(minimum, int(i))
max_count = 0
for X in range(minimum, maximum+1):
    count = 0
    for num in a:
        if X-1 <= num <= X+1:
            count += 1
    max_count = max(max_count, count)
print(max_count)

Fixed submission:
def dic_counter(dic, num):
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

N = int(input())
dic = {}
for i in input().split():
    dic_counter(dic, int(i)-1)
    dic_counter(dic, int(i))
    dic_counter(dic, int(i)+1)
for _, value in sorted(dic.items(), key=lambda x: -x[1]):
    print(value)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
maximum = 0
minimum = 10 ** 5
for i in input().split():
    a.append(int(i))
    maximum = max(maximum, int(i))
    minimum = min(minimum, int(i))
max_count = 0
for X in range(minimum, maximum+1):
    count = 0
    for num in a:
        if X-1 <= num <= X+1:
            count += 1
    max_count = max(max_count, count)
print(max_count)

Fixed submission:
def dic_counter(dic, num):
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

N = int(input())
dic = {}
for i in input().split():
    dic_counter(dic, int(i)-1)
    dic_counter(dic, int(i))
    dic_counter(dic, int(i)+1)
for _, value in sorted(dic.items(), key=lambda x: -x[1]):
    print(value)
    break
Buggy python submission (verdict: Time Limit Exceeded):
def min_mult(a, b):
    result = max(a, b)
    while result % min(a, b) != 0:
        result += max(a, b)
    return result
N = int(input())
multiple = 1
for _ in range(N):
    multiple = min_mult(multiple, int(input()))
print(multiple)

Fixed submission:
def min_mult(a, b):
    result = max(a, b)
    while result % min(a, b) != 0:
        result += max(a, b)
    return result
N = int(input())
multiple = 1
for _ in range(N):
    multiple = min_mult(multiple, int(input()))
print(multiple)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = []
for _ in range(N):
    t = int(input())
    T.append(t)
sorted_T = sorted(T, key = lambda x: -x)
time = sorted_T[0]
for t in sorted_T:
    if time % t != 0:
        time *= t
while time >= sorted_T[0]:
    flag = True
    for t in T:
        if time % t != 0:
            flag = False
            break
    if flag:
        result = time
    time -= sorted_T[0]
print(result)

Fixed submission:
def min_mult(a, b):
    result = max(a, b)
    while result % min(a, b) != 0:
        result += max(a, b)
    return result
N = int(input())
multiple = 1
for _ in range(N):
    multiple = min_mult(multiple, int(input()))
print(multiple)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
max_T = 1
T = []
for _ in range(N):
    t = int(input())
    T.append(t)
    max_T = max(max_T, t)
time = max_T
while time <= 10**18:
    flag = True
    for t in T:
        if time % t != 0:
            flag = False
            break
    if flag == True:
        print(time)
        break
    else:
        time += max_T

Fixed submission:
def min_mult(a, b):
    result = max(a, b)
    while result % min(a, b) != 0:
        result += max(a, b)
    return result
N = int(input())
multiple = 1
for _ in range(N):
    multiple = min_mult(multiple, int(input()))
print(multiple)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
max_T = 1
T = []
for _ in range(N):
    t = int(input())
    T.append(t)
    max_T = max(max_T, t)
time = max_T
while time <= 10**18:
    flag = True
    for t in T:
        if time % t != 0:
            flag = False
            break
    if flag == True:
        print(time)
        break
    else:
        time += max_T

Fixed submission:
def min_mult(a, b):
    result = max(a, b)
    while result % min(a, b) != 0:
        result += max(a, b)
    return result
N = int(input())
multiple = 1
for _ in range(N):
    multiple = min_mult(multiple, int(input()))
print(multiple)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
lis = [10**5]*K
for _ in range(N):
    a, b = map(int, input().split())
    if a < lis[K-1]:
        for index, num in enumerate(lis):
            if num > a:
                if index + b < K:
                    lis = lis[:index] + [a for _ in range(b)] + lis[index:K-b]
                else:
                    lis = lis[:index] + [a for _ in range(K-index)]
                break
print(lis[K-1])

Fixed submission:
N, K = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(input())
count = 0
for string in sorted(AB, key = lambda x: int(x.split()[0])):
    a = int(string.split()[0])
    b = int(string.split()[1])
    count += b
    if count >= K:
        print(a)
        break
Buggy python submission (verdict: Time Limit Exceeded):
def sequence(lis, first_value):
    count = 0
    now_sum = first_value
    pre_sum = first_value
    for num in lis[1:]:
        now_sum += num
        while now_sum == 0 or now_sum * pre_sum > 0:
            now_sum -= pre_sum/abs(pre_sum)
            count += 1
        pre_sum = now_sum
    return count

n = int(input())
a = [int(i) for i in input().split()]
if a[0] == 0:
    print(min(sequence(a, 1), sequence(a, -1))+1)
else:
    print(sequence(a, a[0]))

Fixed submission:
def sequence(lis, first_value):
    count = 0
    now_sum = first_value
    pre_sum = first_value
    for num in lis[1:]:
        now_sum += num
        if now_sum == 0 or pre_sum * now_sum > 0:
            count += abs(now_sum) + 1
            now_sum = -1 * pre_sum / abs(pre_sum)
        pre_sum = now_sum
    return int(count)

n = int(input())
a = [int(i) for i in input().split()]
if a[0] == 0:
    print(min(sequence(a, 1)+1, sequence(a, -1)+1))
else:
    print(min(sequence(a, a[0]), sequence(a, -1*a[0]/abs(a[0]))+abs(a[0])+1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
sub = 0
count = 1
A = [int(i) for i in input().split()]
pre_num = A[1]
pre_sub = A[1] - A[0]
for num in A[2:]:
    if not pre_num == num:
        if pre_sub * (num - pre_num) < 0:
            count += 1
            pre_sub = 0
        else:
          	pre_sub = num - pre_num
        pre_num = num
print(count)

Fixed submission:
N = int(input())
selector = 0
count = 1
A = [int(i) for i in input().split()]
pre_num = A[0]
for num in A[1:]:
    if selector == 0:
        selector = num - pre_num
    if selector > 0:
        if num < pre_num:
            selector = 0
            count += 1
    if selector < 0:
        if num > pre_num:
            selector = 0
            count += 1
    pre_num = num
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def F(a, b):
    count = 0
    c = max(a, b)
    while c > 9:
        c = c / 10
        count += 1
    return count+1

N = int(input())
minimum = 11
for num in range(1,int(N/100)+101):
    if N % num == 0:
        minimum = min(minimum, F(num, N/num))
print(minimum)

Fixed submission:
def F(a, b):
    count = 0
    c = max(a, b)
    while c >= 10:
        c = c / 10
        count += 1
    return count+1

N = int(input())
minimum = 15
for num in range(1,int(N/(10**5))+10**5+1):
    if N % num == 0:
        minimum = min(minimum, F(num, N/num))
print(minimum)

Buggy python submission (verdict: Time Limit Exceeded):
def F(a, b):
    count = 0
    c = max(a, b)
    while c > 9:
        c = c / 10
        count += 1
    return count+1

N = int(input())
minimum = 11
for num in range(1,int(N/4)+5):
    if N % num == 0:
        minimum = min(minimum, F(num, N/num))
print(minimum)

Fixed submission:
def F(a, b):
    count = 0
    c = max(a, b)
    while c >= 10:
        c = c / 10
        count += 1
    return count+1

N = int(input())
minimum = 15
for num in range(1,int(N/(10**5))+10**5+1):
    if N % num == 0:
        minimum = min(minimum, F(num, N/num))
print(minimum)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(r, b)
    
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

l = 1
for a in A:
    l = lcm(l, a)

ans = 0
for a in A:
    ans += l // a

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

Fixed submission:
import fractions
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
N = int(input())
A = list(map(int, input().split()))
 
l = 1
for a in A:
    l = lcm(l, a)
 
ans = 0
for a in A:
    ans += l // a
 
print(ans % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
 
N = int(input())
A = list(map(int, input().split()))
 
l = 1
for a in A:
    l = (l * a) // fractions.gcd(l, a)
 
ans = 0
for a in A:
    ans += l // a
 
print(ans % (10**9 + 7))

Fixed submission:
import fractions
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
N = int(input())
A = list(map(int, input().split()))
 
l = 1
for a in A:
    l = lcm(l, a)
 
ans = 0
for a in A:
    ans += l // a
 
print(ans % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

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

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

l = 1
for a in A:
    l = lcm(l, a)

ans = 0
for a in A:
    ans += l // a

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

Fixed submission:
import fractions
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
N = int(input())
A = list(map(int, input().split()))
 
l = 1
for a in A:
    l = lcm(l, a)
 
ans = 0
for a in A:
    ans += l // a
 
print(ans % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
def dfs(y, x, y0, x0, d=0):
    if y < 0 or y >= H or x < 0 or x >= W:
        return

    if seen[y][x]:
        return

    seen[y][x] = True

    if maze[y][x] == "#":
        return

    if d > dist[y0][x0]:
        dist[y0][x0] = d

    dfs(y, x+1, y0, x0, d+1)
    dfs(y+1, x, y0, x0, d+1)
    dfs(y, x-1, y0, x0, d+1)
    dfs(y-1, x, y0, x0, d+1)


dist = [[0] * W for _ in range(H)]

for i in range(H):
    for j in range(W):
        seen = [[False] * W for _ in range(H)]
        dfs(i, j, i, j)

ans = 0
for row in dist:
    for d in row:
        ans = max(ans, d)

print(ans)

Fixed submission:
from collections import deque

def bfs(h, w):
    q = deque([[h, w]])
    dist[h][w] = 0

    while len(q) != 0:
        y, x = q.popleft()

        for step in steps:
            nx = x + step[0]
            ny = y + step[1]
            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue
            if maze[ny][nx] == "#":
                continue
            if dist[ny][nx] != -1:
                continue
            dist[ny][nx] = dist[y][x] + 1
            q.append([ny, nx])


H, W = map(int, input().split())
maze = [[s for s in input()] for _ in range(H)]

steps = [[1, 0], [0, 1], [-1, 0], [0, -1]]
max_dist = [[0]*W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if maze[h][w] == "#":
            continue
        dist = [[-1]*W for _ in range(H)]
        bfs(h, w)
        for row in dist:
            for d in row:
                max_dist[h][w] = max(max_dist[h][w], d)

ans = 0
for row in max_dist:
    for d in row:
        ans = max(ans, d)

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N % 2 != 0:
    print(0)

else:
    count = N // 10
    for j in range(1, 50):
        count += N // ((5**j) * 10)

print(count)


Fixed submission:
N = int(input())

if N % 2 != 0:
    print(0)
else:
    count = N // 10
    for j in range(1, 50):
        count += N // ((5**j) * 10)
    print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())

if N % 2 != 0:
    print(0)

else:
        count = N // 10
        for j in range(1, 50):
            count += N // ((5**j) * 10)

print(count)


Fixed submission:
N = int(input())

if N % 2 != 0:
    print(0)
else:
    count = N // 10
    for j in range(1, 50):
        count += N // ((5**j) * 10)
    print(count)

Buggy python submission (verdict: Runtime Error):
N = input()

L = len(N)
ans = 0
buf = "0"
p = L - 1

if int(N) % 2 != 0:
    print(0)

else:
        count = int(N) // 10
        for j in range(1, 50):
            count += int(N) // ((5**j) * 10)

print(count)





Fixed submission:
N = int(input())

if N % 2 != 0:
    print(0)
else:
    count = N // 10
    for j in range(1, 50):
        count += N // ((5**j) * 10)
    print(count)
Buggy python submission (verdict: Runtime Error):

import copy

def dfs(graph, v, d):
    seen[v] = True # 訪問済みかどうか
    dist[v] = d # 距離を記録

    # 頂点vから行ける頂点を全探索
    for i in graph[v]:
        if seen[i]:
            continue
        dfs(graph, i, d+1)

# ここから本文
N, u, v = map(int, input().split())

u -= 1
v -= 1

# グラフ構造を作る
graph = [[] for i in range(N)]
for i in range(N - 1):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    graph[A].append(B)
    graph[B].append(A)

# 青木くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, v, 0)
aoki_dist = copy.deepcopy(dist)

# 高橋くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, u, 0)
takahashi_dist = copy.deepcopy(dist)

ans = 0
for i in range(N):
    if aoki_dist[i] > takahashi_dist[i]:
        if aoki_dist[i] - 1 > ans:
            ans = aoki_dist[i] - 1      

print(ans)

Fixed submission:

import copy
import sys

# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)

def dfs(graph, v, d):
    seen[v] = True # 訪問済みかどうか
    dist[v] = d # 距離を記録

    # 頂点vから行ける頂点を全探索
    for i in graph[v]:
        if seen[i]:
            continue
        dfs(graph, i, d+1)

# ここから本文
N, u, v = map(int, input().split())

u -= 1
v -= 1

# グラフ構造を作る
graph = [[] for i in range(N)]
for i in range(N - 1):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    graph[A].append(B)
    graph[B].append(A)

# 青木くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, v, 0)
aoki_dist = copy.deepcopy(dist)

# 高橋くんからの各頂点の距離
seen = [False for i in range(N)]
dist = [0 for i in range(N)]
dfs(graph, u, 0)
takahashi_dist = copy.deepcopy(dist)

ans = 0
for i in range(N):
    if aoki_dist[i] > takahashi_dist[i]:
        if aoki_dist[i] - 1 > ans:
            ans = aoki_dist[i] - 1      

print(ans)