Harryxun/stf_run huggingface dataset:
import math
import sys

sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A.sort()
mx = 10 ** 9
idx = 0
g = []
for i in range(N-1):
    tmp = math.gcd(A[i], A[i+1])
    #print(A[i], A[i+1], tmp)
    if tmp < mx:
        mx = tmp
        idx = i
    g.append([tmp, i])
g.sort(key=lambda x:x[0])
print(g)
if N > 2:
    if g[0][1] + 1 == g[1][1]:
        A.remove(A[g[0][1]+1])
    else :
        tmp1 = math.gcd(A[g[0][1]], A[g[0][1]])
        tmp2 = math.gcd(A[g[0][1]+1], A[g[0][1]+1])
        #print(tmp1, tmp2)
        A.remove(A[g[0][1]] if tmp1 > tmp2 else A[g[0][1]+1])
else :
    A = [max(A)]
tmp = A[0]
for i in A:
    tmp = math.gcd(i, tmp)
print(tmp)


### FIXED CODE ###

from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

L = []
R = []
tl = A[0]
tr = A[-1]
for i in range(N):
  tl = gcd(tl, A[i])
  L.append(tl)
  tr = gcd(tr, A[N-1-i])
  R.append(tr)
mx = 1
R.reverse()
for i in range(N):
  tl = L[i-1] if i else R[i+1]
  tr = R[i+1] if i+1 < N else L[i-1]
  mx = max(mx, gcd(tl, tr))
print(mx)
def main():
    n, m = map(int, input().split())
    switch_list = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ret = 0
    for j in range(2**n):
        cnt = 0
        for i in range(m):
            flag = 1
            for k in switch_list[i][1:]:
                if j & 2**(k-1):
                    total += 1
            if not total%2 == p[i]:
                flag = 0
                break
        if flag:
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

### FIXED CODE ###

