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

n = int(input())
s = [0] * n
for i in range(n):
    s[i] = int(input())

ans = 0
for i in range(2 ** n):
    score = 0
    for j in range(n):
        if i >> j & 1:
            score += s[j]
        
    if score % 10 != 0:
        ans = max(ans, score)

print(ans)



### FIXED CODE ###

n = int(input())
s = [0] * n
for i in range(n):
    s[i] = int(input())

ans = sum(s)
if ans % 10 != 0:
    print(ans)
else:
    s.sort()
    for i in range(n):
        if s[i] % 10 != 0:
            print(ans - s[i])
            exit()
        
    print(0)
### BUGGY CODE ###

#16D8101012J 伊藤惇 dj Python3

def Maximum_Profit(n,A):
    Max=(min(A)-max(A))
    for i in range(n-1):
        for j in range(i+1,n):
            if Max<A[j]-A[i]:
                Max=A[j]-A[i]
    return Max

if __name__ == "__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(int(input()))
    Max=Maximum_Profit(n,A)
    print(Max)


### FIXED CODE ###

#16D8101012J 伊藤惇 dj Python3

def Maximum_Profit(n,A):
    Max=A[1]-A[0]
    Min=A[0]
    for j in range(1,n):
        Max=max(Max,A[j]-Min)
        Min=min(Min,A[j])
    return Max

if __name__ == "__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(int(input()))
    Max=Maximum_Profit(n,A)
    print(Max)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP0 = deepcopy(DP)
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP0[-S[::-1][i]:], max(0, K-S[::-1][i])):
        if d:
            if j + a >= K:
                OK[i] = True
                break
            else:
                DP[j+a] = True
 
if sum(OK) == 0:
    print(N)
else:
    print(OK[::-1].index(True))

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [True]+[False for _ in range(K-1)]

OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP1 = [False] * K
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP[-S[::-1][i]:], max(0, K-S[::-1][i])):
        if d:
            DP1[j] = True
            if j + a >= K:
                OK[i] = True
                break
            else:
                DP1[j+a] = True
    DP = DP1 
if sum(OK) == 0:
    print(N)
else:
    print(OK[::-1].index(True))
### BUGGY CODE ###

import sys
def solve(mid):
    l=k
    for b,g in zip(a,f):
        if b*g>mid:
            l-=b-mid//g
    if l<0:return False
    return True
input=sys.stdin.buffer.readline
n,k=map(int,input().split())
a=sorted(map(int,input().split()))[::-1]
f=sorted(map(int,input().split()))
ok=10**12
ng=-1
while ok-ng>1:
    mid=(ok+ng)//2
    if solve(mid):
        ok=mid
    else:
        ng=mid
print(ok)

### FIXED CODE ###

def main():
    n,k,*a=map(int,open(0).read().split())
    a,f=sorted(a[:n])[::-1],sorted(a[n:])
    ok=10**12
    ng=-1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            if b*g>mid:
                l-=b-mid//g
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()
### BUGGY CODE ###

import sys
N,K,Q =map(int,input().split())
F = {}
a = []
for l in sys.stdin:
    a.append(int(l))

for i in range(N):
    F[str('A'+ str(i+1))] = K
for i in range(N):
    cnt = a.count(i+1)
    F[str('A'+ str(i+1))] = F[str('A'+str(i+1))] - (Q - cnt)
for i in range(N) :
    if F[str('A'+ str(i+1))] >= 1 :
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N,K,Q=map(int,input().split())
L=[K]*N
for i in range(Q):
    A=int(input())
    L[A-1] += 1

for i in L:
    if i - Q > 0 :
        print("Yes")
    else :
        print("No")
### BUGGY CODE ###

S = str(input())
Q = int(input())
flip = 0
for i in range(Q):
  j = input()
  if len(j) == 1:
    flip += 1
    continue
  else:
    if j[2] == '1' and flip % 2 == 0:
      S = j[4] + S
    elif j[2] == '2' and flip % 2 == 0:
      S = S + j[4]
    elif j[2] == '1' and flip % 2 ==1:
      S = S + j[4]
    elif j[2] == '2' and flip % 2 ==1:
      S = j[4] + S
if flip % 2 == 1:
  S = S[::-1]
print(S)

### FIXED CODE ###

