Harryxun/stf_run huggingface dataset:
import re

class Node:
  key = None
  left = None
  right = None
  def __init__(self, k):
    self.key = k

class BST:
  root = None
  def insert(self, k):
    x = self.root
    y = None
    z = Node(k)
    while x is not None:
      y = x
      if z.key < y.key:
        x = x.left
      elif y.key < z.key:
        x = x.right
    
    if y is None:
      # 初回値
      self.root = z
    else:
      if z.key < y.key:
        y.left = z
      elif y.key < z.key:
        y.right = z
        
  def inorder(self, r):
    # 中間巡回順で出力
    if r != None:
      self.inorder(r.left)
      print(" {}".format(r.key), end="")
      self.inorder(r.right)
      

  def preorder(self, r):
    # 先行巡回順で出力
    if r != None:
      print(" {}".format(r.key), end="")
      self.preorder(r.left)
      self.preorder(r.right)

    
n = int(input())
bst = BST()
for _ in range(n):
  # query = [int(x) if re.match('[+|-]?\d', x) else x for x in input().split()]
  if query[0] == 'insert':
    bst.insert(int(query[1]))
  elif query[0] == 'print':
    root = bst.root
    bst.inorder(root)
    print()
    bst.preorder(root)
    print()


### FIXED CODE ###

class Node:
  key = None
  left = None
  right = None
  def __init__(self, k):
    self.key = k

class BST:
  root = None
  def insert(self, k):
    x = self.root
    y = None
    z = Node(k)
    while x is not None:
      y = x
      if z.key < y.key:
        x = x.left
      elif y.key < z.key:
        x = x.right
    
    if y is None:
      # 初回値
      self.root = z
    else:
      if z.key < y.key:
        y.left = z
      elif y.key < z.key:
        y.right = z

  def inorder(self, r, lis):
    # 中間巡回順で出力
    if r != None:
      self.inorder(r.left, lis)
      lis.append(r.key)
      self.inorder(r.right, lis)


  def preorder(self, r, lis):
    # 先行巡回順で出力
    if r != None:
      lis.append(r.key)
      self.preorder(r.left, lis)
      self.preorder(r.right, lis)

    
n = int(input())
bst = BST()
for _ in range(n):
  # query = [int(x) if re.match('[+|-]?\d', x) else x for x in input().split()]
  query = input().split()
  if query[0] == 'insert':
    bst.insert(int(query[1]))
  elif query[0] == 'print':
    root = bst.root
    in_lis = []
    pre_lis = []
    bst.preorder(root, pre_lis)
    bst.inorder(root, in_lis)
    print(" " + " ".join(list(map(str, in_lis))))
    print(" " + " ".join(list(map(str, pre_lis))))
N, result = eval(input()), 1
List = list(map(int, input().split()))
for i in List[N]:
    result *= i
    
print(result if result <= 10**18 else -1)

### FIXED CODE ###

n = int(input())
List = list(map(int, input().split()))
res = 1
if 0 in List:
    print(0)
    quit()
for x in List:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)
a,b=int.input(),split()
if a-b＊2>=0:
  print(a-b＊2)
else:
   print(0)
  


### FIXED CODE ###

a,b=map(int,input().split())
if a-b*2<=0:
  
  print(0)
else:
  print(a-b*2)
N = input()
S = input()

n = int(N/2)
s1 = S[:n]
s2 = S[n:]

if s1 == s2:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N = int(input())
S = input()

n = int(N/2)
s1 = S[:n]
s2 = S[n:]

if s1 == s2:
    print('Yes')
else:
    print('No')
import math


def p_d():
    a, b = map(int, input().split())
    gcd = math.gcd(a, b)
    ans = 1
    cnt = 2
    while cnt * cnt < gcd:
        up = True
        while gcd % cnt == 0:
            if up:
                ans += 1
                up = False
            gcd //= cnt
        cnt += 1
    ans += 1 if ans != 1 else 0
    print(ans)


if __name__ == '__main__':
    p_d()


### FIXED CODE ###

def calc_gcd(a, b):
    return calc_gcd(b, a % b) if b else a


