Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03012 (python)

Fixed submission:
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

n=int(input())

w=list(map(int, input().split()))

m = 1000000000

for i in range(n - 1):
    a = sum(w[:i + 1])
    b = sum(w[i+ 1:])
    m = min(abs(a-b), m)

print(m)

Buggy submission (verdict: Runtime Error):
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
import itertools
from math import factorial

from operator import mul
from functools import reduce

"""
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
"""
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


div_num  = 1000000007

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

dmg = [int(input()) for _ in range(M)]

for i in range(M - 1):
    # 連番なら終了
    if dmg[i] + 1 == (dmg[i + 1]):
        print(0)
        exit()

comb_list = []
start = 0
for i in range(len(dmg) + 1):
    if i == len(dmg):
        interval = N - start
    else:
        interval = (dmg[i] - 1) - start
    j = 0
    comb_sum = 0
    while True:
        if (2 * j) > interval:
            break
        num_ptn_1_2 = j + (interval - (2 * j))
        r = j
        #comb_sum += int(factorial(num_ptn_1_2) / factorial(r) / factorial(num_ptn_1_2 - r))
        comb_sum += cmb(num_ptn_1_2,r)
        j += 1
    if i < len(dmg):
        # 壊れた階段の次を始点にする
        start = dmg[i] + 1
    comb_list.append(comb_sum)

result = 1

for elem in comb_list:
    result *= elem

print(result % div_num)
Problem p03013 (python)

Fixed submission:
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
import itertools

mod  = 1000000007

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

broken = [0 for _ in range(N + 2)]

for i in range(M):
    n = int(input())
    broken[n] = True

dp = [0 for _ in range(N + 2)]
dp[N] = 1
for i in range(0, N)[::-1]:
    if broken[i]:
        dp[i] = 0
        continue
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod

print(dp[0])

Buggy submission (verdict: Runtime Error):
import sys