S = str(input())
Q = int(input())
flip = 0
front,back = '',''
for i in range(Q):
  j = input()
  if len(j) == 1:
    flip += 1
    continue
  else:
    if j[2] == '1' and flip % 2 == 0:
      front = j[4] + front
      continue
    elif j[2] == '2' and flip % 2 == 0:
      back = back + j[4]
      continue
    elif j[2] == '1' and flip % 2 ==1:
      back= back + j[4]
      continue
    elif j[2] == '2' and flip % 2 ==1:
      front = j[4] + front
      continue
S = front + S + back
if flip % 2 == 1:
  S = S[::-1]
print(S)
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp_h = [0] * N
dp_h[1] = abs(h[1] - h[0])
for i in range(2,N):
  tmp_min = abs(h[i] -h[i-1]) + dp_h[i-1]
  for j in range(min(i-1, K-1)):
    tmp = abs(h[i] - h[i - j - 2]) + dp_h[i-j-2]
    if h[i] - h[i-j-2] == 0:
      tmp_min = tmp
      break
    if tmp < tmp_min:
      tmp_min = tmp
  dp_h[i] = tmp_min
print(dp_h[N-1])

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
h = list(map(int, input().split()))
h = np.array(h)
dp = np.zeros(N, dtype = int)
for i in range(1, N):
  j = max(0,i - K)
  dp[i] = np.min(dp[j:i] + np.abs(h[i] - h[j:i]))
print(dp[N-1])
### BUGGY CODE ###

import itertools
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
C=0
for i in A:
    B[i-1]+=1
for i in B:
    C+=len(list(itertools.combinations(range(i),2)))
for i in A:
    print(C-B[i-1]+1)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
C=0
for i in A:
    B[i-1]+=1
for i in B:
    if i>=2:
        C+=i*(i-1)//2
for i in A:
    print(C-B[i-1]+1)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
s=1
for i in range(N):
  s*=A[i]
if s<=10**18:
  print(s)
else:
  print(-1)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
s=1
if 0 in A:
  print(0)
else:
  for i in range(N):
    s*=A[i]
    if s>10**18:
      print(-1)
      break
  if s<=10**18:
    print(s)
### BUGGY CODE ###

import math
mod = 10 ** 9 + 7

n = int(input())
a = [int(i) for i in input().split()]
tmp = a[0]
set_v = a[0]
pairwise = True
for i in range(1, n):
    gcd = math.gcd(tmp, a[i])
    set_v = math.gcd(set_v, a[i])
    if gcd  > 1:
        pairwise = False
    elif gcd == 1:
        setwise = True
    tmp = (a[i] * tmp) // gcd
if pairwise == True:
    ans = 'pairwise coprime'
elif set_v == 1:
    ans = 'setwise coprime'
else:
    ans = 'not coprime'
print(ans)    

### FIXED CODE ###

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return set(a)

import math
mod = 10 ** 9 + 7

n = int(input())
a = [int(i) for i in input().split()]
tmp = a[0]
set_v = a[0]
pairwise = True
prime_list = set([])
for i in range(1, n):
    prime = prime_factorize(a[i])
    set_v = math.gcd(set_v, a[i])
    for p in prime:
        if p in prime_list:
            pairwise = False
        prime_list.add(p)
if pairwise == True:
    ans = 'pairwise coprime'
elif set_v == 1:
    ans = 'setwise coprime'
else:
    ans = 'not coprime'
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
num = 0
for aa in a:
  num = a.count(aa-1)+a.count(aa)+a.count(aa+1)
  ans = max(ans,num)
print(ans)

### FIXED CODE ###

N = int(input())
a = [int(x) for x in input().split()]
memo = [0]*(10**5+2)
ans = 1
for i in range(N):
  memo[a[i]] += 1
  memo[a[i]+1] += 1
  memo[a[i]-1] += 1
print(max(memo))
### BUGGY CODE ###

import numpy as np
n = int(input())
arr = list(map(int,input().split()))
buf = [0 for i in range(61)]

count = [[0,0] for i in range(61)]

for a in arr:
    txt = str(bin(a))[2:].zfill(61)

    for i in range(len(txt)):
        if txt[i] == "0":
            buf[i] += count[i][1]
            count[i][0] += 1
        else:
            buf[i] += count[i][0]
            count[i][1] += 1

m = 10**9 +7