def p_d():
    a, b = map(int, input().split())
    gcd = calc_gcd(a, b)
    ans = 1
    cnt = 2
    while cnt * cnt < gcd:
        up = True
        while gcd % cnt == 0:
            if up:
                ans += 1
                up = False
            gcd //= cnt
        cnt += 1
    ans += 1 if gcd != 1 else 0
    print(ans)


if __name__ == '__main__':
    p_d()
N,T = map(int,input().split())
li = []
for i in range(N):
    c,t = map(int,input().split())
    if t > T:
        continue
    else:
        li.append(c)
print(min(li))

### FIXED CODE ###

N,T = map(int,input().split())
li = []
for i in range(N):
    c,t = map(int,input().split())
    if t > T:
        continue
    else:
        li.append(c)
if li == []:
    print("TLE")
else:
    print(min(li))
n=int(input())
if n%2==0:
    return(0.5)
else:
    return((n+1)/(2*n))


### FIXED CODE ###

n=int(input())
if n%2==0:
  print(0.5)
else:
  print((n+1)/(2*n))
import numpy as np

N = int(input())
As = [int(i) for i in input().split()]

mat = np.array([np.zeros(N) for _ in range(N)])

for i in range(N-1):
    mat[i][i], mat[i][i+1] = 1, 1

mat[N-1][0], mat[N-1][N-1] = 1, 1

for i in range(N):
    C = mat[i][i]
    As[i] /= C
    for j in range(N):
        mat[i][j] /= C
    for k in range(N):
        if k == i: continue
        D = mat[k][i]
        for j in range(N):
            mat[k][j] -= mat[i][j] * D
        As[k] -= As[i] * D

print(*[int(i)*2 for i in As])

### FIXED CODE ###

N = int(input())
As = [int(i) for i in input().split()]

x_0 = sum(As) - 2 * sum(As[1::2])
print(int(x_0), end=" ")
x = x_0

for i in range(N-2):
    x = 2*As[i] - x
    print(int(x), end=" ")

x = 2*As[N-2] - x
print(int(x))
import math

a, b, x = map(int, input().split())
print(math.degrees(math.atan(a/(2*b-2*x/a**2))))

### FIXED CODE ###

import math

a, b, x = map(int, input().split())
if x >= a**2*b/2:
    print(math.degrees(math.atan((2*b-2*x/a**2)/a)))
else:
    print(math.degrees(math.atan(b**2*a/2/x)))
s = input()
while s != '':
    if s[:5] == 'dream' or s[:5] == 'erase':
        if s[5] == 'r':
            s = s[6:]
        else:
            s = s[5:]
    else:
        print('NO')
        quit(0)

print('YES')


### FIXED CODE ###

from collections import deque

def solve(s):
    stack = deque()
    stack.append(s)
    while len(stack) > 0:
        top = stack.pop()
        if top == '':
            return 'YES'

        if top[:5] == 'dream':
            if top[5:7] == 'er':
                stack.append(top[7:])
            stack.append(top[5:])
        elif top[:5] == 'erase':
            if len(top) > 5 and top[5] == 'r':
                stack.append(top[6:])
            else:
                stack.append(top[5:])
    return 'NO'

print(solve(input()))
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1 in range(n):
        if aa[i1] > k:
            break
        else:
            t = bisect(ba, k - aa[i1])
            r = max(r, i1 + 1 + t)
    for j1 in range(m):
        if ba[j1] > k:
            break
        else:
            t = bisect(aa, k - ba[i1])
            r = max(r, j1 + 1 + t)
    print(r)
if __name__ == '__main__':
    main()

### FIXED CODE ###

from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1 in range(n):
        if aa[i1] > k:
            break
        else:
            t = bisect(ba, k - aa[i1])
            r = max(r, i1 + 1 + t)
    for j1 in range(m):
        if ba[j1] > k:
            break
        else:
            t = bisect(aa, k - ba[j1])
            r = max(r, j1 + 1 + t)
    print(r)
if __name__ == '__main__':
    main()
j = 0
a = 0
i = 0
mylist = []
for i in range(N):
    mylist.insert(i, 0)
N=int(input())
h = [int(x) for x in input().split()]
   