"""
# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    N , M = map(int, sys.stdin.readline().split())
    A = [int(sys.stdin.readline()) for _ in range(M)]
    broken = [True if i in A else False for i in range(N + 1)]
    L = [0] * (N + 1)
    L[0] = 1
    if not broken[1]:
        L[1] = 1
    for i in range(2, N + 1):
        if not broken[i]:
            L[i] = L[i - 1] + L[i - 2]
    print(L[N] % mod)

Buggy submission (verdict: Runtime Error):
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
import itertools
from math import factorial


div_num  = 1000000007

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

dmg = [int(input()) for _ in range(M)]

for i in range(M - 1):
    # 連番なら終了
    if dmg[i] == (dmg[i + 1] - 1):
        print(0)
        exit()

comb_list = []
start = 0
for i in range(len(dmg) + 1):
    if i == len(dmg):
        n = N - start
    else:
        n = (dmg[i] - 1) - start
    j = 0
    comb_sum = 0
    while True:
        if 2 * j > n:
            break
        num = j + (n - (2 * j))
        r = j
        comb_sum += int(factorial(num) / factorial(r) / factorial(num - r))
        j += 1
    if i < len(dmg):
        start = dmg[i] + 1
    comb_list.append(comb_sum)

result = 1

for elem in comb_list:
    result *= elem

print(result % div_num)
Problem p03038 (python)

Fixed submission:
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
from time import time

N,M=map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
update = []

for _ in range(M):
    temp = list(map(int, input().split()))
    update.append(temp)

# C_i の値をkeyにしてソートする
update = sorted(update,key = lambda x:x[1], reverse=True)

idx = 0
for b, c in update:
    for i in range(b):
        if idx >= N:
            break
        if A[idx] < c:
            A[idx] = c
            idx += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy


N,M=map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
update = []

for _ in range(M):
    B,C=map(int, input().split())
    for _ in range(B):
        update.append(C)

update = sorted(update,reverse=True)

max_sum = sum(A)

for i in range(N):
    if i > len(update):
        break
    if(A[i] > update[i]):
        break
    A[i] = update[i]
    max_sum = max(max_sum, sum(A))

print(max_sum)
Problem p03107 (python)

Fixed submission:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    bit = list(sys.stdin.readline().rstrip())
    print(2 * min(bit.count("0"), bit.count("1")))

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    bit = list(sys.stdin.readline().rstrip())
    print(2 * min(bit.count("0"), bit.count("1")))
Problem p02711 (python)

Fixed submission:
a=str(input())
if a[0] =='7' or a[1] =='7' or a[2]=='7':
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a=str(input())
if a[0] or a[1] or a[2]==7:
    
    print("Yes")
elif :
    print("No")
Problem p02819 (python)

Fixed submission:
x =  int(input())
 
def primes(z, n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if (is_prime[i]) and (i>=z) ]

Prime = primes(x, (10**5)+4)
ans = Prime[0]
print(ans)

Buggy submission (verdict: Runtime Error):
x =  int(input())
 
def primes(z, n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if (is_prime[i]) and (i>=z) ]

Prime = primes(x, 10**5)
ans = Prime[0]
print(ans)

Buggy submission (verdict: Runtime Error):
x =  int(input())

def primes(z, n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if (is_prime[i]) and (i>=z) ]

Prime = primes(x, 10**5)
ans = Prime[0]
print(ans)
Problem p02862 (python)

Fixed submission:
def cmb(m, n):
    if m - n < n:
        n = m - n
    if n == 0:
        return 1
    if n == 1:
        return m
    
    numerator = [m - n + k + 1 for k in range(n)]
    denominator = [k + 1 for k in range(n)]

    for p in range(2, n+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (m-n) % p
            for k in range(p-1, n, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    
    result = 1
    for k in range(n):
        if numerator[k] > 1:
            result = result * int(numerator[k]) % (10**9 + 7)

    return result

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

if (X+Y) % 3 != 0:
    print(0)
else:
    m = int((2*X - Y) / 3)
    n = int((2*Y - X) / 3)
    if m < 0 or n < 0:
        print(0)
    else:
        ans = cmb(m+n, n)
        print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

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

if (X+Y) % 3 != 0:
    print(0)
else:
    m = (2*X - Y) / 3
    n = (2*Y - X) / 3
    if m < 0 or n < 0:
        print(0)
    else:
        ans = math.factorial(m+n)% (1e+7 + 7) / (math.factorial(m) * math.factorial(n))
        print(int(ans))
Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

cb_dict = {}
for _ in range(m):
    b, c = map(int, input().split())
    new = {c:b}
    if c in cb_dict.keys():
        cb_dict[c] += b
    else:
        cb_dict.update(new)

cb_dict = sorted(cb_dict.items(), key=lambda x:x[0], reverse=True)

now_c = 0
now_b = 0
for i in range(n):
    if A[i] >= cb_dict[now_c][0]:
        break
    else:
        A[i] = cb_dict[now_c][0]
        now_b += 1
        if now_b == cb_dict[now_c][1]:
            now_c += 1
            now_b = 0
        if now_c > len(cb_dict)-1:
            break

ans = sum(A)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

cb_dict = {}
for _ in range(m):
    b, c = map(int, input().split())
    new = {c:b}
    if c in cb_dict.keys():
        cb_dict[c] += b
    else:
        cb_dict.update(new)

cb_dict = sorted(cb_dict.items(), key=lambda x:x[0], reverse=True)

now_c = 0
now_b = 0
for i in range(n):
    if A[i] =< cb_dict[now_c][0]:
        A[i] = cb_dict[now_c][0]
        now_b += 1
    if now_b == cb_dict[now_c][1]:
        now_c += 1
    if now_c > len(cb_dict)-1:
        break

ans = sum(A)
print(ans)
Problem p03053 (python)

Fixed submission:
from collections import deque

h, w = map(int, input().split())
Black = deque([])
Black_grid = [[-1 for _ in range(w)] for _ in range(h)]

for i in range(h):
    a = str(input())
    for j in range(w):
        if a[j] == '#':
            Black.append([j,i])
            Black_grid[i][j] = 0

Move = [[-1,0],[1,0],[0,-1],[0,1]]

while Black:
    now = Black.popleft()
    x = now[0]
    y = now[1]
    for move in Move:
        x_next = x + move[0]
        y_next = y + move[1]
        if x_next < 0 or x_next >= w or y_next < 0 or y_next >= h:
            continue
        elif Black_grid[y_next][x_next] >= 0:
            continue
        else:
            Black.append([x_next, y_next])
            Black_grid[y_next][x_next] = Black_grid[y][x] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, Black_grid[i][j])
    
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

h, w = map(int, input().split())
Black = deque([])
White = deque([])
Black_grid = [[-1 for _ in range(w)] for _ in range(h)]

for i in range(h):
    a = str(input())
    for j in range(w):
        if a[j] == '#':
            Black.append([i,j])
            Black_grid[j][i] = 0
        else:
            White.append([i,j])

Move = [[-1,0],[1,0],[0,-1],[0,1]]


while Black:
    now = Black.popleft()
    x = now[0]
    y = now[1]
    for move in Move:
        x_next = x + move[0]
        y_next = y + move[1]
        if x_next < 0 or x_next >= w or y_next < 0 or y_next >= h:
            continue
        elif Black_grid[y_next][x_next] >= 0:
            continue
        else:
            Black.append([x_next, y_next])
            Black_grid[y_next][x_next] = Black_grid[y][x] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, Black_grid[i][j])
    
print(ans)
Problem p02711 (python)

Fixed submission:
num = input()

for x in num:
	if x == '7':
		print ("Yes")
		exit()

print ("No")

Buggy submission (verdict: Runtime Error):
def find_7(num):
	num_list = list(map(int, str(num)))
	count = 0
	for x in num_list:
		count += 1
		if x == 7:
			return "Yes"
		elif count == len(num_list):
			return "No"

if __name__ == '__main__':
	print (find_7())
Problem p02951 (python)

Fixed submission:
a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
if a>=b+c:
    print(0)
     
else:
    print(b+c-a)

Buggy submission (verdict: Runtime Error):
a, b, c = input().spilt()

if a>=b+c:
  print(0)

else:
  print(b+c-a)
Problem p02771 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a == b and a != c:
    print("Yes")
elif a == c and a != b:
    print("Yes")
elif b == c and b != a:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
  GNU nano 4.3                                  main                                   変更済み  
a,b,c=map(int,input().split())
if a == b and a != c:
    print("Yes")
elif a == c and a != b:
    print("Yes")
elif b == c and b != a:
    print("Yes")
else:
    print("No")
Problem p02711 (python)

Fixed submission:
N = input()

def a(N):
	for c in N:
		if c == "7":
			return "Yes"
	return "No"
 
print(a(N))

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

def a(N):
	for c in N:
  		if c = "7":
    		return "Yes"
    return "No"
 
print(a(N))
Problem p02785 (python)

Fixed submission:
N,K = list(map(int,input().split()))
Hi = list(map(int,input().split()))
Hi.sort()
Hi.reverse()

del Hi[:K]
print(sum(Hi))

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
Hi = sorted(list(map(int,input().split())))

if N <= K:
    print(0)
else:
    for num in range(K):
        Hi.pop((num+1)*-1)
    print(sum(Hi))

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
Hi = sorted(list(map(int,input().split())))

if len(Hi) <= K:
    print(0)
else:
    for num in range(K):
        Hi.pop((num+1)*-1)
    print(sum(Hi))
Problem p02836 (python)

Fixed submission:
S = input()

def kaibun(string):
    count = 0
    strli = list(string)
    for i in range(len(string)//2):
        if strli[i] == strli [-i-1]:
            continue
        else:
            count += 1
    return count

print(kaibun(S))

Buggy submission (verdict: Runtime Error):
S = input()

def kaibun(string):
    count = 0
    strli = list(string)
    for i in range(len(string)/2):
        if strli[i] == strli [-i-1]:
            continue
        else:
            count += 1
    return count

print(kaibun(S))
Problem p02990 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

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

red = n - blue

waru = 10**9+7

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(1, blue+1, 1):
    if red + 1 < i:
        print(0) 
    else:
        ans = cmb(red+1, i) * cmb(blue-1, i-1)
        #print(i)
        print(ans%waru)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

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

red = n - blue

waru = 10**9+7

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


for i in range(1, blue+1):
    ans = cmb(red+1, i) * cmb(blue-1, i-1)
    print(ans%waru)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

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

red = n - blue

waru = 10**9+7

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


for i in range(1, blue+1):
    ans = cmb(red+1, i) * cmb(blue-1, i-1)
    print(ans%waru)
Problem p03774 (python)

Fixed submission:
n, m = map(int, input().split())
a = []
b = []
c = []
d = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp[0])
    b.append(temp[1])


for i in range(m):
    temp = list(map(int, input().split()))
    c.append(temp[0])
    d.append(temp[1])

ans = []

for i in range(n):
    min_dis = 10 ** 9
    for j in range(m):

        distance = abs(c[j] - a[i]) + abs(d[j] - b[i])

        #print("学生{}, {} チェックポイント{}, {}".format(a[i], b[i], c[j], d[j]))
        #print("距離番号{} = {}".format(j, distance))
        
        if min_dis > distance:
            min_dis = distance
            min_num = j
            #print("更新")
        
    ans.append(min_num)
    
for i in range(n):
    print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = []
b = []
c = []
d = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp[0])
    b.append(temp[1])


for i in range(m):
    temp = list(map(int, input().split()))
    c.append(temp[0])
    d.append(temp[1])

ans = []

for i in range(n):
    min_dis = 1000
    for j in range(m):

        distance = abs(c[j] - a[i]) + abs(d[j] - b[i])

        #print("学生{}, {} チェックポイント{}, {}".format(a[i], b[i], c[j], d[j]))
        #print("距離番号{} = {}".format(j, distance))
        
        if min_dis > distance:
            min_dis = distance
            min_num = j
            #print("更新")
        
    ans.append(min_num)
    
for i in range(n):
    print(ans[i] + 1)
Problem p02712 (python)

Fixed submission:
total = 0
for i in range(int(input())):
  if int((i+1) % 3) != 0:
    if int((i+1) % 5) != 0:
    	total += i+1
        
print(total)

Buggy submission (verdict: Runtime Error):
n = [int(i+1) for i in range(input())]

total = 0
for i in n:
  	if (n % 3 =! 0) and (n % 5 =! 0):
      	total += i
        
print(total)
Problem p02831 (python)

Fixed submission:
a, b = map(int, input().split())

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z

lcm = a * b / gcd(a, b)
print(int(lcm))

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())

lcm = a * b / math.gcd(a, b)
print(int(lcm))
Problem p02832 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
i = 0
j = 0
f_flg = 0
while i < len(a) and j < len(a):
    while a[j] != i + 1:
        cnt += 1
        j += 1
#         print(j)
        if j > len(a) - 1:
            if f_flg == 0:
                print(-1)
                exit()
            break
    f_flg = 1
    i += 1
    j += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
i = 0
while i < len(a):
    while a[i] != i + 1:
        cnt += 1
        a.pop(i)
        if len(a) == 0:
            break
    i += 1
if a == []:
    print(-1)
else:
    print(cnt)
Problem p02834 (python)

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

def dfs(v, dist, d = 0, p = -1):
#     print(v, d)
    dist[v] = d
    for u in to[v]:
        if u == p:
            continue
        dfs(u, dist, d + 1, v)
def calcDist(s, dist):
    dfs(s, dist)        
n, u, v = map(int, input().split())
u -= 1
v -= 1
to = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
distS = [0] * n
distT = [0] * n
calcDist(u, distS)
calcDist(v, distT)
mx = 0
for i in range(n):
    if distS[i] < distT[i]:
        mx = max(mx, distT[i])
ans = mx - 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 8)

n, u, v = map(int, input().split())
to = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

def DFS(s, dist, to, d = 0, p = -1):
    dist[s] = d
    for v in to[s]:
        if v == p:
            continue
        DFS(v, dist, to, d + 1, s)
    
def calcDict(s, dist, to):
    DFS(s, dist, to)
    
distU = [0] * (n + 1)
distV = [0] * (n + 1)

calcDist(u, distU, to)
calcDist(v, distV, to)
ans = 0
for i in range(n + 1):
    if dictU[i] < dictV[i]:
        ans = max(ans, dictV[i])
print(ans - 1)

Buggy submission (verdict: Runtime Error):
def dfs(v, dist, d = 0, p = -1):
#     print(v, d)
    dist[v] = d
    for u in to[v]:
        if u == p:
            continue
        dfs(u, dist, d + 1, v)
def calcDist(s, dist):
    dfs(s, dist)        
n, u, v = map(int, input().split())
u -= 1
v -= 1
to = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
distS = [0] * n
distT = [0] * n
calcDist(u, distS)
calcDist(v, distT)
mx = 0
for i in range(n):
    if distS[i] < distT[i]:
        mx = max(mx, distT[i])
ans = mx - 1
print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(v, dist, d = 0, p = -1):
#     print(v, d)
    dist[v] = d
    for u in to[v]:
        if u == p:
            continue
        dfs(u, dist, d + 1, v)
def calcDist(s, dist):
    dfs(s, dist)        
n, u, v = map(int, input().split())
u -= 1
v -= 1
to = [[] for _ in range(100005)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
distS = [0] * n
distT = [0] * n
calcDist(u, distS)
calcDist(v, distT)
mx = 0
for i in range(n):
    if distS[i] < distT[i]:
        mx = max(mx, distT[i])
ans = mx - 1
print(ans)