buf.reverse()
ans = 0

for i in range(len(buf)):
    num = buf[i]
    base = np.power(2,i)
    base = base%m
    base = (base*num)%m

    ans += base
    ans = ans%m

# print(buf)
print(ans)





### FIXED CODE ###

n = int(input())
arr = list(map(int,input().split()))
buf = [0 for i in range(61)]

count = [[0,0] for i in range(61)]

for a in arr:
    txt = str(bin(a))[2:].zfill(61)

    for i in range(len(txt)):
        if txt[i] == "0":
            buf[i] += count[i][1]
            count[i][0] += 1
        else:
            buf[i] += count[i][0]
            count[i][1] += 1

m = 10**9 +7

buf.reverse()
ans = 0

for i in range(len(buf)):
    num = buf[i]
    if i == 0:
        base = 1
    else:
        base = base*2
    b = base%m
    b = (b*num)%m

    ans += b
    ans = ans%m

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

#A

"""
s = input().split("/")
if int(s[1]) <= 4:
    print("Heisei")
else:
    print("TBD")
"""
#B
"""
n = int(input())
ans = 0
for i in range(n):
    a = input().split()
    if a[1] == "JPY":
        ans += int(a[0])
    else:
        ans +=  float(a[0]) * 380000
print(ans)
"""

#C
"""
n, a, b, c = map(int, input().split())
abc = [a,b,c]
x = [int(input()) for i in range(n)]
x.sort()
ans = []
flg = 0
for i in x:
    if i in abc:
        ans.append(i)
        flg = 1
if flg:
    for i in ans:
        abc.remove(i)
        x.remove(i)

"""
#D

a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
s.sort()
t.sort()

import bisect


for i in range(q):
    x = int(input())
    s_l = bisect.bisect_left(s, x) - 1
    t_l = bisect.bisect_left(t, x) - 1
    s_r = s_l + 1
    t_r = t_l + 1
    if s_l == -1:
        s_l = 0
    if t_l == -1:
        t_l = 0
    if s_l == a :
        s_l = a - 1
        s_r = a - 1
    if s_r == a:
        s_r = a - 1
    if t_l == b:
        t_l = b - 1
        t_r = b - 1
    if t_r == b:
        t_r = b - 1
    ans = min(abs(t[t_l] - s[s_r]) + min(abs(t[t_l] - x), abs(s[s_r] - x)),
    abs(s[s_l] - t[t_r]) + min(abs(s[s_l] - x), abs(t[t_r] - x)),
    abs(s[s_l] - t[t_l]) + min(abs(s[s_l] - x), abs(t[t_l] - x)),
    abs(s[s_r] - t[t_r]) + min(abs(s[s_r] - x), abs(t[t_r] - x)),
    )
    
    print(ans)


### FIXED CODE ###

#A

"""
s = input().split("/")
if int(s[1]) <= 4:
    print("Heisei")
else:
    print("TBD")
"""
#B
"""
n = int(input())
ans = 0
for i in range(n):
    a = input().split()
    if a[1] == "JPY":
        ans += int(a[0])
    else:
        ans +=  float(a[0]) * 380000
print(ans)
"""

#C
"""
n, a, b, c = map(int, input().split())
abc = [a,b,c]
x = [int(input()) for i in range(n)]
x.sort()
ans = []
flg = 0
for i in x:
    if i in abc:
        ans.append(i)
        flg = 1
if flg:
    for i in ans:
        abc.remove(i)
        x.remove(i)

"""
#D

a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
s.sort()
t.sort()

import bisect


for i in range(q):
    x = int(input())
    s_l = bisect.bisect_left(s, x) - 1
    t_l = bisect.bisect_left(t, x) - 1
    s_r = s_l + 1
    t_r = t_l + 1
    if s_l == -1:
        s_l = 0
    if t_l == -1:
        t_l = 0
    if s_l == a :
        s_l = a - 1
        s_r = a - 1
    if s_r == a:
        s_r = a - 1
    if t_l == b:
        t_l = b - 1
        t_r = b - 1
    if t_r == b:
        t_r = b - 1
    ans = min(abs(t[t_l] - s[s_r]) + min(abs(t[t_l] - x), abs(s[s_r] - x)),
    abs(s[s_l] - t[t_r]) + min(abs(s[s_l] - x), abs(t[t_r] - x)),
    abs(s[s_l] - t[t_l]) + min(abs(s[s_l] - x), abs(t[t_l] - x)),
    abs(s[s_r] - t[t_r]) + min(abs(s[s_r] - x), abs(t[t_r] - x)),
    )
    
    print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