for i in range(N):
    mylist[h[i]-1]=i+1
    
print(*mylist)

### FIXED CODE ###

j = 1
a = 0
i = 0
N = 0


#N = int(input()) for _ in range(1)
A = [int(input()) for _ in range(1)]
#N=int(input())
mylist = [0]*A[0]

h = [int(x) for x in input().split()]

for i in range(A[0]):
    mylist[h[i]-1]=i+1
print(*mylist)
import sys
rl = sys.stdin.readline


def solve():
    N = int(rl())
    graph = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    fen_dist, sun_dist = [0] * N, [0] * N
    
    def dfs1(node, parent, dist):
        fen_dist[node] = dist
        for child in graph[node]:
            if child != parent:
                dfs1(child, node, dist + 1)
    
    def dfs2(node, parent, dist):
        sun_dist[node] = dist
        for child in graph[node]:
            if child != parent:
                dfs2(child, node, dist + 1)
    
    dfs1(0, -1, 0)
    dfs2(N - 1, -1, 0)
    
    cnt_fen, cnt_sun = 0, 0
    for i in range(N):
        if fen_dist[i] <= sun_dist[i]:
            cnt_fen += 1
        else:
            cnt_sun += 1
    
    if cnt_fen < cnt_sun:
        print('Snuke')
    else:
        print('Fennec')


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    graph = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    fen_dist, sun_dist = [0] * N, [0] * N
    
    def dfs1(node, parent, dist):
        fen_dist[node] = dist
        for child in graph[node]:
            if child != parent:
                dfs1(child, node, dist + 1)
    
    def dfs2(node, parent, dist):
        sun_dist[node] = dist
        for child in graph[node]:
            if child != parent:
                dfs2(child, node, dist + 1)
    
    dfs1(0, -1, 0)
    dfs2(N - 1, -1, 0)
    
    cnt_fen, cnt_sun = 0, 0
    for i in range(N):
        if fen_dist[i] <= sun_dist[i]:
            cnt_fen += 1
        else:
            cnt_sun += 1
    
    if cnt_fen <= cnt_sun:
        print('Snuke')
    else:
        print('Fennec')


if __name__ == '__main__':
    solve()
n=input()
m=len(n)
n=int(n)

if n%2==1:
    print(0)
else:
    if m==1:
        print(0)
    else:
        ans=0
        i=1
        while True:
            ans_plus=n//(2*5**i)
            if ans_plus==0:
                break
            ans+=ans_plus

            i+=1
print(ans)

### FIXED CODE ###

n=input()
m=len(n)
n=int(n)

if n%2==1:
    print(0)
else:
    if m==1:
        print(0)
    else:
        ans=0
        i=1
        while True:
            ans_plus=n//(2*5**i)
            if ans_plus==0:
                break
            ans+=ans_plus

            i+=1
        print(ans)
a,b=map(int,input().split())
print(a-2b)


### FIXED CODE ###

a,b = map(int,input().split())
c = 2*b
d = a-c
if d > 0:
 print(d)
elif d <= 0:
 print(0)
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [(p+1)/2 for p in P]
def s(i):
    return sum(P[:i-1])

S = []
for i in range(N+1):
    S.append(s(i))
B = []
for j in range(N-K+1):
    B.append(S[j+K]-S[j])
ans = max(B)
print(ans)
    




### FIXED CODE ###

from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [0]+[(p+1)/2 for p in P]
S = list(accumulate(P))
B = []
for j in range(N-K+1):
    B.append(S[j+K]-S[j])
ans = max(B)
print(ans)
t = 0
while t == 0:	
		a,b,c,d,e,f = [int(i) for i in input().split()]
	

### FIXED CODE ###

t = 0
while t == 0:	
	try:
		a,b,e,c,d,f = [int(i) for i in input().split()]
	except:
		break
	else:
		x = (d*e - b*f) / (a*d - b*c) + 0
		y = (a*f - c*e) / (a*d - b*c) + 0
		print("{0:.3f}".format(x) + " " + "{0:.3f}".format(y))
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

count_ac = np.zeros([len(s)])
for i in range(len(s)):
    if s[i]=="A" and i<len(s):
        if s[i+1]=="C":
            count_ac[i+1:] += 1