'''
https://atcoder.jp/contests/abc128/tasks/abc128_c
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque

    #mod = 1000000007

    n, m = map(int, input().split())
    switch_list = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ret = 0
    for j in range(2**n):
        cnt = 0
        for i in range(m):
            total = 0
            for k in switch_list[i][1:]:
                if j & 2**(k-1):
                    total += 1
            if total%2 == p[i]:
                cnt += 1
            else:
                break
        if cnt == m:
            ret += 1
    print(ret)
if __name__ == '__main__':
    main()
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int N;
    scanf("%d",&N);

    int M[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++) scanf("%d",&M[i][j]);
    }
    
    //累積和をとる
    for(int i=1;i<N;i++) M[0][i]+=M[0][i-1];
    for(int i=N-2;i>=0;i--) M[1][i]+=M[1][i+1];
    
    int ans=0;
    for(int i=0;i<N;i++) ans=MAX(ans, M[0][i]+M[1][i]);
    printf("%d\n",ans);
    
    return 0;
}

### FIXED CODE ###

#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

MOD = 10**9+7

N = int(input())
A = [list(map(int, input().split())) for i in range(2)]

ans = 0
for i in range(N):
    tmp = 0
    for j in range(i+1):
        tmp += A[0][j]
    for j in range(i,N):
        tmp += A[1][j]
    ans = max(ans,tmp)

print(ans)
n, m, v, p = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l = sorted(l, reverse=True)

# print(l)

s = [0]

for i in range(1, n+1):
    s.append(s[-1] + l[-i])
s = sorted(s, reverse=True)

# print(s)

for i in range(p, n):
    x = (l[i] + m) * (i - p + 1) - (s[p - 1] - s[i])
    # print('i',i)
    # print('(l[i] + m)', (l[i] + m))
    # print('(i - p + 1)', (i - p + 1))
    # print('(s[p - 1] - s[i])', (s[p - 1] - s[i]))
    # print('x',x)
    y = 0
    if v >= (n - i) + (p - 1):
        y = v - (n - i) - (p - 1)

    # print('y * m', y * m)

    if x < y * m:
        ans = i
        break
print(ans)


### FIXED CODE ###

n, m, v, p = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l = sorted(l, reverse=True)

# print(l)

s = [0]


for i in range(1, n+1):
    s.append(s[-1] + l[-i])
s = sorted(s, reverse=True)

# print(s)

for i in range(p, n):
    if l[i] + m < l[p - 1]:
        ans = i
        break
    x = (l[i] + m) * (i - p + 1) - (s[p - 1] - s[i])
    # print('i',i)
    # print('(l[i] + m)', (l[i] + m))
    # print('(i - p + 1)', (i - p + 1))
    # print('(s[p - 1] - s[i])', (s[p - 1] - s[i]))
    # print('x',x)
    y = 0
    if v >= (n - i) + (p - 1):
        y = v - (n - i) - (p - 1)

    # print('y * m', y * m)

    if x < y * m:
        ans = i
        break

    if i == n-1:
        ans = n

print(ans)
from operator import itemgetter
n = int(input())
rest = []
for i in range(n):
  s, p = map(str, input().split())
  rest.append([i+1, s, int(p)])

  rest = sorted(rest, key=itemgetter(2), reverse=True)
  rest = sorted(rest, key=itemgetter(1))
  for i in range(n):
    print(rest[i][0])

### FIXED CODE ###

def Guidebook():
    n = int(input())
    rest = []
    for i in range(n):
        s, p = map(str, input().split())
        rest.append([i+1, s, int(p)])

    rest.sort(key=lambda x:x[2], reverse=True)
    rest.sort(key=lambda x:x[1])
    for i in range(n):
        print(rest[i][0])
if __name__ == "__main__":
    Guidebook()
import sys
n,k = map(int,input().split())
if n%k < abs((n%k) - k):
    print(n%k)
    sys.exit(n%k)
print(abs((n%k) - k))

### FIXED CODE ###

import sys
n,k = map(int,input().split())
if n%k < abs((n%k) - k):
    print(n%k)
    sys.exit()
print(abs((n%k) - k))
import itertools
import math
H,W,A,B=map(int,raw_input().split())

mod=10**9+7


FACT={}
FACT_INVERSE={}

n=1
for i in range(H+W-1):
	if i==0: n=1
	else: n=(n*i)%mod
	FACT[i]=n

for x,y in FACT.items():
	FACT_INVERSE[x]=pow(FACT[x],10**9+5 ,mod)


def C(n,r):
	return (FACT[n]*FACT_INVERSE[r]*FACT_INVERSE[n-r]) %mod


N=(H-A-1)+B
M=(H-1)+(W-1)-N

p=0
for i in range(H-A,H):
	#print N,i,M,(H-1)-i,C(N,i), C(M,(H-1)-i)
	p+=C(N,i)*C(M,(H-1)-i)		#Count paterens through prohibited point.
	p=p%mod


if C(N+M,(H-1))-p>=0:
	print C(N+M,(H-1))-p
else:
	print C(N+M,(H-1))-p+10**9+7






### FIXED CODE ###

import itertools
import math
H,W,A,B=map(int,raw_input().split())

mod=10**9+7


FACT={}
FACT_INVERSE={}

n=1
for i in range(H+W-1):
	if i==0: n=1
	else: n=(n*i)%mod
	FACT[i]=n

#print FACT

def C(n,r):
	return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod


p=0
for i in range(B,W):
	p+=C(H-A-1+i,i)*C(A-1+W-i-1,W-i-1)
	p=p%mod


print p
n,a = map(int,input().split())
if n%500 > a:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

n = int(input())
a = int(input())
if n%500 > a:
  print("No")
else:
  print("Yes")
num = input()
tate = int(num)
side = int(num)
for i in tate:
    for j in side:
       print("#")
    j += 1
i += 1

### FIXED CODE ###

while True:
    tate, side = map(int, input().split())
    if tate == side == 0 : break
    print((side * "#" + "\n") * tate)
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():
    a,b = i_map()

    def make_divisors(n,m):
        lower_divisors , upper_divisors = [], []
        i = 1
        while i*i <= n:
            if n % i == 0 and m % i == 0:
                lower_divisors.append(i)
                if n%(n//i)==0 and m%(n//i)==0:
                    upper_divisors.append(n//i)
            i += 1
        return lower_divisors + upper_divisors[::-1]

    l = set(make_divisors(a,b))

    def primes(n):
        is_prime = [True] * (n + 1)
        is_prime[0], is_prime[1] = False, 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]]

    L = set(primes(a+b))
    L.add(1)
    print(len(L&l))










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():
    a,b = i_map()

    def prime_decomposition(n):
        i = 2
        table = []
        while i * i <= n: # sqrt(n)で計算が済む
            while n % i == 0:
                n //= i
                table.append(i)
            i += 1
        if n > 1:
            table.append(n)
        return table

    a = set(prime_decomposition(a))
    b = set(prime_decomposition(b))
    print(len(a&b)+1)



if __name__=="__main__":
    main()
w,h,x,y=(map(int,input().split()))
xeven=(w%2==0)
yeven=(h%2==0)
if(xeven and yeven):
	if(x==w//2 and y==w//2):
		print(w*h/2,1)
elif(xeven and x==w//2):
	print(w*h/2,0)
elif(yeven and y==h//2):
	print(w*h/2,0)
else:
	a=[]
	a.append((0,0,0))
	a.append((0,w,0))
	a.append((h,0,0))
	a.append((h,w,0))
	i=0
	while(i<4):
		a[i][2]=(x-a[0])**2+(y-a[1])**2
		i+=1
	a.sort(key=lambda b:b[2])
	mini=a[0]
	maxi=a[4]
	xclose=abs(mini[0]-x)<abs(mini[1]-y)
	slope=abs(x-maxi[0])/abs(y-maxi[1])
	if(xclose):
		ynew=abs(mini[0]-x)/slope
		print(abs(maxi[1]-mini[1])*(abs(x-maxi[0])+ynew)/2,0)
	else:
		ynew=abs(mini[1]-y)*slope
		print(abs(maxi[0]-mini[0])*(abs(y-maxi[1])+ynew)/2,0)

### FIXED CODE ###

w,h,x,y=(map(int,input().split()))


if(x+x==w and y+y==h):
		print(w*h/2,1)
else:
	print(w*h/2,0)
x = int(input()
for i in range(120):
  for j i range(120):
    if i**5-j**5 == x:
        print(i, j)
        break

### FIXED CODE ###

x = int(input())
for i in range(-120, 120):
    for j in range(-120, 120):
        if i**5+j**5 == x:
            print(i,-j)
            exit(0)
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + int(hp / max_slash + 0.9999999))

n, hp = map(int, input().split())
takanas = [map(int, input().split()) for _ in range(n)]
katana(hp, takanas)

### FIXED CODE ###

import math
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + math.ceil(hp / max_slash))

n, hp = map(int, input().split())
takanas = [list(map(int, input().split())) for _ in range(n)]
katana(hp, takanas)
a, b, c = [int(input()) for _ in range(3)]

if (b + c) - a < 1:
    print(0)
else:
    print(b+c-a)

### FIXED CODE ###

a, b, c = map(int, input().split())
ans = b+c-a
if ans < 1:
    print(int(0))
else:
    print(ans)
a,b=map(int,input().split())
n=100

grid=[["#"]*n for _ in range(n//2)]+[["."]*n for _ in range(n//2)]

k=0
cnt=0
for i in range(a-1):
    grid[k][2*i-cnt]="."
    if 2*i==n-2:
        k+=2
        cnt+=n

k=n//2+1
cnt=0
for i in range(b-1):
    grid[k][2*i-cnt]="#"
    if 2*i==n-2:
        k+=2
        cnt+=n
print(100,100)
for i in grid:
    print("".join(i))

### FIXED CODE ###

a,b=map(int,input().split())
n=100

grid=[["#"]*n for _ in range(n//2)]+[["."]*n for _ in range(n//2)]

k=0
cnt=0
for i in range(a-1):
    grid[k][2*i-cnt]="."
    if (2*i)%100==n-2:
        k+=2
        cnt+=n

k=n//2+1
cnt=0
for i in range(b-1):
    grid[k][2*i-cnt]="#"
    if (2*i)%100==n-2:
        k+=2
        cnt+=n
print(100,100)
for i in grid:
    print("".join(i))
n,d= map(int, input().split())
x,y=[int(input()) for i in range(n)]
s=0
def distance_count():
  
  for i in range(N)
  　　if (x[i]**2 + y[i]**2)**(1/2)<= D :
     　　s=s+1
  return s
answer = distance_count(x,y)
print(answer)

### FIXED CODE ###

N,D = map(int, input().split())
XY = [map(int, input().split()) for _ in range(N)]
X,Y = [list(i) for i in zip(*XY)]

s=0
for i in range (N):
  if X[i]*X[i]+Y[i]*Y[i]<=D*D:
    s=s+1
print(s)
N = int(input())
A = list(map(int, input().split())
if sum(A)%2:
    print("NO")
else:
    print("YES")

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
if sum(A)%2:
    print("NO")
else:
    print("YES")
s = input()
2. 
3.# sを分解して1の数をカウントする
4.print(s.count('1'))


### FIXED CODE ###

s = input()
 
print(int(s[0])+int(s[1])+int(s[2]))
n,a,b=map(int, input().split())

balls= ""
count = 0
blue = 0

for i in range(10**18):
  count= count+1
  if count % 2 == 1:
    balls = balls +'b'*a
  else:
    balls = balls +'r'*b
  if i > n:
    break

for i in range(n):
  if balls[i] == 'b':
  	blue = blue+1

print(blue)

### FIXED CODE ###

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

balls= 0
blue = 0

time = n // (a+b)
tmp = n % (a+b)
if tmp < a:
  blue = time*a + tmp
else:
  blue = (time+1)*a

print(blue)
a,b,c = map(int,input(),split())
print((a*b)/2)


### FIXED CODE ###

a,b,c = map(int,input().split())
print(a*b//2)
x, n = map(int, input().split());
if n == 0:
    print(x);
if n == 1:
    b = int(input());
    if b == x:
        print(x-1);
    else:
        print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
        
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);

### FIXED CODE ###

x, n = map(int, input().split());
if n == 0:
    print(x);
elif n == 1:
    b = int(input());
    if b == x:
        print(x-1);
    else:
        print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
        
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);
import math
n = int(input())
if n%2==1:
    print(0)
else:
    print(sum([n//(2*pow(5,i)) for i in range(1,math.ceil(math.log(n,5)))]))

### FIXED CODE ###

import math
n = int(input())
if n%2==1:
    print(0)
else:
    print(sum([n//(2*pow(5,i)) for i in range(1,math.ceil(math.log(n+1,5)))]))
# coding:utf-8


def inpl(): return list(map(int, input().split()))


H, W = inpl()
board = []
for i in range(H):
    board.append(inpl())

ans = []
cnt = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if w + 1 < W:
                    board[h][w + 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w + 2])
                    cnt += 1
                elif h + 1 < H:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
                    cnt += 1

    else:
        for w in range(W)[::-1]:
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if 0 < w - 1:
                    board[h][w - 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w])
                    cnt += 1
                elif 0 < h - 1:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
                    cnt += 1

print(cnt)

for a in ans:
    print(' '.join(map(str, a)))

### FIXED CODE ###

# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

H, W = inpl()
mass = []
coin = 0
for i in range(H):
    tmp = inpl()
    coin += sum(tmp)
    mass.append(tmp)

odd = []
for h in range(H):
    for w in range(W):
        if mass[h][w] % 2 == 1:
            odd.append([h, w])

count = 0
ans = []
odd.sort()
for i in range(H):
    for j in range(W):
        if mass[i][j] & 1:
            if j < W - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
                mass[i][j] -= 1
                mass[i][j + 1] += 1
            elif i < H - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 2, j + 1])
                mass[i][j] -= 1
                mass[i + 1][j] += 1

print(count)
for a in ans:
    print(' '.join(map(str, a)))
array_length = raw_input()
unsorted_array = list(map(int, raw_input().split()))

for i in range(array_length):
    v = unsorted_array[i]
    j = i - 1
    while j >= 0 and unsorted_array[j] > v:
        unsorted_array[j + 1] = unsorted_array[j]
        j -= 1
    unsorted_array[j + 1] = v
    print(" ".join(str(i) for i in unsorted_array))

### FIXED CODE ###

#!/usr/bin/env python
# encoding: utf-8

from __future__ import print_function


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def insertion_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        for i in range(array_length):
            v = unsorted_array[i]
            j = i - 1
            while j >= 0 and unsorted_array[j] > v:
                unsorted_array[j + 1] = unsorted_array[j]
                j -= 1
            unsorted_array[j + 1] = v
            print(" ".join(map(str, unsorted_array)))


if __name__ == '__main__':
    solution = Solution()
    solution.insertion_sort()
a,b,c,d = map(int,input(),split())

if abs(a-b) <= d:
    print('YES')

elif abs(a-b) <= d and abs(b-c) <= d:
    print('YES')

else:
    print('NO')



### FIXED CODE ###

a,b,c,d = map(int,input().split())

if abs(a-c) <= d:
    print('Yes')

elif abs(a-b) <= d and abs(b-c) <= d:
    print('Yes')

else:
    print('No')
N = int(input())
A = map(int, input().split())
ans = 0

for i in range(N):
  for j in range(i+1, N):
    ans = max(ans, abs(A[i] - A[j]))

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
 
for i in range(N):
  for j in range(i+1, N):
    ans = max(ans, abs(A[i] - A[j]))
 
print(ans)
n = int(input())
lst = [int(e) for e in input().split(' ')]

lst = sorted(lst)

valid_list = []
if n % 2 == 1:
    # 奇数
    valid_list.append(0)
    for i in range(1, int((n + 1) / 2)):
        valid_list.append(i * 2)
        valid_list.append(i * 2)
    if lst == valid_list:
        print((2 ** (((n - 1) / 2) / 5) % 1000000007) ** 5 % 1000000007)
    else:
        print(0)
else:
    for i in range(1, int((n / 2) + 1)):
        valid_list.append((i * 2) - 1)
        valid_list.append((i * 2) - 1)
    if lst == valid_list:
        print(int(2 ** ((n / 2) / 5) % 1000000007) ** 5 % 1000000007)
    else:
        print(0)


### FIXED CODE ###

## 2 * 100000 % 1000000007 の高速計算法がわからずOUT

n = int(input())
lst = [int(e) for e in input().split(' ')]

lst = sorted(lst)
result = 1

valid_list = []
if n % 2 == 1:
    # 奇数
    valid_list.append(0)
    for i in range(1, int((n + 1) / 2)):
        valid_list.append(i * 2)
        valid_list.append(i * 2)
    if lst == valid_list:
        for i in range(int((n - 1) / 2)):
            result = (result * 2) % 1000000007
        print(int(result))
    else:
        print(0)
else:
    for i in range(1, int((n / 2) + 1)):
        valid_list.append((i * 2) - 1)
        valid_list.append((i * 2) - 1)
    if lst == valid_list:
        for i in range(int(n / 2)):
            result = (result * 2) % 1000000007
        print(int(result))
    else:
        print(0)
n,u,v=map(int,input().split())
u=u-1
v=v-1
edge=[]
for i in range(n-1):
    a,b=map(int,input().split())
    edge.append((a-1,b-1))
dp1=[-1]*n
dp1[u]=0
dp2=[-1]*n
dp2[v]=0

root=[[] for i in range(n)]
for a,b in edge:
    root[a].append(b)
    root[b].append(a)

def dfs(node,depth,par,dp):
    for vertex in root[node]:
        if vertex == par:
            continue
        dp[vertex]=depth+1
        dfs(vertex,depth+1,node,dp)
dfs(u,0,u,dp1)
dfs(v,0,v,dp2)
buf=-1
buf1=0
#print(dp1,dp2,root)
for i in range(n):
    if dp1[i]<dp2[i] and dp2[i]>buf:
        buf=dp2[i]
        buf1=dp1[i]
print(buf-1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
n,u,v=map(int,input().split())
u=u-1
v=v-1
root=[[] for i in range(n)]

for i in range(n-1):
    a,b=map(int,input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)

dp=[[-1]*n for i in range(2)]
dp[0][u]=0
dp[1][v]=0
def dfs(node,depth,par,flag):
    for vertex in root[node]:
        if vertex == par or dp[flag][vertex]!=-1:
            continue
        dp[flag][vertex]=depth+1
        dfs(vertex,depth+1,node,flag)
    return
dfs(u,0,u,0)
dfs(v,0,v,1)
buf=-1
buf1=0
#print(dp1,dp2,root)
for i in range(n):
    if dp[0][i]<dp[1][i] and dp[1][i]>buf:
        buf=dp[1][i]
        buf1=dp[0][i]
print(buf-1)
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC0 = [0]*M
for m in range(M):
    BC0[m] = list(map(int, input().split()))
A.sort()
BC0.sort(key=lambda x:x[1])
BC = []
for bc0 in BC0:
    BC = BC + [bc0[1]]*bc0[0]

S = []
while len(S)<N:
    if len(A)==0:
        S = S + A[-(N-len(S))]
    elif A[-1] >= BC[-1]:
        S.append(A.pop())
    else:
        S.append(BC.pop())
        
print(sum(S))

### FIXED CODE ###

N, M = map(int, input().split())
A0 = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A = [[1,a] for a in A0] 
ABC = A + BC
ABC.sort(key=lambda x:x[1], reverse=True)

summation = 0
p = 0
n = 0

while n<N:
    summation += ABC[p][1] * (min(ABC[p][0], N-n))
    n += min(ABC[p][0], N-n)
    p += 1

print(summation)
BIG_NUM = 10**18

N, K = map(int, input().split(" "))
H = list(map(int, input().split(" ")))

l = [BIG_NUM]*(N+200)
l[0] = 0
for i in range(1, N):
    l[i] = min([
        l[i-j] + abs(H[i]-H[i-j]) for j in range(1, min(N, K, i)+1)
    ])

# print(l)
print(l[N-1])

### FIXED CODE ###

BIG_NUM = 10**18

N = int(input())
H = list(map(int, input().split(" ")))

l = [BIG_NUM] * (N+10)
l[0] = 0

for i in range(1, N):
    l[i] = min(
        l[i-1] + abs(H[i] - H[i-1]),
        l[i-2] + abs(H[i] - H[i-2]),
    )

print(l[N-1])
n = int(input())
if n > 29:
  print("Yes")
  elif 0 < n <= 29:
    print("No")

### FIXED CODE ###

n = int(input())

if 30 <= n <= 40:
  print('Yes')
else:
  print('No')
from collections import*;C=Counter;print('YNeos'[eval('!=C(C(input()).values())'*2[2:])::2])

### FIXED CODE ###

s,t=[0]*26,[0]*26
for a,b in zip(input(),input()):
  s[ord(a)-ord('a')]+=1
  t[ord(b)-ord('a')]+=1
u,v=[],[]
for a,b in zip(s,t):
  if a!=b:
    u.append(a)
    v.append(b)
print('YNeos'[sorted(u)!=sorted(v)::2])
num, base = input()
print(int(log(int(num), int(base)) + 1)

### FIXED CODE ###

import math

num, base = input().split(' ')
print(int(math.log(int(num), int(base)) + 1))