sorted_a=list(set(sorted(a)))
d={}
for i in range(n):
    y=a[i]
    if y in d:
        print(d[y])
        continue
    total=sum([sum(range(a.count(x) - (1 if x==y else 0))) for x in sorted_a])
    print(total)
    d[y]=total


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
d={}
for x in a:
    if d.get(x) is None:
        d[x]=1
        continue
    d[x]+=1
total=0
for v in d.values():
    total+=(v-1)*v//2
for x in a:
    print(total-d[x]+1)
### BUGGY CODE ###

import numpy as np
from numba import njit

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
a = np.array(A)

fin = np.array([N] * N)


@njit(cache=True)
def calc_b(a):
    b = np.array([0] * N)
    for i in range(N):
        l = max(0, i - a[i])
        r = min(N - 1, i + a[i])

        for j in range(l, r + 1):
            b[j] += 1
    return b


for k in range(K):
    a = calc_b(a)

    if all(a == fin):
        break

a = [str(_) for _ in a]
print(' '.join(a))



### FIXED CODE ###

import numpy as np
from numba import njit

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
a = np.array(A, dtype=int)


fin = [N] * N

@njit(cache=True)
def calc_b(a):
    b = np.zeros(N, dtype=np.int64)
    for i, _a in enumerate(a):
        l = max(0, i - _a)
        r = min(N - 1, i + _a)

        # imos hou
        b[l] += 1
        if r + 1 < N:
            b[r + 1] -= 1

    b = np.cumsum(b)
    # print('b_sum', b)
    return b


for k in range(min(K,100)):
    # print('a', a)
    a = calc_b(a)
    # if all(a == fin):
    #     break

a = [str(_) for _ in a]
print(' '.join(a))
# print('step=', k)
### BUGGY CODE ###

import collections
N = int(input())
countr = []
liss = []
for i in range(N):
  s = input()
  a = collections.Counter(s)
  if a in liss:
    ind = liss.index(a)
    countr[ind] += 1
  else:
    liss.append(a)
    countr.append(1)

ans = 0
for cc in countr:
  ans = ans + (cc * (cc - 1) / 2)
print(int(ans))

### FIXED CODE ###

N = int(input())
liss = {}
for i in range(N):
  s = input()
  a = "".join(sorted(s))
  if a in liss:
    liss[a] += 1
  else:
    liss[a] = 1

ans = 0
for cc in liss:
  ans = ans + (liss[cc] * (liss[cc] - 1) / 2)
print(int(ans))
### BUGGY CODE ###

h, n = map(int, input().split())
magics = [list(map(int, input().split())) for _ in range(n)]
max_cost = max(magic[1] for magic in magics)

dp = [float('inf')] * (h+max_cost)

dp[0] = 0
for i in range(len(dp)):
    for at, cost in magics:
        if at <= i:
            dp[i] = min(dp[i], dp[i-at] + cost)
print(min(dp[h:]))



### FIXED CODE ###

h, n = map(int, input().split())
magics = sorted(list(map(int, input().split())) for _ in range(n))
max_cost = max(magic[1] for magic in magics)

dp = [float('inf')] * (h+max_cost)
dp[0] = 0
for i in range(h+max_cost):
    for at, cost in magics:
        if at <= i:
            dp[i] = min(dp[i], dp[i-at] + cost)
        else:
            break
print(min(dp[h:]))
### BUGGY CODE ###

N, Q = map(int, input().split())
s = input()
for _ in range(Q):
  l, r = map(int, input().split())
  print(s[l-1:r].count('AC'))

### FIXED CODE ###

import sys
import bisect

N, Q = map(int, input().split())
s = sys.stdin.readline().rstrip()
ac_list = []
start = 0
while True:
  index = s.find('AC', start)
  if index == -1:
    break
  ac_list.append(index + 1)
  start = index + 1


for _ in range(Q):
  l, r = map(int, input().split())
  res = 0
  start = bisect.bisect_left(ac_list, l)
  end = bisect.bisect_right(ac_list, r-1) - 1
  print(end-start+1)