print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))


### FIXED CODE ###

# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while i < n-1:
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1

count_ac.append(count)


# print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))
N = int(input())
ans = 0
​
for i in range(1,26):
  for j in range(1,15):
    n = 4*i + 7*j
    if n == N:
      ans = 1
      break
      
if ans == 1:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
ans = 0

for i in range(26):
  for j in range(15):
    n = 4*i + 7*j
    if n == N:
      ans = 1
      break
  if ans == 1:
    break

if ans == 1:
  print("Yes")
else:
  print("No")
ret=0
m=10
for _ in range(6):
  y=int(input())
  ret+=(y+9)//10
  if y%10!=0:
    m=min(m,y%10)
print(ret-(10-m))

### FIXED CODE ###

ret=0
m=10
for _ in range(5):
  y=int(input())
  ret+=(y+9)//10*10
  if y%10!=0:
    m=min(m,y%10)
print(ret-(10-m))
a,b=(int,input().split())
print("{0} {1} {2:.8f}".format{a // b, a % b, a / b))



### FIXED CODE ###

a,b = map(int,input().split())
print("{0} {1} {2:.8f}".format(a // b, a % b, a / b))
#include <stdio.h>

int main(void){
  int l1 = [3];
  int i;
  
  for (i = 0;i < 9;i += 3){
    scanf("%d", &l1[i]);
  }
  print("%d%d%d\n", l1[0], l1[1], l1[2]);
  return 0;
}

### FIXED CODE ###

A, B, C = [input() for i in range(3)]

print(A[0] + B[1] + C[2])
s = input()

if s.isuppper():
    print("A")
elif s.islower():
    print("a")

### FIXED CODE ###

s = input()

if s.isupper():
        print("A")
elif s.islower():
        print("a")
s = []
r.extend( [0 for i in range(x+y)])
p.sort()
q.sort()
r.sort()


for i in range(x):
    if  p[-1]>= r[-1]:
        s.append(p.pop())
    else:
        s.append(r.pop())
    
for i in range(y):
    if  q[-1]>= r[-1]:
        s.append(q.pop())
    else:
        s.append(r.pop())
        
print(sum(s))

### FIXED CODE ###

x, y, a, b, c = [int(t) for t in input().split()]
p = [int(t) for t in input().split()]
q = [int(t) for t in input().split()]
r = [int(t) for t in input().split()]

s = []
p.sort(reverse=True)
p = p[:x]

q.sort(reverse=True)
q = q[:y]

s = p + q + r
s.sort(reverse=True)
s = s[:x+y]
print(sum(s))
if S is 'ABC':
	print('ARC')
elif S is 'ARC':
    print('ABC')

### FIXED CODE ###

S = input()
if S == 'ABC':
  print('ARC')
else:
  print('ABC')
def main():

    a = input()
    b = input()
    c = input()

    def LCS(S, T):

        if len(S) == 0 or len(T) == 0:
            return 0
        

        dp = [[0 for _ in range(len(S) + 1)] for _ in range(len(T) + 1)]
        for i in range(len(S)):
            for j in range(len(T)):
                if S[i] == "?" or T[j] == "?" or S[i] == T[j]:
                    dp[i+1][j+1] = dp[i][j] + 1
                else:
                    dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

        return dp[len(S)][len(T)]

    ans = 0

    ab = LCS(a,b)

    ac = LCS(a,c)

    bc = LCS(b,c)


    if ab == ac == bc == 0:
        print(len(a) + len(b) + len(c))
        exit()

    if ac <= ab and ac <= bc:
        ans = (len(a) + len(b) - ab) + (len(c) - bc) 

    elif ab <= ac and ab <= bc:
        ans = (len(a) + len(c) - ac) + (len(c) - bc) 

    elif bc <= ab and bc <= ac:
        ans = (len(a) + len(b) - ab) + (len(c) - ac)

    print(ans) 


if __name__ == "__main__":
    main()
        

### FIXED CODE ###


A = input()
B = input()
C = input()

def match(c1, c2):
    return c1 == "?" or c2 == "?" or c1 == c2

la = len(A)
lb  =len(B)
lc = len(C)

ml = max(la, lb, lc)

# 。a の左端の位置を 0 としたとき、他の文字列の左端の位置は −4000 から 4000 まで動く可能性があることに注意してください  より、４倍
ab = [False for _ in range(ml * 4 + 1)]
ac = [False for _ in range(ml * 4 + 1)]
bc = [False for _ in range(ml * 4 + 1)]

"""
下の２重forで(i,j) = (0,0)と(1,1)で配列のindexが同じになってしまうが、AとBの０文字目どうし、1文字目どうしを比べるのは、
同じところから先頭が始まっている場合なので、あるずれの配置について、全文字比較していることになる
i=0,j=2とかだとBのほうが左にある場合で、i=3,j=0だとAが左にある場合

ab[i - j]のindexに+2mlして、-2ml ~ 2ml 感を出したい気持ちがあるが、意味がないのでしない
"""


def main():

    for i in range(la):
        for j in range(lb):
            # すでにそのずらし方で文字が重ねられないことが分かっている場合はスキップ
            if ab[i - j]:
                continue
            # そのずらし方で重ねられない場合はTrue
            if not match(A[i], B[j]):
                ab[i - j] = True


    for i in range(la):
        for j in range(lc):
            # すでにそのずらし方で文字が重ねられないことが分かっている場合はスキップ
            if ac[i - j]:
                continue
            # そのずらし方で重ねられない場合はTrue
            if not match(A[i], C[j]):
                ac[i - j] = True

    for i in range(lb):
        for j in range(lc):
            # すでにそのずらし方で文字が重ねられないことが分かっている場合はスキップ
            if bc[i - j]:
                continue
            # そのずらし方で重ねられない場合はTrue
            if not match(B[i], C[j]):
                bc[i - j] = True       

    ans = la + lb + lc
    # BCAとかACBみたいにAの前後に並ぶ場合があるので、AとBの位置関係について±2*ml分探索（Aの頭が０の位置にあるとしてBをどこに置くか(それがi)ということ。）
    for i in range(-2*ml, 2*ml+1):
        # a,bについて、あるずらし方で重ねられない場合は飛ばす
        if ab[i]:
            continue
        # CBA,ABCのパターンがあるので～
        for j in range(-2*ml, 2*ml+1):
            if ac[j]:
                continue
            
            # ここでi,jはaの頭をindexの0としたときの位置にあたるので、B基準で見たときのCとの位置関係はj - iとなる
            # で、そのとき重ねられないならスキップ
            if bc[j - i]:
                continue

            # 文字列Sの左端のindex
            l = min(0, i, j)
            # 文字列Sの右端のindex
            r = max(0 + la, i + lb, j + lc)
            ans = min(ans, r - l)

    print(ans)

if __name__ == "__main__":
    main()
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bin_sort(A,n_min=None,n_max=None):
    if(n_min is None): n_min=min(A)
    if(n_max is None): n_max=max(A)
    bin=[0]*(n_max-n_min+1)
    for a in A: bin[a]+=1
    B=[]
    for i in range(n_min,n_max+1): B+=[i]*bin[i]
    return B

def resolve():
    n=int(input())
    A=[0]*n
    for a in map(int,input().split()): A[a-1]+=1
    A=bin_sort(A,0,n-1)
    S=[0]*(n+1)
    for i in range(n): S[i+1]=S[i]+A[i]
    # output
    p=n; i=n
    for k in range(1,n+1):
        while(1):
            while(1):
                if(i<=0 or A[i-1]<p): break
                i-=1
            if(S[i]+p*(n-i)>=k*p): break
            p-=1
        print(p)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisection(l,r,f,discrete=True,left=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return h if not discrete else l if left else r

def resolve():
    from collections import Counter
    from bisect import bisect_left
    n=int(input())
    A=Counter(map(int,input().split()))
    A=list(A.values())
    A.sort()
    m=len(A)
    S=[0]*(m+1)# cumulative distribution
    for i in range(m):
        S[i+1]=S[i]+A[i]
    for k in range(1,n+1):
        def check(p):
            i=bisect_left(A,p)
            return S[i]+(m-i)*p>=k*p
        print(bisection(0,n//k+1,check))
resolve()
a,b,c=map(int,input().split())
k=int(input())
B=b
for n in range(k):
  if a>b:
    b=b*2
  else:
    break
e=b/B
for n in range(k-e):
  if b>c:
    c=c*2
  else:
    break
if b>a and c>b:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c=map(int,input().split())
k=int(input())
for n in range(k):
  if a>=b:
    b=b*2
  elif b>=c:
    c=c*2
if b>a and c>b:
  print('Yes')
else:
  print('No')
n = input()
l = []
for i in range(int(n)):
	command = input()
	print(command)
	if command[0] == 'i':
		l.insert([(command[6:])])
	else:
		if command[7] == " ":
			if  command[6:] in l:
				l.remove(command[6:])
		else:
			if command[7] == 'L':
				l.pop()
			else:
				l.pop(0)
for i in l[:-1]:
	print(i, end=' ')
print(l[-1])

### FIXED CODE ###

from collections import deque
n = input()
d = deque()
for i in range(int(n)):
	command = input()
	if command[0] == 'i':
		d.appendleft(command[7:])
	else:
		if command[6] == " ":
			if  command[7:] in d:
				d.remove(command[7:])
		else:
			if command[6] == 'L':
				d.pop()
			else:
				d.popleft()
for _ in range(len(d)-1):
	print(d.popleft(), end=" ")
print(d.pop())
n, k = map(int, input().split())

s = list(str(input()))

first_index=0
last_index=0

res = 0
for f in range (first_index, n+1):
  for l in range (last_index, n+1):
    if f < l:
      continue
    check = 0
    for i in range(f, l+1):
      if s[i] == 0:
        check += 1
    if check <= k:
      if l-f > res:
        res = l-f

print(res)

### FIXED CODE ###

n, k = map(int, input().split())
s = list(input())

# 部分文字列の和を算出
array = []
now_num = 1
count = 0
for i in s:
  if now_num == int(i):
    count += 1
  else:
    array.append(count)
    count = 1
    now_num = 1 - now_num

if count != 0:
  array.append(count)

if len(array) % 2 == 0:
  array.append(0)

res = 0
add = 2 * k + 1
ans = 0
left = 0
right = 0
tmp = 0

for i in range(len(array))[::2]:
    next_left = i
    next_right = min(i+add, len(array))
    # 尺取法
    while next_left > left:
        tmp -= array[left]
        left += 1
    while next_right > right:
        tmp += array[right]
        right += 1
    ans = max(tmp,ans)

print(ans)
n=int(input())
a=list(map(int,input().split()))
box=[0]*n
for i in range(n):
  baisu=n%(n-i)
  if baisu==1:
    box[n-i-1]=a[n-i-1]
  else:
    cnt=0
    for j in range(2,baisu+1):
      cnt+=box[(n-i-1)*j]
    if cnt%2!=a[n-i-1]:
      box[n-i-1]=1
print(sum(box))
if sum(box)!=0:
  for i in range(n):
    if box[i]==1:
      print(i+1,end=' ')


### FIXED CODE ###

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

#箱の状態を記録しておく配列
box=[0]*n


for i in range(n):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

ans=[]
for i in range(n):
  if box[i]==1:
    ans.append(i+1)

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")
n = int(input())
d = [-1 for i in range(n)]
e = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    e[a - 1].append([b - 1, c])
    e[b - 1].append([a - 1, c])
q, k = map(int, input().split())
def dfs(cur, par, di):
    d[cur] = di
    for i in e[cur]:
        if d[i[0]] == -1:
            if i == par:
                continue
            dfs(i[0], cur, di + i[1])
dfs(k - 1, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
d = [-1 for i in range(n)]
e = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    e[a - 1].append([b - 1, c])
    e[b - 1].append([a - 1, c])
q, k = map(int, input().split())
def dfs(cur, par, di):
    d[cur] = di
    for i in e[cur]:
        if d[i[0]] == -1:
            if i == par:
                continue
            dfs(i[0], cur, di + i[1])
dfs(k - 1, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])