### BUGGY CODE ###

s=input()
while s:
    if s[-5:]=='erase':
        s=s[:-5]
    elif s[-5:]=='dream':
        s=s[:-5]
    elif s[-6:]=='eraser':
        s=s[:-6]
    elif s[-7:]=='dreamer':
        s=s[:-7]
    else:
        print('NO')
print('YES')

### FIXED CODE ###

s=input()[::-1]
i=0
while i<len(s):
    if i+5<=len(s) and s[i:i+5]=='esare':
        i+=5
    elif i+5<=len(s) and s[i:i+5]=='maerd':
        i+=5
    elif i+6<=len(s) and s[i:i+6]=='resare':
        i+=6
    elif i+7<=len(s) and s[i:i+7]=='remaerd':
        i+=7
    elif i<len(s):
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

a, b, c = map(int, input().split())
k = int(input())
flag = False
if a < b < c:
    flag = True
count = 0
if not flag:
    while count < k:

        if a > b:
            count += 1
            b = 2*b
        if b > c:
            count += 1
            c = 2*c

if count <= k:
    if a < b < c:
        print("Yes")
    else:
        print("No")
else:
    print("No")

### FIXED CODE ###

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

count = 0
while count < k and not (a < b < c):
    if a >= b:
        count += 1
        b = 2*b
    if b >= c:
        count += 1
        c = 2*c

if count <= k:
    if a < b < c:
        print("Yes")
    else:
        print("No")
else:
    print("No")
### BUGGY CODE ###

import sys

inf = sys.maxsize

# 入力:graphと始点s
# 出力:始点sから各頂点tへの距離dist
def shortestPath(graph, s):
    n = len(graph)

    dist    = [inf for _ in range(n)]
    visited = [False for _ in range(n)]
    dist[s] = 0

    while True:
        idx, u  = -1, inf
        for i in range(n):
            if not visited[i] and dist[i] < u:
                idx = i
                u = dist[i]
        
        if u == inf: break
        
        visited[idx] = True

        for (next, w) in graph[idx]:
            newdist = w + dist[idx]
            if newdist < dist[next]:
                dist[next] = newdist
    return dist

def main():
    v, e, s = map(int, input().split())
    
    # 隣接リスト
    graph = [[] for _ in range(v)]
    
    for i in range(e):
        a, b, cost = map(int, input().split())
        graph[a].append((b, cost))
            
    c_dist = shortestPath(graph, s)
            
    for d in c_dist:
        if d == inf:
            print("INF")
        else:
            print(d)
main()

### FIXED CODE ###

import sys
import heapq as h

inf = sys.maxsize

class heapq:
    def __init__(self):
        self.q = []

    def push(self,v):
        h.heappush(self.q, v)
    
    def pop(self):
        return h.heappop(self.q)

    def is_empty(self):
        return len(self.q) == 0

# 入力:graphと始点s
# 出力:始点sから各頂点tへの距離dist
def shortestPath0(graph, s):
    n = len(graph)

    dist    = [inf for _ in range(n)]
    visited = [False for _ in range(n)]
    dist[s] = 0

    while True:
        idx, u  = -1, inf
        for i in range(n):
            if not visited[i] and dist[i] < u:
                idx = i
                u = dist[i]
        
        if u == inf: break
        
        visited[idx] = True

        for (next, w) in graph[idx]:
            newdist = w + dist[idx]
            if newdist < dist[next]:
                dist[next] = newdist
    return dist

def shortestPath1(graph, s):
    n = len(graph)

    dist    = [inf for _ in range(n)]
    visited = [False for _ in range(n)]
    
    q = heapq()
    q.push((0, s))

    while not q.is_empty():
        (cur_dist, v) = q.pop()

        if visited[v] or dist[v] <= cur_dist:
            continue

        dist[v] = cur_dist
        visited[v] = True

        for next, w in graph[v]:
            if not visited[next] and dist[v] + w < dist[next]:
                q.push((dist[v] + w, next))

    return dist

def main():
    v, e, s = map(int, input().split())
    
    # 隣接リスト
    graph = [[] for _ in range(v)]
    
    for i in range(e):
        a, b, cost = map(int, input().split())
        graph[a].append((b, cost))
            
    c_dist = shortestPath1(graph, s)
            
    for d in c_dist:
        if d == inf:
            print("INF")
        else:
            print(d)
main()
### BUGGY CODE ###

from collections import deque, defaultdict
N, M = map(int, input().split())
D = [[float("inf")]*N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for i in range(M):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    D[s][t] = 1
    D[t][s] = 1

q = deque()
q.append(0)
d = defaultdict(lambda : int(-1))
d[0] = 0
while q:
    u = q.popleft()
    for v in range(N):
        if D[u][v] == float("inf"):
            continue
        if not d[v] == -1:
            continue
        d[v] = u
        q.append(v)
if len(d) == N:
    print("Yes")
else:
    print("No")
    exit()
for i in range(1, N):
    print(d[i]+1)

### FIXED CODE ###

from collections import deque, defaultdict
N, M = map(int, input().split())
D = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    D[s].append(t)
    D[t].append(s)

q = deque()
q.append(1)
d = defaultdict(lambda : float("inf"))
d[1] = 0
while q:
    u = q.popleft()
    for v in D[u]:
        if d[v] == float("inf"):
            d[v] = u
            q.append(v)

if len(d) == N:
    print("Yes")
else:
    print("No")
    exit()
for i in range(2, N+1):
    print(d[i])
### BUGGY CODE ###

M = 10**9 + 7
k,n = int(input()),len(input())
a = t = pow(26,k,M)

for i in range(k):
    t = t*25*(i+n)*pow(26,-1,M)*pow(i+1,-1,M)%M
    a += t

print(a%M)

### FIXED CODE ###

M = 10**9 + 7
k,n = int(input()),len(input())
a = t = pow(26,k,M)

for i in range(k):
    t = t*25*(i+n)*pow(26*(i+1),-1,M)%M
    a += t

print(a%M)
### BUGGY CODE ###

from collections import Counter

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

s = input()

if 10 % p == 0:
    ans = 0
    for i, x in enumerate(s):
        if int(x) % p == 0:
            ans += i + 1
    print(ans)
else:
    li = [0]
    for i, x in enumerate(reversed(s)):
        li.append((li[-1] + int(x) * (10**i) % p) % p)

    ans = 0
    c = Counter(li[1:])
    for v in c.values():
        ans += (v * (v-1) // 2)
    ans += c[0]
    print(ans)


### FIXED CODE ###

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

s = input()

if 10 % p == 0:
    ans = sum(i + 1 for i, x in enumerate(s) if int(x) % p == 0)
    print(ans)
else:
    counter = [0] * p
    counter[0] = 1
    cur = 0
    p10 = 1
    ans = 0
    for x in s[::-1]:
        cur = (cur + int(x) * p10) % p
        ans += counter[cur]
        counter[cur] += 1
        p10 *= 10
        p10 %= p
    print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
N, u, v = map(int, input().split())
u -= 1
v -= 1

G = [[] for _ in range(N)]
elens = [0] * N

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

def dfs_aoki(cur: int, past: int, d: int):

    if elens[cur] == 1 and G[cur][0] == past:
        return [d - 1, 0 if cur == u else -1]

    ret = 0
    takahashi_d = -1

    for nx in G[cur]:
        if nx == past:
            continue

        r = dfs_aoki(nx, cur, d + 1)
        depth, td = r[0], r[1]
        if td >= 0:
            if td >= 0 and d <= td + 1:
                return depth, td
            takahashi_d = td + 1

        ret = max(ret, depth)

    return [ret, takahashi_d]

ret = dfs_aoki(v, -1, 0)
print(ret[0])

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N, u, v = map(int, input().split())
u -= 1
v -= 1

G = [[] for _ in range(N)]
elens = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    elens[a] += 1
    elens[b] += 1
depths = [0] * N
dists = [0] * N


TAKAHASHI = [0] * N
AOKI = [0] * N

def dfs_aoki(cur: int, past: int, d: int):
    AOKI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_aoki(nx, cur, d + 1)

def dfs_takahashi(cur: int, past: int, d: int):
    TAKAHASHI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_takahashi(nx, cur, d + 1)

dfs_takahashi(u, -1, 0)
dfs_aoki(v, -1, 0)

ans = 0

for i in range(N):
    if TAKAHASHI[i] < AOKI[i]:
        ans = max(ans, AOKI[i] - 1)

print(ans)